[kupfer: 11/51] emit d-bus signal BoundKeyChanged



commit bce3f12fea20302ae5f32acd2b68bd6c26139275
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 28 16:51:42 2011 +0200

    emit d-bus signal BoundKeyChanged

 kupfer/ui/browser.py     |    2 ++
 kupfer/ui/keybindings.py |    8 ++++++++
 kupfer/ui/listen.py      |    4 ++--
 3 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 8635576..bdedc11 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -2167,6 +2167,8 @@ class WindowController (pretty.OutputMixin):
 			kserv.connect("execute-file", self._execute_file_received)
 			kserv.connect("quit", self.quit)
 			keyobj = keybindings.GetKeyboundObject()
+			keyobj.connect("bound-key-changed",
+			               lambda x,y,z: kserv.BoundKeyChanged(y,z))
 			kserv.connect("relay-keys", keyobj.relayed_keys)
 
 		# Load data and present UI
diff --git a/kupfer/ui/keybindings.py b/kupfer/ui/keybindings.py
index 14b719c..e8e6ee4 100644
--- a/kupfer/ui/keybindings.py
+++ b/kupfer/ui/keybindings.py
@@ -32,6 +32,8 @@ class KeyboundObject (gobject.GObject):
 		import keybinder
 		time = keybinder.get_current_event_time()
 		self.emit("keybinding", target, time, "")
+	def emit_bound_key_changed(self, keystring, is_bound):
+		self.emit("bound-key-changed", keystring, is_bound)
 	def relayed_keys(self, sender, keystring, display):
 		for target, key in _currently_bound.iteritems():
 			if keystring == key:
@@ -41,6 +43,10 @@ class KeyboundObject (gobject.GObject):
 gobject.signal_new("keybinding", KeyboundObject, gobject.SIGNAL_RUN_LAST,
 		gobject.TYPE_BOOLEAN,
 		(gobject.TYPE_INT, gobject.TYPE_INT64, gobject.TYPE_STRING))
+# Arguments: Keystring, Boolean
+gobject.signal_new("bound-key-changed", KeyboundObject, gobject.SIGNAL_RUN_LAST,
+		gobject.TYPE_BOOLEAN,
+		(gobject.TYPE_STRING, gobject.TYPE_BOOLEAN,))
 
 _currently_bound = {}
 
@@ -84,6 +90,7 @@ def bind_key(keystr, keybinding_target=KEYBINDING_DEFAULT):
 		try:
 			succ = keybinder.bind(keystr, callback)
 			pretty.print_debug(__name__, "binding", repr(keystr))
+			GetKeyboundObject().emit_bound_key_changed(keystr, True)
 		except KeyError, exc:
 			pretty.print_error(__name__, exc)
 			succ = False
@@ -92,6 +99,7 @@ def bind_key(keystr, keybinding_target=KEYBINDING_DEFAULT):
 		if old_keystr and old_keystr != keystr:
 			keybinder.unbind(old_keystr)
 			pretty.print_debug(__name__, "unbinding", repr(old_keystr))
+			GetKeyboundObject().emit_bound_key_changed(old_keystr, False)
 		_register_bound_key(keystr, keybinding_target)
 	return succ
 
diff --git a/kupfer/ui/listen.py b/kupfer/ui/listen.py
index 24562e4..acc02d6 100644
--- a/kupfer/ui/listen.py
+++ b/kupfer/ui/listen.py
@@ -110,8 +110,8 @@ class Service (ExportedGObject):
 		from kupfer.ui import keybindings
 		return keybindings.get_all_bound_keys()
 
-	@dbus.service.signal(interface_name, signature="ay")
-	def KeyWasBound(self, keystr):
+	@dbus.service.signal(interface_name, signature="sb")
+	def BoundKeyChanged(self, keystr, is_bound):
 		pass
 
 	@dbus.service.method(interface_name)



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