summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEitan Isaacson <eitan@monotonous.org>2010-08-16 09:50:59 -0700
committerEitan Isaacson <eitan@monotonous.org>2010-08-16 10:00:58 -0700
commitf55c465101446d1543be10e666f6de7a3647775f (patch)
tree6b04011eac370de7242777df03304b06cd150c94
parent75ad6b94f583d55f30eac5cdab518dbec1c421ea (diff)
downloadcaribou-f55c465101446d1543be10e666f6de7a3647775f.tar.gz
Allow user to change key font and size.
https://bugzilla.gnome.org/show_bug.cgi?id=622163
-rw-r--r--caribou/ui/keyboard.py120
-rw-r--r--caribou/ui/window.py8
-rw-r--r--data/caribou-prefs.ui67
-rw-r--r--data/caribou.schemas22
4 files changed, 151 insertions, 66 deletions
diff --git a/caribou/ui/keyboard.py b/caribou/ui/keyboard.py
index 0590924..0737a6f 100644
--- a/caribou/ui/keyboard.py
+++ b/caribou/ui/keyboard.py
@@ -26,6 +26,7 @@ import caribou.common.const as const
import gconf
import gobject
import gtk
+import pango
import sys
import virtkey
import os
@@ -95,7 +96,27 @@ class KeyboardPreferences:
mouse_over_color_button)
+ key_font_button = builder.get_object("key_font_button")
+ key_font_string = client.get_string(
+ const.CARIBOU_GCONF + "/key_font") or "Sans 12"
+ key_font_button.set_font_name(key_font_string)
+ key_font_button.connect('font-set', self._on_key_font_set, client)
+
+ default_font_checkbox = builder.get_object("default_font_checkbox")
+ use_defaults = client.get_bool(const.CARIBOU_GCONF + '/default_font')
+ if use_defaults is None:
+ use_defaults = True
+
+ default_font_checkbox.set_active(use_defaults)
+
+ self._on_default_font_toggled(default_font_checkbox,
+ client, key_font_button)
+
+ default_font_checkbox.connect('toggled',
+ self._on_default_font_toggled,
+ client, key_font_button)
+
kbds = self._fetch_keyboards()
for kbddef in kbds:
layout_combo.append_text(kbddef)
@@ -108,23 +129,16 @@ class KeyboardPreferences:
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")
- 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)
- 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 _on_default_font_toggled(self, default_colors_checkbox, gconf_client,
+ key_font_button):
+
+ use_defaults = default_colors_checkbox.get_active()
+ gconf_client.set_bool(const.CARIBOU_GCONF + '/default_font',
+ use_defaults)
+ key_font_button.set_sensitive(not use_defaults)
+
def _on_default_colors_toggled(self, default_colors_checkbox, gconf_client,
normal_color_button,
mouse_over_color_button):
@@ -160,6 +174,9 @@ class KeyboardPreferences:
color = colorbutton.get_color().to_string()
client.set_string(const.CARIBOU_GCONF + "/mouse_over_color", color)
+ def _on_key_font_set(self, fontbutton, client):
+ font = fontbutton.get_font_name()
+ client.set_string(const.CARIBOU_GCONF + "/key_font", font)
class Key(gtk.Button):
@@ -187,8 +204,29 @@ class Key(gtk.Button):
else:
self.set_label(self.label)
- def set_relative_size(self, size):
- self.set_size_request(int(size * self.width), int(size))
+ self.connect('size-allocate', self._on_size_allocate)
+
+ def _on_size_allocate(self, widget, allocation):
+ widget.set_property('width-request', allocation.height * self.width)
+
+ def set_font(self, font):
+ label = self.get_child()
+ if not isinstance(label, gtk.Label):
+ return
+ rcstyle = label.get_modifier_style()
+ rcstyle.font_desc = pango.FontDescription(font)
+
+ label.modify_style(rcstyle)
+ label.queue_resize()
+
+ def reset_font(self):
+ label = self.get_child()
+ if not isinstance(label, gtk.Label):
+ return
+ rcstyle = label.get_modifier_style()
+ rcstyle.font_desc = None
+ label.modify_style(rcstyle)
+ label.queue_resize()
def set_color(self, normal_color, mouse_over_color):
rcstyle = self.get_modifier_style()
@@ -234,11 +272,12 @@ class KeyboardLayout(gtk.Alignment):
self.layout_name = name
self.rows = []
self.vbox = gtk.VBox()
+ self.vbox.set_homogeneous(True)
self.add(self.vbox)
def add_row(self, row):
self.rows.append(row)
- alignment = gtk.Alignment(0.5, 0.5, 0, 0)
+ alignment = gtk.Alignment(0.5, 0.5, 1, 1)
hbox = gtk.HBox()
for key in row:
hbox.pack_start(key, expand = True, fill = key.fill)
@@ -361,7 +400,36 @@ class CaribouKeyboard(gtk.Notebook):
self._colors_changed)
self.client.notify_add(const.CARIBOU_GCONF + "/default_colors",
self._colors_changed)
+ self.client.notify_add(const.CARIBOU_GCONF + "/default_font",
+ self._key_font_changed)
+ self.client.notify_add(const.CARIBOU_GCONF + "/key_font",
+ self._key_font_changed)
+ self.connect('size-allocate', self._on_size_allocate)
+
+ self.row_height = -1
+
+ def reset_row_height(self):
+ for i in xrange(self.get_n_pages()):
+ layout = self.get_nth_page(i)
+ for row in layout.vbox.get_children():
+ row.set_property('height-request', -1)
+ self.row_height = -1
+
+ def _on_size_allocate(self, notebook, allocation):
+ if self.row_height > 0:
+ return
+
+ for i in xrange(self.get_n_pages()):
+ layout = self.get_nth_page(i)
+ rows = layout.vbox.get_children()
+ height = rows[0].allocation.height
+ self.row_height = max(self.row_height, height)
+ for i in xrange(self.get_n_pages()):
+ layout = self.get_nth_page(i)
+ for row in layout.vbox.get_children():
+ row.set_property('height-request', self.row_height)
+
def load_kb(self, kb_location):
kb_deserializer = KbLayoutDeserializer()
@@ -387,19 +455,25 @@ class CaribouKeyboard(gtk.Notebook):
else:
key.connect('clicked',
self._pressed_normal_key)
- key.set_relative_size(self.key_size)
def _colors_changed(self, client, connection_id, entry, args):
self._update_key_style()
+ def _key_font_changed(self, client, connection_id, entry, args):
+ self.reset_row_height()
+ self._update_key_style()
+
def _update_key_style(self):
default_colors = self.client.get_bool(const.CARIBOU_GCONF +
'/default_colors')
normal_color = self.client.get_string(const.CARIBOU_GCONF +
"/normal_color")
mouse_over_color = self.client.get_string(const.CARIBOU_GCONF +
- "/mouse_over_color") or \
- "yellow"
+ "/mouse_over_color")
+ default_font = self.client.get_bool(const.CARIBOU_GCONF +
+ "/default_font")
+ key_font = self.client.get_string(const.CARIBOU_GCONF +
+ "/key_font")
n_pages = self.get_n_pages()
for i in range(n_pages):
layout = self.get_nth_page(i)
@@ -410,6 +484,10 @@ class CaribouKeyboard(gtk.Notebook):
else:
button.set_color(normal_color,
mouse_over_color)
+ if default_font:
+ button.reset_font()
+ else:
+ button.set_font(key_font)
def _clear(self):
n_pages = self.get_n_pages()
diff --git a/caribou/ui/window.py b/caribou/ui/window.py
index 72647a2..08d3e2f 100644
--- a/caribou/ui/window.py
+++ b/caribou/ui/window.py
@@ -57,6 +57,8 @@ class CaribouWindow(gtk.Window):
if conf_file_path:
text_entry_mech.load_kb(conf_file_path)
+ self.connect('show', self._on_window_show)
+
def set_cursor_location(self, cursor_location):
self._cursor_location = cursor_location
self._update_position()
@@ -163,6 +165,12 @@ class CaribouWindow(gtk.Window):
self.keyboard.hide_all()
gtk.Window.hide_all(self)
+ def _on_window_show(self, window):
+ child = self.get_child()
+ border = self.get_border_width()
+ w, h = child.size_request()
+ self.resize(w + border, h + border)
+
class CaribouWindowDocked(CaribouWindow,
animation.AnimatedWindowBase,
opacity.ProximityWindowBase):
diff --git a/data/caribou-prefs.ui b/data/caribou-prefs.ui
index 8ebb0d5..97fcec0 100644
--- a/data/caribou-prefs.ui
+++ b/data/caribou-prefs.ui
@@ -147,80 +147,57 @@
<property name="border_width">12</property>
<property name="spacing">6</property>
<child>
- <object class="GtkVBox" id="vbox6">
+ <object class="GtkTable" id="table2">
<property name="visible">True</property>
- <property name="spacing">6</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
<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="expand">False</property>
- <property name="padding">6</property>
- <property name="position">0</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="label" translatable="yes">Key font:</property>
<property name="use_underline">True</property>
- <property name="mnemonic_widget">combobox_keyspacing</property>
<accessibility>
- <relation type="label-for" target="combobox_keyspacing"/>
+ <relation type="label-for" target="key_font_button"/>
</accessibility>
</object>
<packing>
- <property name="expand">False</property>
- <property name="padding">6</property>
- <property name="position">1</property>
+ <property name="y_options">GTK_EXPAND</property>
</packing>
</child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkVBox" id="vbox7">
- <property name="visible">True</property>
- <property name="spacing">6</property>
<child>
- <object class="GtkComboBox" id="combobox_keysize">
+ <object class="GtkFontButton" id="key_font_button">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
<accessibility>
<relation type="labelled-by" target="label_keysize"/>
</accessibility>
</object>
<packing>
- <property name="expand">False</property>
- <property name="position">0</property>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
- <object class="GtkComboBox" id="combobox_keyspacing">
+ <object class="GtkCheckButton" id="default_font_checkbox">
+ <property name="label" translatable="yes">Use Defaults</property>
<property name="visible">True</property>
- <accessibility>
- <relation type="labelled-by" target="label_keyspacing"/>
- </accessibility>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
- <property name="expand">False</property>
- <property name="position">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_EXPAND</property>
</packing>
</child>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
diff --git a/data/caribou.schemas b/data/caribou.schemas
index e3f933e..70ab261 100644
--- a/data/caribou.schemas
+++ b/data/caribou.schemas
@@ -44,5 +44,27 @@
<long></long>
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/caribou/osk/key_font</key>
+ <applyto>/apps/caribou/osk/keyboard_font</applyto>
+ <owner>caribou</owner>
+ <type>string</type>
+ <default>Sans 12</default>
+ <locale name="C">
+ <short>Custom font for keyboard/short>
+ <long></long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/caribou/osk/default_font</key>
+ <applyto>/apps/caribou/osk/default_font</applyto>
+ <owner>caribou</owner>
+ <type>bool</type>
+ <default>true</default>
+ <locale name="C">
+ <short>Use the default system font for keyboard</short>
+ <long></long>
+ </locale>
+ </schema>
</schemalist>
</gconfschemafile>