jaredks / rumps

Ridiculously Uncomplicated macOS Python Statusbar apps
BSD 3-Clause "New" or "Revised" License
3.06k stars 177 forks source link

Double event loop possible? #118

Open ethanpil opened 5 years ago

ethanpil commented 5 years ago

A simplification of my application is a web server controlled by the Rumps menu. I cannot combine Rumps main loop and asyncio (or any other similar web server lib)'s event loop. In a way that doesn't lock up the Rumps GUI.

Based on some of the examples below, (I am not much of a MacOS internals person) do you think it would be possible to add some functionality to integrate two event loops in some sort of co-routine with Rumps?

For more info, please look here: https://www.reddit.com/r/Python/comments/33ecpl/neat_discovery_how_to_combine_asyncio_and_tkinter/ https://github.com/harvimt/quamash https://pypi.org/project/async_gui/0.1.1/ https://docs.python.org/3/library/asyncio-task.html

jaredks commented 5 years ago

Do you have example code you have been working with? I'd like to play around with it.

xinhuang commented 5 years ago

I have the same question.

I would like to use wxWidgets to create some windows, but wxWidgets event loop is brought up by app.MainLoop() and rumps also requires a App().run(). These two calls are all blocking.

Investigate a bit on rumps.App().run(): It calls AppHelper.runEventLoop(), which calls NSApp().run(), which is blocking.

https://opensource.apple.com/source/pyobjc/pyobjc-37/pyobjc/pyobjc-framework-Cocoa/Lib/PyObjCTools/AppHelper.py.auto.html

Not sure how to implement this...

BTW, thanks for creating this handy library.

sanderfoobar commented 4 years ago

Yeah.. App().run() (rumps) and asyncio's event loop don't play nice together. Tried putting rumps in a Python thread, I got:

objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread!

<_<

jaredks commented 4 years ago

I think using two different UI packages generally isn't advised.

ethanpil commented 4 years ago

My original issue was in regards to asyncio for web server. Same problem. I'm sorry I haven't posted up the code. I will find that and get it up soon. Thanks for your patience.

belthesar commented 1 year ago

I have a situation where this would also be handy. I'm attempting to use the python library @ https://github.com/jonathanslenders/ui24r-client to create a system tray app that monitors the mute status of channels on a mixer. The library is an asyncio-based client. The goal would be to use the client to manipulate the title of the menu bar app. I have an existing solution that updates every second using xbar, but I'm hoping to find a solution that provides real-time feedback.

brechtm commented 1 year ago

I haven't tried this, but you should be able to run the asyncio loop in a thread different from the main thread. See for example this gist: Python asyncio event loop in a separate thread