[kupfer: 28/51] Port getkey_dialog to use current screen
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 28/51] Port getkey_dialog to use current screen
- Date: Mon, 28 Mar 2011 15:03:25 +0000 (UTC)
commit daa57a876fdda904483312ac08904b703e7b6e45
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Mar 28 16:51:46 2011 +0200
Port getkey_dialog to use current screen
kupfer/plugin/triggers.py | 12 ++++++++----
kupfer/ui/getkey_dialog.py | 19 ++++++++++---------
kupfer/ui/preferences.py | 8 +++++---
3 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/kupfer/plugin/triggers.py b/kupfer/plugin/triggers.py
index f911f2d..9b06f8a 100644
--- a/kupfer/plugin/triggers.py
+++ b/kupfer/plugin/triggers.py
@@ -143,14 +143,15 @@ def try_bind_key(keystr):
return succ
class BindTask (task.Task):
- def __init__(self, leaf):
+ def __init__(self, leaf, screen):
self.leaf = leaf
+ self.screen = screen
def start(self, finish_callback):
glib.idle_add(self.ask_key, finish_callback)
def ask_key(self, finish_callback):
- keystr = getkey_dialog.ask_for_key(try_bind_key)
+ keystr = getkey_dialog.ask_for_key(try_bind_key, screen=self.screen)
if keystr:
Triggers.add_trigger(self.leaf, keystr)
finish_callback(self)
@@ -162,8 +163,11 @@ class AddTrigger (Action):
def is_async(self):
return True
- def activate(self, leaf):
- return BindTask(leaf)
+ def wants_context(self):
+ return True
+
+ def activate(self, leaf, ctx):
+ return BindTask(leaf, ctx.environment.get_screen())
def item_types(self):
yield ComposedLeaf
diff --git a/kupfer/ui/getkey_dialog.py b/kupfer/ui/getkey_dialog.py
index 161d179..cd407e3 100644
--- a/kupfer/ui/getkey_dialog.py
+++ b/kupfer/ui/getkey_dialog.py
@@ -5,8 +5,7 @@ from kupfer import version, config
class GetKeyDialogController(object):
-
- def __init__(self, check_callback=None, previous_key=None):
+ def __init__(self, check_callback=None, previous_key=None, screen=None):
'''@check_callback - optional function to check is entered key is valid.
@previous_key - optional previous keybinding, press equal act like cancel'''
builder = gtk.Builder()
@@ -29,6 +28,8 @@ class GetKeyDialogController(object):
self._previous_key = previous_key
self._press_time = None
+ if screen:
+ self.window.set_screen(screen)
self.window.connect("focus-in-event", self.on_window_focus_in)
self.window.connect("focus-out-event", self.on_window_focus_out)
@@ -47,8 +48,8 @@ class GetKeyDialogController(object):
def on_buttoncancel_activate(self, _widget):
self._return(None)
- def translate_keyboard_event(self, event):
- keymap = gtk.gdk.keymap_get_default()
+ def translate_keyboard_event(self, widget, event):
+ keymap = gtk.gdk.keymap_get_for_display(widget.get_display())
# translate keys properly
keyval, egroup, level, consumed = keymap.translate_keyboard_state(
event.hardware_keycode, event.state, event.group)
@@ -62,12 +63,12 @@ class GetKeyDialogController(object):
accel_label = gtk.accelerator_get_label(keyval, state)
self.labelaccelerator.set_text(accel_label)
- def on_dialoggetkey_key_press_event(self, _widget, event):
+ def on_dialoggetkey_key_press_event(self, widget, event):
self.imagekeybindingaux.hide()
self.labelkeybindingaux.hide()
self._press_time = event.time
- keyval, state = self.translate_keyboard_event(event)
+ keyval, state = self.translate_keyboard_event(widget, event)
keyname = gtk.accelerator_name(keyval, state)
if keyname == 'Escape':
self._return(None)
@@ -78,7 +79,7 @@ class GetKeyDialogController(object):
def on_dialoggetkey_key_release_event(self, widget, event):
if not self._press_time:
return
- keyval, state = self.translate_keyboard_event(event)
+ keyval, state = self.translate_keyboard_event(widget, event)
self.update_accelerator_label(0, 0)
if gtk.accelerator_valid(keyval, state):
@@ -101,7 +102,7 @@ class GetKeyDialogController(object):
pass
-def ask_for_key(check_callback=None, previous_key=None):
- dlg = GetKeyDialogController(check_callback, previous_key)
+def ask_for_key(check_callback=None, previous_key=None, screen=None):
+ dlg = GetKeyDialogController(check_callback, previous_key, screen)
result = dlg.run()
return result
diff --git a/kupfer/ui/preferences.py b/kupfer/ui/preferences.py
index 04dca7a..0177f27 100644
--- a/kupfer/ui/preferences.py
+++ b/kupfer/ui/preferences.py
@@ -306,7 +306,8 @@ class PreferencesWindowController (pretty.OutputMixin):
pass
def on_buttonkeybinding_clicked(self, widget):
- keystr = getkey_dialog.ask_for_key(keybindings.bind_key)
+ keystr = getkey_dialog.ask_for_key(keybindings.bind_key,
+ screen=widget.get_screen())
if keystr:
self.entrykeybinding.set_text(keystr)
self.output_debug("Try set keybinding with", keystr)
@@ -696,7 +697,8 @@ class PreferencesWindowController (pretty.OutputMixin):
setctl = settings.GetSettingsController()
curr_key = setctl.get_global_keybinding(keybind_id)
bind_func = bind_key_func(self.KEYBINDING_TARGETS[keybind_id])
- keystr = getkey_dialog.ask_for_key(bind_func, curr_key)
+ keystr = getkey_dialog.ask_for_key(bind_func, curr_key,
+ screen=treeview.get_screen())
if keystr == '':
keybindings.bind_key(None, self.KEYBINDING_TARGETS[keybind_id])
setctl.set_global_keybinding(keybind_id, keystr)
@@ -720,7 +722,7 @@ class PreferencesWindowController (pretty.OutputMixin):
setctl = settings.GetSettingsController()
curr_key = setctl.get_accelerator(keybind_id)
keystr = getkey_dialog.ask_for_key(self._is_good_keystr,
- previous_key=curr_key)
+ previous_key=curr_key, screen=treeview.get_screen())
if keystr is not None:
setctl.set_accelerator(keybind_id, keystr)
label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]