summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-08-21 13:49:34 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-08-21 13:49:34 +0800
commitc77adbb5dea1bfd4fe275c9789623a0360677c9e (patch)
tree6bffad692c996f569151d3c8777e2e87d257dbd5
parent766f22120dfeaa883ef0c3346898d9a7a690dd11 (diff)
downloadibus-c77adbb5dea1bfd4fe275c9789623a0360677c9e.tar.gz
ibus-c77adbb5dea1bfd4fe275c9789623a0360677c9e.tar.xz
ibus-c77adbb5dea1bfd4fe275c9789623a0360677c9e.zip
Add configure items for keyboard shortcuts.
-rw-r--r--daemon/bus.py49
-rw-r--r--ibus/modifier.py10
-rw-r--r--setup/keyboardshortcut.py2
-rw-r--r--setup/setup.glade111
4 files changed, 110 insertions, 62 deletions
diff --git a/daemon/bus.py b/daemon/bus.py
index 6e68f1e..068da15 100644
--- a/daemon/bus.py
+++ b/daemon/bus.py
@@ -60,9 +60,29 @@ class IBus(ibus.Object):
self.__connections = list()
self.__prev_key = None
- self.__shortcut_trigger = [(keysyms.space, modifier.CONTROL_MASK)]
- m = modifier.CONTROL_MASK | modifier.SHIFT_MASK | modifier.RELEASE_MASK
- self.__shortcut_next_engine = [(keysyms.Shift_L, m), (keysyms.Shift_R, m)]
+
+ self.__shortcut_trigger = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"])
+ self.__shortcut_next_engine = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
+ ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"])
+ self.__shortcut_prev_engine = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, [])
+
+ def __load_config_shortcut(self, config_key, default_value):
+
+ # load trigger
+ shortcut_strings = default_value
+ try:
+ shortcut_strings = self.__config.get_value(config_key)
+ except:
+ pass
+ shortcuts = []
+ for s in shortcut_strings:
+ keyval, keymask = self.__parse_shortcut_string(s)
+ if keyval != 0:
+ shortcuts.append((keyval, keymask))
+ return shortcuts
def new_connection(self, dbusconn):
conn = Connection(dbusconn)
@@ -436,6 +456,19 @@ class IBus(ibus.Object):
if key in self.__config_watch:
self.__config_watch[key].remove(conn)
+ def __parse_shortcut_string(self, string):
+ keys = string.split("+")
+ keymask = 0
+ for name, mask in modifier.MODIFIER_NAME_TABLE:
+ if name in keys[:-1]:
+ keymask |= mask
+ keyname = keys[-1]
+ if keyname[0] in "1234567890":
+ keyname = "_" + keyname
+ keyval = keysyms.__dict__.get(keyname, 0)
+
+ return keyval, keymask
+
def __config_value_changed_cb(self, config, key, value):
for _dir in self.__config_watch.keys():
if key.startswith(_dir):
@@ -444,11 +477,15 @@ class IBus(ibus.Object):
# check daemon configure
if key == CONFIG_GENERAL_SHORTCUT_TRIGGER:
- print value
+ self.__shortcut_trigger = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_TRIGGER, ["Ctrl+space"])
elif key == CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE:
- print value
+ self.__shortcut_next_engine = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE,
+ ["Ctrl+Shift+Release+Shift_L", "Ctrl+Shift+Release+Shift_R"])
elif key == CONFIG_GENERAL_SHORTCUT_PREV_ENGINE:
- print value
+ self.__shortcut_prev_engine = self.__load_config_shortcut(
+ CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE, [])
def __config_destroy_cb(self, config):
if config == self.__config:
diff --git a/ibus/modifier.py b/ibus/modifier.py
index b652bd9..7f6afad 100644
--- a/ibus/modifier.py
+++ b/ibus/modifier.py
@@ -42,3 +42,13 @@ RELEASE_MASK = 1 << 30
MODIFIER_MASK = 0x5c001fff
+MODIFIER_NAME_TABLE = (
+ ("Shift", SHIFT_MASK),
+ ("CapsLock", LOCK_MASK),
+ ("Ctrl", CONTROL_MASK),
+ ("Alt", MOD1_MASK),
+ ("SUPER", SUPER_MASK),
+ ("Hyper", HYPER_MASK),
+ ("Meta", META_MASK),
+ ("Release", RELEASE_MASK),
+)
diff --git a/setup/keyboardshortcut.py b/setup/keyboardshortcut.py
index eeca766..eb6219e 100644
--- a/setup/keyboardshortcut.py
+++ b/setup/keyboardshortcut.py
@@ -82,11 +82,11 @@ class KeyboardShortcutSelection(gtk.VBox):
self.__modifier_buttons.append(("Ctrl", gtk.CheckButton("_Ctrl"), gdk.CONTROL_MASK))
self.__modifier_buttons.append(("Alt", gtk.CheckButton("A_lt"), gdk.MOD1_MASK))
self.__modifier_buttons.append(("Shift", gtk.CheckButton("_Shift"), gdk.SHIFT_MASK))
- self.__modifier_buttons.append(("Release", gtk.CheckButton("_Release"), gdk.RELEASE_MASK))
self.__modifier_buttons.append(("Meta", gtk.CheckButton("_Meta"), gdk.META_MASK))
self.__modifier_buttons.append(("Super", gtk.CheckButton("S_uper"), gdk.SUPER_MASK))
self.__modifier_buttons.append(("Hyper", gtk.CheckButton("_Hyper"), gdk.HYPER_MASK))
self.__modifier_buttons.append(("Capslock", gtk.CheckButton("Capsloc_k"), gdk.LOCK_MASK))
+ self.__modifier_buttons.append(("Release", gtk.CheckButton("_Release"), gdk.RELEASE_MASK))
for name, button, mask in self.__modifier_buttons:
button.connect("toggled", self.__modifier_button_toggled_cb, name)
diff --git a/setup/setup.glade b/setup/setup.glade
index 79294cd..d8d1c9d 100644
--- a/setup/setup.glade
+++ b/setup/setup.glade
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.4 on Thu Aug 21 07:52:13 2008 -->
+<!--Generated with glade3 3.4.4 on Thu Aug 21 13:47:06 2008 -->
<glade-interface>
<widget class="GtkDialog" id="dialog_setup">
<property name="border_width">5</property>
@@ -49,13 +49,19 @@
<property name="n_rows">3</property>
<property name="n_columns">3</property>
<child>
- <widget class="GtkLabel" id="label7">
+ <widget class="GtkButton" id="button_prev_engine">
<property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Trigger:</property>
- <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">...</property>
+ <property name="response_id">0</property>
</widget>
<packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
@@ -63,46 +69,51 @@
</packing>
</child>
<child>
- <widget class="GtkEntry" id="entry_trigger">
+ <widget class="GtkButton" id="button_next_engine">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="editable">False</property>
+ <property name="receives_default">True</property>
+ <property name="label" translatable="yes">...</property>
+ <property name="response_id">0</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label8">
+ <widget class="GtkEntry" id="entry_prev_engine">
<property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Next engine:</property>
- <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
</widget>
<packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label9">
+ <widget class="GtkEntry" id="entry_next_engine">
<property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Previous engine:</property>
- <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
</widget>
<packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
@@ -126,69 +137,59 @@
</packing>
</child>
<child>
- <widget class="GtkEntry" id="entry_next_engine">
+ <widget class="GtkLabel" id="label9">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Previous engine:</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
</packing>
</child>
<child>
- <widget class="GtkEntry" id="entry_prev_engine">
+ <widget class="GtkLabel" id="label8">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Next engine:</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
</widget>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
</packing>
</child>
<child>
- <widget class="GtkButton" id="button_next_engine">
+ <widget class="GtkEntry" id="entry_trigger">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">...</property>
- <property name="response_id">0</property>
+ <property name="editable">False</property>
</widget>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>
<property name="y_padding">4</property>
</packing>
</child>
<child>
- <widget class="GtkButton" id="button_prev_engine">
+ <widget class="GtkLabel" id="label7">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">...</property>
- <property name="response_id">0</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Trigger:</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
</widget>
<packing>
- <property name="left_attach">2</property>
- <property name="right_attach">3</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
<property name="x_padding">4</property>