diff options
author | Ben Konrath <ben@bagu.org> | 2010-01-26 19:24:28 -0500 |
---|---|---|
committer | Ben Konrath <ben@bagu.org> | 2010-01-26 19:24:28 -0500 |
commit | 4b75eac52b34148eb8ed03f8751d037de9f616b6 (patch) | |
tree | b38a0385aefff639b65874fb1043c8d9a3f05a56 | |
parent | 7719394530d7c2d69de3ca46779c8843568aa27d (diff) | |
download | caribou-4b75eac52b34148eb8ed03f8751d037de9f616b6.tar.gz |
Add preferences dialog
-rw-r--r-- | src/caribou/caribou-prefs.ui | 182 | ||||
-rw-r--r-- | src/caribou/keyboard.py | 108 | ||||
-rw-r--r-- | src/caribou/keyboards/qwerty.py | 6 | ||||
-rw-r--r-- | src/caribou/keyboards/qwerty_sv.py | 6 |
4 files changed, 257 insertions, 45 deletions
diff --git a/src/caribou/caribou-prefs.ui b/src/caribou/caribou-prefs.ui new file mode 100644 index 0000000..1475029 --- /dev/null +++ b/src/caribou/caribou-prefs.ui @@ -0,0 +1,182 @@ +<?xml version="1.0"?> +<interface> + <requires lib="gtk+" version="2.16"/> + <!-- interface-naming-policy toplevel-contextual --> + <object class="GtkDialog" id="dialog_prefs"> + <property name="border_width">6</property> + <property name="title" translatable="yes">Caribou Preferences</property> + <property name="modal">True</property> + <property name="window_position">center-on-parent</property> + <property name="type_hint">dialog</property> + <property name="has_separator">False</property> + <child internal-child="vbox"> + <object class="GtkVBox" id="vbox_dialog"> + <property name="visible">True</property> + <property name="orientation">vertical</property> + <property name="spacing">2</property> + <child> + <object class="GtkVBox" id="vbox4"> + <property name="visible">True</property> + <property name="border_width">6</property> + <property name="orientation">vertical</property> + <property name="spacing">18</property> + <child> + <object class="GtkAlignment" id="alignment1"> + <property name="visible">True</property> + <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> + <property name="top_padding">6</property> + <property name="left_padding">12</property> + <child> + <object class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="n_rows">3</property> + <property name="n_columns">2</property> + <property name="column_spacing">20</property> + <property name="row_spacing">5</property> + <child> + <object class="GtkComboBox" id="combobox_layout"> + <property name="visible">True</property> + <accessibility> + <relation type="labelled-by" target="label_layout"/> + </accessibility> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="combobox_keysize"> + <property name="visible">True</property> + <accessibility> + <relation type="labelled-by" target="label_keysize"/> + </accessibility> + </object> + <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="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label_keysize"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Key _size:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combobox_keysize</property> + <accessibility> + <relation type="label-for" target="combobox_keysize"/> + </accessibility> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label_layout"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Keyboard _layout:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combobox_layout</property> + <accessibility> + <relation type="label-for" target="combobox_layout"/> + </accessibility> + </object> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label_keyspacing"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Key s_pacing:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">combobox_keyspacing</property> + <accessibility> + <relation type="label-for" target="combobox_keyspacing"/> + </accessibility> + </object> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="combobox_keyspacing"> + <property name="visible">True</property> + <accessibility> + <relation type="labelled-by" target="label_keyspacing"/> + </accessibility> + </object> + <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="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + </object> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child internal-child="action_area"> + <object class="GtkHButtonBox" id="dialog-action_area1"> + <property name="visible">True</property> + <property name="layout_style">end</property> + <child> + <placeholder/> + </child> + <child> + <object class="GtkButton" id="button_close"> + <property name="label">gtk-close</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="can_default">True</property> + <property name="receives_default">False</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </object> + </child> + <action-widgets> + <action-widget response="0">button_close</action-widget> + </action-widgets> + </object> +</interface> diff --git a/src/caribou/keyboard.py b/src/caribou/keyboard.py index d1aafd5..972b14d 100644 --- a/src/caribou/keyboard.py +++ b/src/caribou/keyboard.py @@ -20,41 +20,89 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +import gobject import gtk +import keyboards +import sys import virtkey -class CaribouPredicitionArea(gtk.HBox): - pass +class KeyboardPreferences: + __gtype_name__ = "KeyboardPreferences" + + def __init__(self): + builder = gtk.Builder() + builder.add_from_file("caribou/caribou-prefs.ui") + + self.window = builder.get_object("dialog_prefs") + self.window.connect("destroy", self.destroy) + self.window.connect("delete_event", self.destroy) + + close = builder.get_object("button_close") + close.connect("clicked", self.destroy) + + layout_combo = builder.get_object("combobox_layout") + # we can't use gtk.combo_box_new_text() with glade + # we have to manually set up simple combobox + liststore = gtk.ListStore(gobject.TYPE_STRING) + layout_combo.set_model(liststore) + cell = gtk.CellRendererText() + layout_combo.pack_start(cell, True) + layout_combo.add_attribute(cell, 'text', 0) + + for kbddef in keyboards.kbds: + layout_combo.append_text(kbddef) + layout_combo.set_active(1) + + # grey out the key size and key spacing + keysize_label = builder.get_object("label_keysize") + keysize_label.set_sensitive(False) + keysize_combo = builder.get_object("combobox_keysize") + keysize_combo.set_sensitive(False) + keyspacing_label = builder.get_object("label_keyspacing") + keyspacing_label.set_sensitive(False) + keyspacing_combo = builder.get_object("combobox_keyspacing") + keyspacing_combo.set_sensitive(False) + + self.window.show_all() + + def destroy(self, widget, data = None): + self.window.destroy() -# TODO validate keyboard by creating this object and catching exception class CaribouKeyboard(gtk.Frame): __gtype_name__ = "CaribouKeyboard" - def __init__(self, keyboard): + 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] + # end FIXME + layouts, switch_buttons = [], [] - for layout in keyboard.layouts: - layoutvbox = gtk.VBox(homogeneous=True) + for layout in kbddef.layouts: + layoutvbox = gtk.VBox(homogeneous = True) layoutvbox.set_name(layout) - layout = getattr(keyboard, layout) + # get the layout tuple from the string + layout = getattr(kbddef, layout) for row in layout: - rowhbox = gtk.HBox(homogeneous=True) + rowhbox = gtk.HBox(homogeneous = True) for key in row: - # check if the key is a simple str or a key defined by a tuple + # check if the key is defined by a string or a tuple if isinstance(key, str): - if key == "cf": - # configuration key + 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.set_name ("configuration") - switch_buttons.append(button) + button.connect("clicked", self.__open_prefs) else: # single utf-8 character key button = gtk.Button(key) @@ -74,31 +122,12 @@ class CaribouKeyboard(gtk.Frame): else: pass #TODO throw error here - rowhbox.pack_start(button, expand=False, fill=True) + rowhbox.pack_start(button, expand = False, fill = True) - layoutvbox.pack_start(rowhbox, expand=False, fill=True) + layoutvbox.pack_start(rowhbox, expand = False, fill = True) layouts.append(layoutvbox) - # add preferences layout - image = gtk.Image() - image.set_from_icon_name("gnome-dev-keyboard", gtk.ICON_SIZE_BUTTON) - button = gtk.Button() - button.set_image(image) - button.set_name(layouts[0].get_name()) - switch_buttons.append(button) - - confhbox = gtk.HBox() - confhbox.pack_start(button) - confhbox.pack_start(gtk.Label("configuration coming soon")) - - confvbox = gtk.VBox(homogeneous=True) - confvbox.pack_start(confhbox) - confvbox.pack_start(gtk.HBox()) - confvbox.pack_start(gtk.HBox()) - confvbox.set_name("configuration") - layouts.append(confvbox) - # connect the change layout buttons for button in switch_buttons: for layout in layouts: @@ -128,16 +157,17 @@ class CaribouKeyboard(gtk.Frame): self.add(data) self.show_all() + def __open_prefs(self, widget): + prefs = KeyboardPreferences() if __name__ == "__main__": # dynamically import keyboard file - import keyboards, sys - name = "keyboards." + keyboards.kbds[0] - __import__(name) - kbddef = sys.modules[name] + #name = "keyboards." + keyboards.kbds[0] + #__import__(name) + #kbddef = sys.modules[name] # create test window with keyboard - ckbd = CaribouKeyboard(kbddef) + ckbd = CaribouKeyboard() 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 78bf8d7..a4478bb 100644 --- a/src/caribou/keyboards/qwerty.py +++ b/src/caribou/keyboards/qwerty.py @@ -67,15 +67,15 @@ lt = ("abc", "lowercase") # keyboard layouts # rules: # * key can be a single utf-8 character or a tuple defined above -# * at least one layout must contain the reserved label "cf" for configuration +# * at least one layout must contain the reserved label "pf" for preferences # * layouts must be the same dimensions ############################################################################### -lowercase = ( ("cf", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"), +lowercase = ( ("pf", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"), ( np, "a", "s", "d", "f", "g", "h", "j", "k", "l", bs), ( su, "z", "x", "c", "v", "b", "n", "m", sp, ".", en) ) -uppercase = ( ("cf", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"), +uppercase = ( ("pf", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"), ( np, "A", "S", "D", "F", "G", "H", "J", "K", "L", bs), ( sd, "Z", "X", "C", "V", "B", "N", "M", sp, ".", en) ) diff --git a/src/caribou/keyboards/qwerty_sv.py b/src/caribou/keyboards/qwerty_sv.py index a34a1e8..2f043ec 100644 --- a/src/caribou/keyboards/qwerty_sv.py +++ b/src/caribou/keyboards/qwerty_sv.py @@ -69,19 +69,19 @@ lt = ("abc", "lowercase") # keyboard layouts # rules: # * key can be a single utf-8 character or a tuple defined above -# * at least one layout must contain the reserved label "cf" for configuration +# * at least one layout must contain the reserved label "pf" for preferences # * layouts must be the same dimensions ############################################################################### lowercase = ( ( "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", bs), ( "a", "s", "d", "f", "g", "h", "j", "k", "l", "å", pu), ( "z", "x", "c", "v", "b", "n", "m", ".", "ö", "ä", en), - ( su, np,"cf", sp, le, up, ri, dn, om, nd, pd) ) + ( su, np,"pf", sp, le, up, ri, dn, om, nd, pd) ) uppercase = ( ( "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", bs), ( "A", "S", "D", "F", "G", "H", "J", "K", "L", "Å", pu), ( "Z", "X", "C", "V", "B", "N", "M", ".", "Ö", "Ä", en), - ( sd, np,"cf", sp, le, ri, up, dn, om, nd, pd) ) + ( sd, np,"pf", sp, le, ri, up, dn, om, nd, pd) ) num_punct = ( ( "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", bs), ( "!", "@", "€", "£", "$", "/", "+", "-", "=", "?", "*"), |