Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine i3ipc with other event loops #134

Open
ghistes opened this issue Oct 25, 2019 · 4 comments
Open

combine i3ipc with other event loops #134

ghistes opened this issue Oct 25, 2019 · 4 comments

Comments

@ghistes
Copy link

ghistes commented Oct 25, 2019

Hi,

is it possible (and if it is how do you do it) to combine the event-loop from i3ipc with another event loop (gtk say) so that you could for example write a GUI-script that uses i3ipc?

Many thanks!

@acrisci
Copy link
Member

acrisci commented Oct 25, 2019

No, it's not currently possible. But I would like to support the use case and I'm open to a discussion about how to implement it.

@acrisci
Copy link
Member

acrisci commented Oct 25, 2019

For GTK in particular, I have this project but I haven't updated in awhile.

@ghistes
Copy link
Author

ghistes commented Oct 27, 2019

I can't really contribute to any discussion as I am pretty new to Python and don't know the ecosystem.
But it maybe worth you can get some ideas from Perl's AnyEvent-module (https://metacpan.org/pod/AnyEvent).

@Aphray
Copy link

Aphray commented Mar 31, 2020

I realize this is a slightly old thread, however I felt I should add that it is possible to combine with the event loop of Qt using asyncqt. The snippet below achieves just that.

from i3ipc.aio import Connection
from i3ipc import Event
from PyQt5.QtWidgets import QApplication, QWidget
from asyncqt import QEventLoop
import sys
import asyncio

def _print(conn, event):
    print(event)

async def main():
    i3 = await Connection(auto_reconnect=True).connect()
    i3.on(Event.WINDOW, _print)
    await i3.main()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    loop = QEventLoop(app)
    asyncio.set_event_loop(loop)
    widget = QWidget()
    widget.show()
    with loop:
        sys.exit(loop.run_until_complete(main()))

In case anyone is looking to combine with Qt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants