Re: Opening new tabs in existing instance



Le 19/10/2011 00:06, Kai a écrit :
> From looking at the patch, there's still some work needed before it
could actually be merged. For a start, it fails if dbus isn't
available (yes, it looks like it tries to fail gracefully, but it
doesn't; declaring DBusProvider requires dbus.service.Object, which
breaks). Also, Stephen Kennedy's comments from bug 453670 are still
relevant, and there's an optparse-related bugfix from Jeff Oliver in
the same bug that isn't incorporated.
thanks for your time and following up on this
At the time of submitting the patch in https://bugzilla.gnome.org/show_bug.cgi?id=616466, I was (and still) using meld inside shell scripts to compare a bunch of files in one shot; thus I wasn't realising the functionality (and importance) using meld as my vc merge tool I sent too much patches in my previous post - you should consider only the last one

Since then I re-introduced a real --newtab option consideration wich occur if not any of your parser.error triggers Thus, and if I tested well all combinations, the optparse-related bug/bugfix is no more accurate, and if any parser.error trigger it will not break any existing instance, dbus registered or not.

For dbus.service.Object breaking please find attached a new version of the patch: if dbus not available, when --newtab option is called, a message stating dbus not supported is printed and meld is launched as if no --newtab option asked
...but I'm not sure a class inside a try/except is aproriate
The patch also demonstrates the issue of exposing a dbus ABI. The
patch carries forward the auto-compare option in the dbus method, and
I'm not sure that I'd want to include that at all.
I am not sure I understand well the threat of auto-compare when called with --new-tab... The use case I see is or you are using meld in combination with vc as a merge tool or you use it as a gui diff tool and explicitely called as this with --new-tab you want auto-compare But, when I might understand better, I am ready to try to find a way you will agree
Looking at these issues is on my list, but as usual, it's a long list.
sure I understand there might have higher priority issues,
so thanks again for your time and for considering to merge this patch
cheers,
Antoine
=== modified file 'meldapp.py'
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -30,6 +30,57 @@
 version = "1.5.2"
 
 
+################################################################################
+#
+# DbusHandler
+#
+################################################################################
+# dbus check Cf http://mail.gnome.org/archives/meld-list/2011-October/msg00008.html
+dbus_available = False
+try:
+    import dbus
+    if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
+        import sys
+        import dbus.glib
+        import dbus.service
+        dbus_available = True
+        
+        class DBusApp:
+            def register(self, app):
+                bus = dbus.SessionBus()
+                bus_name = dbus.service.BusName('net.sf.meld', bus=bus)
+                self.remote_instance = DBusProvider(bus_name, app)
+                
+            def running_already(self):
+                bus = dbus.SessionBus()
+                proxy = bus.get_object('org.freedesktop.DBus',
+                                       '/org/freedesktop/DBus')
+                iface = dbus.Interface(proxy, 'org.freedesktop.DBus')
+                names = iface.ListNames()
+                if 'net.sf.meld' in names:
+                    return True
+                return False        
+            
+            def remote_open_paths(self, args, auto_compare):
+                bus = dbus.SessionBus()
+                proxy = bus.get_object('net.sf.meld', '/net/sf/meld')
+                iface = dbus.Interface(proxy, 'net.sf.meld')
+                iface.open_paths(args, auto_compare)
+
+        class DBusProvider(dbus.service.Object):
+            def __init__(self, bus_name, app, object_path='/net/sf/meld'):
+                dbus.service.Object.__init__(self, bus_name, object_path)
+                self.app = app
+                
+            @dbus.service.method('net.sf.meld')
+            def open_paths(self, args, auto_compare):
+                self.app.window.open_paths(args, auto_compare)        
+
+# No dbus support
+except ImportError:
+    pass
+
+
 class FilterEntry(object):
 
     __slots__ = ("label", "active", "filter", "filter_string")
@@ -164,6 +215,8 @@
             version="%prog " + version)
         parser.add_option("-L", "--label", action="append", default=[],
             help=_("Set label to use instead of file name"))
+        parser.add_option("-n", "--newtab", action="store_true", default=False,
+            help=_("Open a new tab in already running instance"))
         parser.add_option("-a", "--auto-compare", action="store_true", default=False,
             help=_("Automatically compare all differing files on startup"))
         parser.add_option("-u", "--unified", action="store_true",
@@ -185,7 +238,29 @@
                 parser.error(_("can't compare more than three directories"))
             self.window.open_paths(files)
 
+        # dbus handling
+        if options.newtab:
+            if not dbus_available:
+                print _("no dbus support, thus option -n --newtab not available.")
+            else:
+            # successfull import dbus
+                running_already = False
+                dbus_app = DBusApp()
+                # check any already registered instance
+                running_already = dbus_app.running_already()
+                if not running_already:
+                # dbus register it
+                    dbus_app.register(self)
+                else:
+                # use existing instance
+                    tab = dbus_app.remote_open_paths(args, options.auto_compare)
+                    self.parse_args_tab(tab, options)
+                    sys.exit(0)
+                    
         tab = self.window.open_paths(args, options.auto_compare)
+        self.parse_args_tab(tab, options)
+
+    def parse_args_tab(self, tab, options):
         if tab:
             tab.set_labels(options.label)
 


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