summaryrefslogtreecommitdiff
path: root/src/plugins/pythonconsole/console.py
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2011-03-26 17:37:55 +0000
committerBastien Nocera <hadess@hadess.net>2011-03-27 05:15:02 +0100
commit9cc3129e8f432543a513c4977a453176d191f05b (patch)
tree61cd5a6db2ad859aa8f0285dcec9e2b51edb6c10 /src/plugins/pythonconsole/console.py
parentedebbb33433e8e30b7c5b401a89b3367f274330a (diff)
downloadtotem-9cc3129e8f432543a513c4977a453176d191f05b.tar.gz
pythonconsole: Fix key event handling
Port fixes to key event handling from gedit's pythonconsole Fix the event handling for key events so that typing in the console works as expected. Based on: http://git.gnome.org/browse/gedit/commit/plugins/pythonconsole/pythonconsole/console.py?id=da49b588a394717b5ea0a3f9e6a823a86e62feae http://git.gnome.org/browse/gedit/commit/plugins/pythonconsole/pythonconsole/console.py?id=ba74278347888e4a16f3a0fee2a359b7f2bcde8b Closes: bgo#645762
Diffstat (limited to 'src/plugins/pythonconsole/console.py')
-rw-r--r--src/plugins/pythonconsole/console.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/plugins/pythonconsole/console.py b/src/plugins/pythonconsole/console.py
index f1e6bdd76..6a7118366 100644
--- a/src/plugins/pythonconsole/console.py
+++ b/src/plugins/pythonconsole/console.py
@@ -88,12 +88,13 @@ class PythonConsole(Gtk.ScrolledWindow):
def __key_press_event_cb(self, view, event):
- (_, state) = event.get_state ()
+ modifier_mask = Gtk.accelerator_get_default_mod_mask()
+ event_state = event.state & modifier_mask
- if event.key.keyval == Gdk.KEY_d and state & Gdk.ModifierType.CONTROL_MASK:
+ if event.keyval == Gdk.KEY_d and event_state == Gdk.ModifierType.CONTROL_MASK:
self.destroy()
- elif event.key.keyval == Gdk.KEY_Return and state & Gdk.ModifierType.CONTROL_MASK:
+ elif event.keyval == Gdk.KEY_Return and event_state == Gdk.ModifierType.CONTROL_MASK:
# Get the command
buffer = view.get_buffer()
inp_mark = buffer.get_mark("input")
@@ -119,7 +120,7 @@ class PythonConsole(Gtk.ScrolledWindow):
gobject.idle_add(self.scroll_to_end)
return True
- elif event.key.keyval == Gdk.KEY_Return:
+ elif event.keyval == Gdk.KEY_Return:
# Get the marks
buffer = view.get_buffer()
lin_mark = buffer.get_mark("input-line")
@@ -163,32 +164,32 @@ class PythonConsole(Gtk.ScrolledWindow):
gobject.idle_add(self.scroll_to_end)
return True
- elif event.key.keyval == Gdk.KEY_KP_Down or event.key.keyval == Gdk.KEY_Down:
+ elif event.keyval == Gdk.KEY_KP_Down or event.keyval == Gdk.KEY_Down:
# Next entry from history
view.emit_stop_by_name("key_press_event")
self.history_down()
gobject.idle_add(self.scroll_to_end)
return True
- elif event.key.keyval == Gdk.KEY_KP_Up or event.key.keyval == Gdk.KEY_Up:
+ elif event.keyval == Gdk.KEY_KP_Up or event.keyval == Gdk.KEY_Up:
# Previous entry from history
view.emit_stop_by_name("key_press_event")
self.history_up()
gobject.idle_add(self.scroll_to_end)
return True
- elif event.key.keyval == Gdk.KEY_KP_Left or event.key.keyval == Gdk.KEY_Left or \
- event.key.keyval == Gdk.KEY_BackSpace:
+ elif event.keyval == Gdk.KEY_KP_Left or event.keyval == Gdk.KEY_Left or \
+ event.keyval == Gdk.KEY_BackSpace:
buffer = view.get_buffer()
inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
cur = buffer.get_iter_at_mark(buffer.get_insert())
return inp.compare(cur) == 0
- elif event.key.keyval == Gdk.KEY_Home:
+ elif event.keyval == Gdk.KEY_Home:
# Go to the begin of the command instead of the begin of the line
buffer = view.get_buffer()
inp = buffer.get_iter_at_mark(buffer.get_mark("input"))
- if state & Gdk.ModifierType.SHIFT_MASK:
+ if event_state == Gdk.ModifierType.SHIFT_MASK:
buffer.move_mark_by_name("insert", inp)
else:
buffer.place_cursor(inp)