From 75ad6b94f583d55f30eac5cdab518dbec1c421ea Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 16 Aug 2010 09:50:43 -0700 Subject: Proper highlight colors. https://bugzilla.gnome.org/show_bug.cgi?id=622246 --- caribou/ui/keyboard.py | 65 ++++++++++++++++++++++++++++++------ data/caribou-prefs.ui | 89 ++++++++++++++++++++++++++++++-------------------- data/caribou.schemas | 11 +++++++ 3 files changed, 120 insertions(+), 45 deletions(-) diff --git a/caribou/ui/keyboard.py b/caribou/ui/keyboard.py index 67d580d..0590924 100644 --- a/caribou/ui/keyboard.py +++ b/caribou/ui/keyboard.py @@ -71,12 +71,30 @@ class KeyboardPreferences: mouse_over_color_button = builder.get_object("mouse_over_color_button") mouse_over_color_string = client.get_string(const.CARIBOU_GCONF + - "/mouse_over") or "yellow" + "/mouse_over_color") or "yellow" mouse_over_color = gtk.gdk.Color(mouse_over_color_string) mouse_over_color_button.set_color(mouse_over_color) mouse_over_color_button.connect("color-set", - self._on_mouse_over_color_set, + self._on_mouse_over_color_set, client) + + default_colors_checkbox = builder.get_object("default_colors_checkbox") + use_defaults = client.get_bool(const.CARIBOU_GCONF + '/default_colors') + if use_defaults is None: + use_defaults = True + + default_colors_checkbox.set_active(use_defaults) + + self._on_default_colors_toggled(default_colors_checkbox, + client, normal_color_button, + mouse_over_color_button) + + default_colors_checkbox.connect('toggled', + self._on_default_colors_toggled, + client, normal_color_button, + mouse_over_color_button) + + kbds = self._fetch_keyboards() for kbddef in kbds: @@ -107,6 +125,15 @@ class KeyboardPreferences: self.window.show_all() + def _on_default_colors_toggled(self, default_colors_checkbox, gconf_client, + normal_color_button, + mouse_over_color_button): + use_defaults = default_colors_checkbox.get_active() + gconf_client.set_bool(const.CARIBOU_GCONF + '/default_colors', + use_defaults) + normal_color_button.set_sensitive(not use_defaults) + mouse_over_color_button.set_sensitive(not use_defaults) + def destroy(self, widget, data = None): self.window.destroy() @@ -164,8 +191,18 @@ class Key(gtk.Button): self.set_size_request(int(size * self.width), int(size)) def set_color(self, normal_color, mouse_over_color): - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(normal_color)) - self.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(mouse_over_color)) + rcstyle = self.get_modifier_style() + + rcstyle.bg[gtk.STATE_NORMAL] = gtk.gdk.Color(normal_color) + rcstyle.bg[gtk.STATE_PRELIGHT] = gtk.gdk.Color(mouse_over_color) + + self.modify_style(rcstyle) + + def reset_color(self): + rcstyle = self.get_modifier_style() + rcstyle.bg[gtk.STATE_NORMAL] = None + rcstyle.bg[gtk.STATE_PRELIGHT] = None + self.modify_style(rcstyle) def _get_value(self): return self._value @@ -322,12 +359,15 @@ class CaribouKeyboard(gtk.Notebook): self._colors_changed) self.client.notify_add(const.CARIBOU_GCONF + "/mouse_over_color", self._colors_changed) + self.client.notify_add(const.CARIBOU_GCONF + "/default_colors", + self._colors_changed) + def load_kb(self, kb_location): kb_deserializer = KbLayoutDeserializer() layouts = kb_deserializer.deserialize(kb_location) self._set_layouts(layouts) - self._update_colors() + self._update_key_style() def _set_layouts(self, layout_list): self._clear() @@ -350,11 +390,13 @@ class CaribouKeyboard(gtk.Notebook): key.set_relative_size(self.key_size) def _colors_changed(self, client, connection_id, entry, args): - self._update_colors() + self._update_key_style() - def _update_colors(self): + 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") or "grey80" + "/normal_color") mouse_over_color = self.client.get_string(const.CARIBOU_GCONF + "/mouse_over_color") or \ "yellow" @@ -363,8 +405,11 @@ class CaribouKeyboard(gtk.Notebook): layout = self.get_nth_page(i) for row in layout.rows: for button in row: - button.set_color(normal_color, - mouse_over_color) + if default_colors: + button.reset_color() + else: + button.set_color(normal_color, + mouse_over_color) def _clear(self): n_pages = self.get_n_pages() diff --git a/data/caribou-prefs.ui b/data/caribou-prefs.ui index 6c4a029..8ebb0d5 100644 --- a/data/caribou-prefs.ui +++ b/data/caribou-prefs.ui @@ -244,70 +244,89 @@ 12 6 - + True - 6 - True + 3 + 2 + 6 + 6 - + True - 0 - Normal state: + True + True + #000000000000 + + + - False - 6 - 0 + 1 + 2 - + + True + True + True + #000000000000 + + + + + + 1 + 2 + 1 + 2 + + + + True 0 - Mouse over: + Normal state: + + + - False - 6 - 1 + GTK_FILL - - - False - 0 - - - - - True - 6 - True - + True - True - True - #000000000000 + 0 + Mouse over: + + + - 0 + 1 + 2 + GTK_FILL - + + Use Defaults True True - True - #000000000000 + False + True - 1 + 2 + 2 + 3 - 1 + 0 diff --git a/data/caribou.schemas b/data/caribou.schemas index 9e0566d..e3f933e 100644 --- a/data/caribou.schemas +++ b/data/caribou.schemas @@ -33,5 +33,16 @@ + + /schemas/apps/caribou/osk/default_colors + /apps/caribou/osk/default_colors + caribou + bool + true + + Use the default theme colors + + + -- cgit v1.2.1 From f55c465101446d1543be10e666f6de7a3647775f Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Mon, 16 Aug 2010 09:50:59 -0700 Subject: Allow user to change key font and size. https://bugzilla.gnome.org/show_bug.cgi?id=622163 --- caribou/ui/keyboard.py | 120 ++++++++++++++++++++++++++++++++++++++++--------- caribou/ui/window.py | 8 ++++ data/caribou-prefs.ui | 67 +++++++++------------------ data/caribou.schemas | 22 +++++++++ 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 @@ 12 6 - + True - 6 + 2 + 2 True 0 - Key _size: - True - combobox_keysize - - - - - - False - 6 - 0 - - - - - True - 0 - Key s_pacing: + Key font: True - combobox_keyspacing - + - False - 6 - 1 + GTK_EXPAND - - - False - 0 - - - - - True - 6 - + True + True + True - False - 0 + 1 + 2 + GTK_EXPAND - + + Use Defaults True - - - + True + False + True - False - 1 + 2 + 1 + 2 + GTK_EXPAND - 1 + 0 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 @@ + + /schemas/apps/caribou/osk/key_font + /apps/caribou/osk/keyboard_font + caribou + string + Sans 12 + + Custom font for keyboard/short> + + + + + /schemas/apps/caribou/osk/default_font + /apps/caribou/osk/default_font + caribou + bool + true + + Use the default system font for keyboard + + + -- cgit v1.2.1