Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created March 13, 2019 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstraLuma/0391fcacea394ec86836b045ac93fa31 to your computer and use it in GitHub Desktop.
Save AstraLuma/0391fcacea394ec86836b045ac93fa31 to your computer and use it in GitHub Desktop.
Gio Weirdness
import functools
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import GLib
def runloop(func):
@functools.wraps(func)
def wrapped(*pargs, **kwargs):
func(None)
mc = GLib.main_context_default()
print(mc)
ml = GLib.MainLoop.new(mc, True)
print(ml)
print("run")
ml.run()
return wrapped
@runloop
def main(loop):
print("main")
vm = Gio.VolumeMonitor.get()
for sig in GObject.signal_list_names(Gio.VolumeMonitor):
print(sig)
vm.connect(sig, functools.partial(print, sig))
if __name__ == '__main__':
main()
import functools
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import GLib
def runloop(func):
@functools.wraps(func)
def wrapped(*pargs, **kwargs):
mc = GLib.main_context_default()
print(mc)
ml = GLib.MainLoop.new(mc, True)
print(ml)
GLib.idle_add(lambda: func(ml, *pargs, **kwargs))
print("run")
ml.run()
return wrapped
@runloop
def main(loop):
print("main")
vm = Gio.VolumeMonitor.get()
for sig in GObject.signal_list_names(Gio.VolumeMonitor):
print(sig)
vm.connect(sig, functools.partial(print, sig))
if __name__ == '__main__':
main()
import functools
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import GLib
def runloop(func):
@functools.wraps(func)
def wrapped(*pargs, **kwargs):
GLib.idle_add(lambda: func(ml, *pargs, **kwargs))
mc = GLib.main_context_default()
print(mc)
ml = GLib.MainLoop.new(mc, True)
print(ml)
print("run")
ml.run()
return wrapped
@runloop
def main(loop):
print("main")
vm = Gio.VolumeMonitor.get()
for sig in GObject.signal_list_names(Gio.VolumeMonitor):
print(sig)
vm.connect(sig, functools.partial(print, sig))
if __name__ == '__main__':
main()
import functools
from gi.repository import GObject
from gi.repository import Gio
from gi.repository import GLib
vm = Gio.VolumeMonitor.get()
for sig in GObject.signal_list_names(Gio.VolumeMonitor):
print(sig)
vm.connect(sig, functools.partial(print, sig))
mc = GLib.main_context_default()
print(mc)
ml = GLib.MainLoop.new(mc, True)
print(ml)
print("run")
ml.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment