[caribou] antler: Refactor antler-keyboard invocation



commit 9e1e605a224b14b473c769e926208d157089b525
Author: Daiki Ueno <dueno src gnome org>
Date:   Fri Jan 16 17:14:39 2015 +0900

    antler: Refactor antler-keyboard invocation

 bin/antler-keyboard.in |    4 +---
 caribou/antler/main.py |   33 ++++++++++++++++++++++++++-------
 2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/bin/antler-keyboard.in b/bin/antler-keyboard.in
index 941cf91..a1f41a6 100755
--- a/bin/antler-keyboard.in
+++ b/bin/antler-keyboard.in
@@ -38,6 +38,4 @@ else
   export ANTLER_THEME_PATH="$(dirname $script_dir)/data"
 fi
 
- PYTHON@ -c "
-from caribou.antler.main import AntlerKeyboardService
-AntlerKeyboardService().run()"
+ PYTHON@ -m caribou.antler.main "$@"
diff --git a/caribou/antler/main.py b/caribou/antler/main.py
index 24b842a..251678b 100644
--- a/caribou/antler/main.py
+++ b/caribou/antler/main.py
@@ -1,10 +1,14 @@
-from gi.repository import Caribou, GObject
-from window import AntlerWindowEntry
-from keyboard_view import AntlerKeyboardView
+from gi.repository import Caribou, GLib, GObject
+from .window import AntlerWindowEntry
+from .keyboard_view import AntlerKeyboardView
 import sys
 
-class AntlerKeyboardService(Caribou.KeyboardService):
-    def __init__(self):
+class AntlerKeyboardCommand(object):
+    def run(self):
+        pass
+
+class AntlerKeyboardService(Caribou.KeyboardService, AntlerKeyboardCommand):
+    def __init__(self, args=None):
         GObject.GObject.__init__(self)
         self.register_keyboard("Antler")
         self.window = AntlerWindowEntry(AntlerKeyboardView)
@@ -30,5 +34,20 @@ class AntlerKeyboardService(Caribou.KeyboardService):
         sys.exit(0)
 
 if __name__ == "__main__":
-    antler_keyboard_service = AntlerKeyboardService()
-    antler_keyboard_service.run()
+    import argparse
+    import signal
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+    GLib.set_prgname('antler-keyboard')
+
+    parser = argparse.ArgumentParser(description='antler-keyboard')
+    parser.add_argument('-c', '--command', type=str, default='service',
+                        help='command (service or preview, default: service)')
+    args = parser.parse_args()
+
+    command = globals().get('AntlerKeyboard%s' % args.command.capitalize())
+    if command:
+        command(args).run()
+    else:
+        sys.stderr.write("Unknown command: %s\n" % args.command)
+        sys.exit(1)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]