[meld/deprecation-cleanup] melddoc: Move label-changed to new signal style



commit de3dd6258a00a6629fc339ed527879a61d085b90
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 9 06:09:30 2018 +1000

    melddoc: Move label-changed to new signal style
    
    The main reason for this is that it seems basically impossible to
    inherit signals (because of a mix of GObject limitations and intentional
    pygobject barriers). As such, the attribute-style declaration is the
    easiest and cleanest way I've found to enable "inheriting" these via
    dumb class-level name assignments.

 meld/dirdiff.py    |  2 +-
 meld/filediff.py   |  2 +-
 meld/melddoc.py    | 10 +++-------
 meld/newdifftab.py |  7 +++----
 meld/vcview.py     |  2 +-
 5 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index a786fa3f..862251b5 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -1535,7 +1535,7 @@ class DirDiff(tree.TreeviewCommon, MeldDoc, Component):
             shortnames = misc.shorten_names(*filenames)
         self.label_text = " : ".join(shortnames)
         self.tooltip_text = self.label_text
-        self.label_changed()
+        self.label_changed.emit(self.label_text, self.tooltip_text)
 
     def set_labels(self, labels):
         labels = labels[:self.num_panes]
diff --git a/meld/filediff.py b/meld/filediff.py
index 9ba3051c..47051350 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1085,7 +1085,7 @@ class FileDiff(MeldDoc, Component):
         else:
             self.label_text = " — ".join(shortnames)
         self.tooltip_text = self.label_text
-        self.label_changed()
+        self.label_changed.emit(self.label_text, self.tooltip_text)
 
     def pre_comparison_init(self):
         self._disconnect_buffer_handlers()
diff --git a/meld/melddoc.py b/meld/melddoc.py
index da00de58..617bdbe8 100644
--- a/meld/melddoc.py
+++ b/meld/melddoc.py
@@ -59,17 +59,13 @@ class ComparisonState(enum.IntEnum):
 
 
 class LabeledObjectMixin(GObject.GObject):
-    __gsignals__ = {
-        'label-changed': (
-            GObject.SignalFlags.RUN_FIRST, None,
-            (GObject.TYPE_STRING, GObject.TYPE_STRING)),
-    }
 
     label_text = _("untitled")
     tooltip_text = None
 
-    def label_changed(self):
-        self.emit("label-changed", self.label_text, self.tooltip_text)
+    @GObject.Signal
+    def label_changed(self, label_text: str, tooltip_text: str) -> None:
+        ...
 
 
 class MeldDoc(LabeledObjectMixin, GObject.GObject):
diff --git a/meld/newdifftab.py b/meld/newdifftab.py
index 944da646..7840f53f 100644
--- a/meld/newdifftab.py
+++ b/meld/newdifftab.py
@@ -44,13 +44,12 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
     __gtype_name__ = "NewDiffTab"
 
     __gsignals__ = {
-        'label-changed': (
-            GObject.SignalFlags.RUN_FIRST, None,
-            (GObject.TYPE_STRING, GObject.TYPE_STRING)),
         'close': (GObject.SignalFlags.RUN_FIRST, None, (bool,)),
         'diff-created': (GObject.SignalFlags.RUN_FIRST, None, (object,)),
     }
 
+    label_changed_signal = LabeledObjectMixin.label_changed
+
     label_text = _("New comparison")
 
     button_compare = Template.Child()
@@ -191,7 +190,7 @@ class NewDiffTab(Gtk.Alignment, LabeledObjectMixin):
         self.emit('diff-created', tab)
 
     def on_container_switch_in_event(self, *args):
-        self.label_changed()
+        self.label_changed.emit(self.label_text, self.tooltip_text)
 
     def on_container_switch_out_event(self, *args):
         pass
diff --git a/meld/vcview.py b/meld/vcview.py
index 63d2c985..28511fff 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -329,7 +329,7 @@ class VcView(tree.TreeviewCommon, MeldDoc, Component):
         self.label_text = os.path.basename(self.location)
         # TRANSLATORS: This is the location of the directory being viewed
         self.tooltip_text = _("%s: %s") % (_("Location"), self.location)
-        self.label_changed()
+        self.label_changed.emit(self.label_text, self.tooltip_text)
 
     def _search_recursively_iter(self, start_path, replace=False):
 


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