|
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) |