Commits

Anonymous committed eb40b0a

split dbus related class/functions to dbus_interface.py module

  • Participants
  • Parent commits 93aa84e

Comments (0)

Files changed (2)

File dbus_interface.py

+#
+# Copyright (c) 2008 NAKAMURA Yoshitaka <arumakanoy@gmail.com>
+# 
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+import dbus
+import dbus.service
+import gtk
+
+DBUS_BUS_NAME_BASE = 'org.ny.Yomogi'
+DBUS_OBJECT_PATH = '/org/ny/Yomogi'
+DBUS_INTERFACE_NAME = 'org.ny.Yomogi'
+
+
+class DBusInterface(dbus.service.Object):
+    '''DBus API to control Terminals
+    '''
+    def __init__(self, term_cls):
+        bus_name = dbus.service.BusName(make_bus_name_for_display(),
+                                        bus=dbus.SessionBus())
+        super(DBusInterface, self).__init__(bus_name, DBUS_OBJECT_PATH)
+
+        self._term_cls = term_cls
+
+    @dbus.service.method(DBUS_INTERFACE_NAME, in_signature='a{ss}')
+    def open_terminal(self, opts):
+        self._term_cls(opts)
+
+
+def make_bus_name_for_display():
+    display_name = gtk.gdk.display_get_default().get_name()
+    disp = ''.join(c.isalnum() and c or '_' for c in display_name)
+    return DBUS_BUS_NAME_BASE + disp
+
+
+def get_dbus_interface():
+    bus = dbus.SessionBus()
+    sess_obj = bus.get_object(make_bus_name_for_display(), DBUS_OBJECT_PATH)
+    return dbus.Interface(sess_obj, DBUS_INTERFACE_NAME)
 import difflib
 import unicodedata
 import urllib
-import dbus
-import dbus.service
-
-from dbus.mainloop.glib import DBusGMainLoop
 
 
 synced_terminal = []
 
 url_re = re.compile('(' + '|'.join((url_re_str, www_ftp_re_str)) + ')')
 
-DBUS_BUS_NAME_BASE = 'org.ny.Yomogi'
-DBUS_OBJECT_PATH = '/org/ny/Yomogi'
-DBUS_INTERFACE_NAME = 'org.ny.Yomogi'
-
 class VirtualTerminal(gtk.HBox):
     default_encoding = 'UTF-8'
     #default_encoding = 'EUC-JP'
         terminal.set_highlight_pos(base_highlight_pos)
 
 
-class DBusInterface(dbus.service.Object):
-    '''DBus API to control Terminals
-    '''
-    def __init__(self):
-        bus_name = dbus.service.BusName(make_bus_name_for_display(),
-                                        bus=dbus.SessionBus())
-        super(DBusInterface, self).__init__(bus_name, DBUS_OBJECT_PATH)
+def main():
+    import dbus
 
-    @dbus.service.method(DBUS_INTERFACE_NAME, in_signature='a{ss}')
-    def open_terminal(self, opts):
-        MainWindow(opts)
+    import dbus_interface
 
-
-def make_bus_name_for_display():
-    display_name = gtk.gdk.display_get_default().get_name()
-    disp = ''.join(c.isalnum() and c or '_' for c in display_name)
-    return DBUS_BUS_NAME_BASE + disp
-
-
-def get_dbus_interface():
-    bus = dbus.SessionBus()
-    sess_obj = bus.get_object(make_bus_name_for_display(), DBUS_OBJECT_PATH)
-    return dbus.Interface(sess_obj, DBUS_INTERFACE_NAME)
-
-
-
-def main():
+    from dbus.mainloop.glib import DBusGMainLoop
     from optparse import OptionParser
 
     op = OptionParser()
 
         try:
             # try to re-use existent terminal
-            interface = get_dbus_interface()
+            interface = dbus_interface.get_dbus_interface()
             interface.open_terminal(kwargs)
 
         except dbus.DBusException:
             # start new terminal
-            DBusInterface()
+            dbus_interface.DBusInterface(MainWindow)
 
             MainWindow(kwargs)