[caribou] More work on the preferences.
- From: Benjamin Konrath <bkonrath src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [caribou] More work on the preferences.
- Date: Tue, 2 Feb 2010 17:27:22 +0000 (UTC)
commit 7a83a53611c03ff7ec10985220769ab90740712c
Author: Ben Konrath <ben bagu org>
Date: Tue Feb 2 12:20:53 2010 -0500
More work on the preferences.
Fixed an issue with underscores in button labels and changed keyboards to have
consistant naming (keyboard defs are layouts and layers are within the
layouts).
src/caribou/caribou-prefs.ui | 41 ++++++++
src/caribou/keyboard.py | 196 +++++++++++++++++++++---------------
src/caribou/keyboards/qwerty.py | 14 ++--
src/caribou/keyboards/qwerty_sv.py | 12 +-
4 files changed, 168 insertions(+), 95 deletions(-)
---
diff --git a/src/caribou/caribou-prefs.ui b/src/caribou/caribou-prefs.ui
index 1475029..c025447 100644
--- a/src/caribou/caribou-prefs.ui
+++ b/src/caribou/caribou-prefs.ui
@@ -141,6 +141,47 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkTable" id="table2">
+ <property name="visible">True</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">20</property>
+ <property name="row_spacing">5</property>
+ <child>
+ <object class="GtkLabel" id="label_test">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Test settings here:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">entry_test</property>
+ <accessibility>
+ <relation type="label-for" target="entry_test"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="entry_test">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <accessibility>
+ <relation type="labelled-by" target="label_test"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
<property name="position">2</property>
</packing>
</child>
diff --git a/src/caribou/keyboard.py b/src/caribou/keyboard.py
index 972b14d..6329adb 100644
--- a/src/caribou/keyboard.py
+++ b/src/caribou/keyboard.py
@@ -20,12 +20,14 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+import gconf
import gobject
import gtk
-import keyboards
import sys
import virtkey
+import keyboards
+
class KeyboardPreferences:
__gtype_name__ = "KeyboardPreferences"
@@ -40,9 +42,13 @@ class KeyboardPreferences:
close = builder.get_object("button_close")
close.connect("clicked", self.destroy)
+ client = gconf.client_get_default()
+ client.add_dir("/apps/caribou/osk", gconf.CLIENT_PRELOAD_NONE)
+
layout_combo = builder.get_object("combobox_layout")
+ layout_combo.connect("changed", self._on_layout_changed, client)
# we can't use gtk.combo_box_new_text() with glade
- # we have to manually set up simple combobox
+ # we have to manually set up a simple combobox
liststore = gtk.ListStore(gobject.TYPE_STRING)
layout_combo.set_model(liststore)
cell = gtk.CellRendererText()
@@ -51,9 +57,18 @@ class KeyboardPreferences:
for kbddef in keyboards.kbds:
layout_combo.append_text(kbddef)
- layout_combo.set_active(1)
- # grey out the key size and key spacing
+ defaultkbd = client.get_string("/apps/caribou/osk/layout")
+ try:
+ index = keyboards.kbds.index(defaultkbd)
+ except ValueError:
+ print "FIXME: pick a suitable keyboard layout: " + (defaultkbd or "None")
+ layout_combo.set_active(0)
+ else:
+ layout_combo.set_active(index)
+
+ # grey out the key size, key spacing and test area
+ # TODO: implement key size, key spacing and test area
keysize_label = builder.get_object("label_keysize")
keysize_label.set_sensitive(False)
keysize_combo = builder.get_object("combobox_keysize")
@@ -62,112 +77,129 @@ class KeyboardPreferences:
keyspacing_label.set_sensitive(False)
keyspacing_combo = builder.get_object("combobox_keyspacing")
keyspacing_combo.set_sensitive(False)
+ test_label = builder.get_object("label_test")
+ test_label.set_sensitive(False)
+ entry_test = builder.get_object("entry_test")
+ entry_test.set_sensitive(False)
self.window.show_all()
def destroy(self, widget, data = None):
self.window.destroy()
+ def _on_layout_changed(self, combobox, client):
+ kbdname = combobox.get_active_text()
+ if kbdname:
+ client.set_string("/apps/caribou/osk/layout", kbdname)
+
class CaribouKeyboard(gtk.Frame):
__gtype_name__ = "CaribouKeyboard"
+ class _KeyboardLayout:
+ vk = virtkey.virtkey()
+
+ def __init__(self, kdbdef):
+ self.layers, self.switch_layer_buttons = [], []
+ for layer in kdbdef.layers:
+ layervbox = gtk.VBox(homogeneous = True)
+ self.layers.append(layervbox)
+ layervbox.set_name(layer)
+ # get the layer tuple from the string
+ layer = getattr(kdbdef, layer)
+ for row in layer:
+ rowhbox = gtk.HBox(homogeneous = True)
+ for key in row:
+ # check if the key is defined by a string or a tuple
+ if isinstance(key, str):
+ if key == "pf":
+ # preferences key
+ button = gtk.Button()
+ button.set_use_underline(False)
+ image = gtk.image_new_from_pixbuf(
+ button.render_icon(gtk.STOCK_PREFERENCES,
+ gtk.ICON_SIZE_BUTTON))
+ button.set_image(image)
+ button.connect("clicked", self._open_prefs)
+ else:
+ # single utf-8 character key
+ button = gtk.Button(key)
+ button.set_use_underline(False)
+ char = ord(key.decode('utf-8'))
+ button.connect("clicked", self._send_unicode, char)
+ elif isinstance(key, tuple):
+ button = gtk.Button(key[0])
+ button.set_use_underline(False)
+ # check if this key is a layer switch key or not
+ if isinstance(key[1], str):
+ # switch layer key
+ # set layer name on button and save to process later
+ button.set_name(key[1])
+ self.switch_layer_buttons.append(button)
+ else:
+ # regular key
+ button.connect("clicked", self._send_keysym, key[1])
+ else:
+ pass # TODO: throw error here
+
+ rowhbox.pack_start(button, expand = False, fill = True)
+
+ layervbox.pack_start(rowhbox, expand = False, fill = True)
+
+ def _open_prefs(self, widget):
+ KeyboardPreferences()
+
+ def _send_unicode(self, widget, char):
+ self.vk.press_unicode(char)
+ self.vk.release_unicode(char)
+
+ def _send_keysym(self, widget, char):
+ self.vk.press_keysym(char)
+ self.vk.release_keysym(char)
+
def __init__(self):
gtk.Frame.__init__(self)
self.set_shadow_type(gtk.SHADOW_NONE)
- self._vk = virtkey.virtkey()
-
# FIXME: load from stored value, default to locale appropriate
- name = "caribou.keyboards.qwerty"
- #name = "keyboards.qwerty"
- __import__(name)
- kbddef = sys.modules[name]
+ kbdloc = "caribou.keyboards.qwerty"
+ __import__(kbdloc)
+ kbdlayout = self._KeyboardLayout(sys.modules[kbdloc])
+ self._set_kbd_layout(kbdlayout)
# end FIXME
- layouts, switch_buttons = [], []
- for layout in kbddef.layouts:
- layoutvbox = gtk.VBox(homogeneous = True)
- layoutvbox.set_name(layout)
- # get the layout tuple from the string
- layout = getattr(kbddef, layout)
- for row in layout:
- rowhbox = gtk.HBox(homogeneous = True)
- for key in row:
- # check if the key is defined by a string or a tuple
- if isinstance(key, str):
- if key == "pf":
- # preferences key
- button = gtk.Button()
- image = gtk.image_new_from_pixbuf(
- button.render_icon(gtk.STOCK_PREFERENCES,
- gtk.ICON_SIZE_BUTTON))
- button.set_image(image)
- button.connect("clicked", self.__open_prefs)
- else:
- # single utf-8 character key
- button = gtk.Button(key)
- char = ord(key.decode('utf-8'))
- button.connect("clicked", self.__send_unicode, char)
- elif isinstance(key, tuple):
- button = gtk.Button(key[0])
- # check if this key is a layout switch key or not
- if isinstance(key[1], str):
- # switch layout key
- # set layer name on button and save to process later
- button.set_name(key[1])
- switch_buttons.append(button)
- else:
- # regular key
- button.connect("clicked", self.__send_keysym, key[1])
- else:
- pass #TODO throw error here
-
- rowhbox.pack_start(button, expand = False, fill = True)
-
- layoutvbox.pack_start(rowhbox, expand = False, fill = True)
-
- layouts.append(layoutvbox)
+ def _change_layer(self, widget, data):
+ self.remove(self.get_child())
+ self.add(data)
+ self.show_all()
- # connect the change layout buttons
- for button in switch_buttons:
- for layout in layouts:
- if button.get_name() == layout.get_name():
- button.connect("clicked", self.__change_layout, layout)
+ def _set_kbd_layout(self, layout):
+ # FIXME: set kbd name properly
+ self._kbd_name = "qwerty"
+ # connect the change layer buttons
+ for button in layout.switch_layer_buttons:
+ for layer in layout.layers:
+ if button.get_name() == layer.get_name():
+ button.connect("clicked", self._change_layer, layer)
button.set_name("")
break
else:
- print "ERROR" # TODO throw exception
+ print "ERROR" # TODO: throw exception
- # add the first layout and make it visible
- self.add(layouts[0])
- del layouts
- del switch_buttons
+ # add the first layer and make it visible
+ self.add(layout.layers[0])
self.show_all()
- def __send_unicode(self, widget, data):
- self._vk.press_unicode(data)
- self._vk.release_unicode(data)
-
- def __send_keysym(self, widget, data):
- self._vk.press_keysym(data)
- self._vk.release_keysym(data)
+ def get_layout(self):
+ return self._kbd_name()
- def __change_layout(self, widget, data):
- self.remove(self.get_child())
- self.add(data)
- self.show_all()
- def __open_prefs(self, widget):
- prefs = KeyboardPreferences()
if __name__ == "__main__":
- # dynamically import keyboard file
- #name = "keyboards." + keyboards.kbds[0]
- #__import__(name)
- #kbddef = sys.modules[name]
-
# create test window with keyboard
- ckbd = CaribouKeyboard()
+ # run with: python caribou/keyboard.py
+ kbdloc = "keyboards.qwerty"
+ __import__(kbdloc)
+ ckbd = KeyboardLayout(sys.modules[kbdloc])
window = gtk.Window(gtk.WINDOW_POPUP)
window.add(ckbd)
window.show_all()
diff --git a/src/caribou/keyboards/qwerty.py b/src/caribou/keyboards/qwerty.py
index a4478bb..a9b8cf2 100644
--- a/src/caribou/keyboards/qwerty.py
+++ b/src/caribou/keyboards/qwerty.py
@@ -26,7 +26,7 @@ import keysyms
# TODO add noop keysym
# TODO add ability switch back to previous layer after x keystrokes
# TODO ensure keyboard doesn't change size when changing layers
-# TODO finish numbers and punctuation layout
+# TODO finish numbers and punctuation layer
###############################################################################
# keys with keysyms - use known keysyms from keysyms.py or used hex code
@@ -64,11 +64,11 @@ np = (".?12", "num_punct")
lt = ("abc", "lowercase")
###############################################################################
-# keyboard layouts
+# keyboard layers
# rules:
# * key can be a single utf-8 character or a tuple defined above
-# * at least one layout must contain the reserved label "pf" for preferences
-# * layouts must be the same dimensions
+# * at least one layer must contain the reserved label "pf" for preferences
+# * layers must be the same dimensions
###############################################################################
lowercase = ( ("pf", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"),
@@ -84,8 +84,8 @@ num_punct = ( ("!", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"),
("'", "(", ")", ";", ":", le, dn, ri, sp, ".", en) )
###############################################################################
-# list of keyboard layouts - the layout in position 0 will be active when the
-# keyboard is first created
+# list of keyboard layers - the layer in position 0 will be active when the
+# keyboard is first created
###############################################################################
-layouts = ( "lowercase", "uppercase", "num_punct" )
+layers = ( "lowercase", "uppercase", "num_punct" )
diff --git a/src/caribou/keyboards/qwerty_sv.py b/src/caribou/keyboards/qwerty_sv.py
index 2f043ec..f58bd34 100644
--- a/src/caribou/keyboards/qwerty_sv.py
+++ b/src/caribou/keyboards/qwerty_sv.py
@@ -66,11 +66,11 @@ np = (".?12", "num_punct")
lt = ("abc", "lowercase")
###############################################################################
-# keyboard layouts
+# keyboard layers
# rules:
# * key can be a single utf-8 character or a tuple defined above
-# * at least one layout must contain the reserved label "pf" for preferences
-# * layouts must be the same dimensions
+# * at least one layer must contain the reserved label "pf" for preferences
+# * layers must be the same dimensions
###############################################################################
lowercase = ( ( "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", bs),
@@ -90,8 +90,8 @@ num_punct = ( ( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", bs),
###############################################################################
-# list of keyboard layouts - the layout in position 0 will be active when the
-# keyboard is first created
+# list of keyboard layers - the layer in position 0 will be active when the
+# keyboard is first created
###############################################################################
-layouts = ( "lowercase", "uppercase", "num_punct" )
+layers = ( "lowercase", "uppercase", "num_punct" )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]