[meld] filediff: Simplify our key press/release event handling
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff: Simplify our key press/release event handling
- Date: Mon, 30 Dec 2013 21:22:39 +0000 (UTC)
commit df650dd66edfcfa19bff33b7bebd4fbf15b210fb
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Dec 21 07:52:35 2013 +1000
filediff: Simplify our key press/release event handling
data/ui/filediff.ui | 15 ++++++++-------
meld/filediff.py | 30 ++++++++++++------------------
2 files changed, 20 insertions(+), 25 deletions(-)
---
diff --git a/data/ui/filediff.ui b/data/ui/filediff.ui
index a401ff8..6f82b3f 100644
--- a/data/ui/filediff.ui
+++ b/data/ui/filediff.ui
@@ -108,7 +108,8 @@
<object class="GtkVBox" id="filediff">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
+ <signal name="key-press-event" handler="on_key_event" swapped="no"/>
+ <signal name="key-release-event" handler="on_key_event" swapped="no"/>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
@@ -295,8 +296,8 @@
<property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event"
swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/>
- <signal name="key-release-event" handler="on_key_release_event" swapped="no"/>
- <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
+ <signal name="key-release-event" handler="on_key_event" swapped="no"/>
+ <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
@@ -381,8 +382,8 @@
<property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event"
swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/>
- <signal name="key-release-event" handler="on_key_release_event" swapped="no"/>
- <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
+ <signal name="key-release-event" handler="on_key_event" swapped="no"/>
+ <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
@@ -428,8 +429,8 @@
<property name="can_focus">True</property>
<signal name="button-press-event" handler="on_textview_button_press_event"
swapped="no"/>
<signal name="draw" handler="on_textview_draw" swapped="no"/>
- <signal name="key-release-event" handler="on_key_release_event" swapped="no"/>
- <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
+ <signal name="key-release-event" handler="on_key_event" swapped="no"/>
+ <signal name="key-press-event" handler="on_key_event" swapped="no"/>
<signal name="focus-in-event" handler="on_textview_focus_in_event" swapped="no"/>
<signal name="focus-out-event" handler="on_textview_focus_out_event" swapped="no"/>
<signal name="popup-menu" handler="on_textview_popup_menu" swapped="no"/>
diff --git a/meld/filediff.py b/meld/filediff.py
index b80a940..0ca8f27 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -393,6 +393,18 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.emit("action-mode-changed", mode)
keymask = property(get_keymask, set_keymask)
+ def on_key_event(self, object, event):
+ keymap = Gdk.Keymap.get_default()
+ ok, keyval, group, lvl, consumed = keymap.translate_keyboard_state(
+ event.hardware_keycode, 0, event.group)
+ mod_key = self.keylookup.get(keyval, 0)
+ if event.type == Gdk.EventType.KEY_PRESS:
+ self.keymask |= mod_key
+ if event.keyval == Gdk.KEY_Escape:
+ self.findbar.hide()
+ elif event.type == Gdk.EventType.KEY_RELEASE:
+ self.keymask &= ~mod_key
+
def on_style_set(self, widget, prev_style):
style = widget.get_style()
@@ -844,24 +856,6 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
if key == 'font':
self.load_font()
- def on_key_press_event(self, object, event):
- keymap = Gdk.Keymap.get_default()
- ok, keyval, group, lvl, consumed = keymap.translate_keyboard_state(
- event.hardware_keycode, 0, event.group)
- mod_key = self.keylookup.get(keyval, 0)
- if self.keymask | mod_key != self.keymask:
- self.keymask |= mod_key
- elif event.keyval == Gdk.KEY_Escape:
- self.findbar.hide()
-
- def on_key_release_event(self, object, event):
- keymap = Gdk.Keymap.get_default()
- ok, keyval, group, level, consumed = keymap.translate_keyboard_state(
- event.hardware_keycode, 0, event.group)
- mod_key = self.keylookup.get(keyval, 0)
- if self.keymask & ~mod_key != self.keymask:
- self.keymask &= ~mod_key
-
def check_save_modified(self, label=None):
response = Gtk.ResponseType.OK
modified = [b.data.modified for b in self.textbuffer]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]