I'd like to transition https://github.com/openaps/oacids and https://github.com/bewest/openxshareble/tree/master/openxshareble and https://github.com/bewest/mmblelink and several other things to internet of things style daemons using linux to prototype these services.
Created
February 22, 2016 09:59
-
-
Save bewest/9c8332ac60a3ea20b59b to your computer and use it in GitHub Desktop.
plea for GIO examples for python + gdbus servers#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from gi.repository import Gio, Gtk | |
class App(Gio.Application): | |
def __init__(self): | |
Gio.Application.__init__(self, | |
application_id="org.gnome.example", | |
flags=Gio.ApplicationFlags.FLAGS_NONE) | |
# flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE) | |
self.connect("activate", self.activateCb) | |
# self.connect("command-line", self.my_argv) | |
def xyzdo_command_line (self, args): | |
# adopted from multiple examples do_command_line is needed any time | |
# HANDLES_COMMAND_LINE is triggered, which can happen in multiple ways. | |
# by default, it calls signals activate, which invokes some kind of main | |
# loop with an appropriate context | |
print "XYZ", args.get_arguments( ) | |
# help(args) | |
# help(line) | |
# self.do_activate(self) | |
self.activate( ) | |
return 0 | |
return Gio.Application.do_activate(self) | |
def activateCb(self, app): | |
print "ACTIVATED!" | |
# sans GUI default loop taking over, there is nothing to do | |
""" | |
many apps supply GUIs, and will launch windows in the "main" instance. | |
What about internet of things apps, which need to export informatin | |
over dbus/websocket and simply want to export data, maybe signals, and | |
if lucky methods, on a bus? | |
With a gui this works, and even registers on properly on d-feet. | |
For now it's not clear how to launch managed objects purely as a | |
library, and potentially export them on new threads as appropriate for | |
library usage. | |
It has something to do with iterating a MainLoop using MainContext's | |
push_thread_default, but no documentation or examples makes this | |
explicit. | |
""" | |
""" | |
window = Gio.ApplicationWindow() | |
app.add_window(window) | |
window.show() | |
""" | |
def do_local_command_line (self, args): | |
print "XXX", self, args | |
# run any argparse here, including argcomplete? | |
# Let Gio/Gio | |
foo = Gio.Application.do_local_command_line(self, args[:1]) | |
# print foo | |
ret = (True, None, 0) # allows dispatchin inner mainloop | |
# ret = (False, None, 0) # continue invoking do_command_line logic, regardless of registered Flags!! | |
# print foo == ret | |
print ret | |
return ret | |
if __name__ == '__main__': | |
app = App() | |
# this does not work either... | |
try: | |
app.run(sys.argv) | |
except KeyboardInterrupt, e: | |
print "Quitting" | |
app.quit( ) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment