Fix not to emit property-activate when state is not changed.
authorfujiwarat <takao.fujiwara1@gmail.com>
Mon, 17 May 2010 09:17:57 +0000 (18:17 +0900)
committerfujiwarat <takao.fujiwara1@gmail.com>
Tue, 18 May 2010 05:59:23 +0000 (14:59 +0900)
ui/gtk/menu.py
ui/gtk/toolitem.py

index 7d69670..b9a6b44 100644 (file)
@@ -157,11 +157,19 @@ class CheckMenuItem(gtk.CheckMenuItem, PropItem):
             self.hide_all()
 
     def do_toggled(self):
+        # Do not send property-activate to engine in case the event is
+        # sent from engine.
+        do_emit = False
         if self.get_active():
+            if self._prop.state != ibus.PROP_STATE_CHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_CHECKED
         else:
+            if self._prop.state != ibus.PROP_STATE_UNCHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_UNCHECKED
-        self.emit("property-activate", self._prop.key, self._prop.state)
+        if do_emit:
+            self.emit("property-activate", self._prop.key, self._prop.state)
 
     def property_changed(self):
         self.set_active(self._prop.state == ibus.PROP_STATE_CHECKED)
@@ -207,11 +215,19 @@ class RadioMenuItem(gtk.RadioMenuItem, PropItem):
             self.hide_all()
 
     def do_toggled(self):
+        # Do not send property-activate to engine in case the event is
+        # sent from engine.
+        do_emit = False
         if self.get_active():
+            if self._prop.state != ibus.PROP_STATE_CHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_CHECKED
         else:
+            if self._prop.state != ibus.PROP_STATE_UNCHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_UNCHECKED
-        self.emit("property-activate", self._prop.key, self._prop.state)
+        if do_emit:
+            self.emit("property-activate", self._prop.key, self._prop.state)
 
 class SeparatorMenuItem(gtk.SeparatorMenuItem, PropItem):
     __gtype_name__ = "IBusSeparatorMenuItem"
index 071ab08..4bdffba 100644 (file)
@@ -135,11 +135,19 @@ class ToggleToolButton(gtk.ToggleToolButton, PropItem):
             self.hide_all()
 
     def do_toggled(self):
+        # Do not send property-activate to engine in case the event is
+        # sent from engine.
+        do_emit = False
         if self.get_active():
+            if self._prop.state != ibus.PROP_STATE_CHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_CHECKED
         else:
+            if self._prop.state != ibus.PROP_STATE_UNCHECKED:
+                do_emit = True
             self._prop.state = ibus.PROP_STATE_UNCHECKED
-        self.emit("property-activate", self._prop.key, self._prop.state)
+        if do_emit:
+            self.emit("property-activate", self._prop.key, self._prop.state)
 
 class SeparatorToolItem(gtk.SeparatorToolItem, PropItem):
     __gtype_name__ = "IBusSeparatorToolItem"