[caribou: 1/3] Proper highlight colors.



commit 75ad6b94f583d55f30eac5cdab518dbec1c421ea
Author: Eitan Isaacson <eitan monotonous org>
Date:   Mon Aug 16 09:50:43 2010 -0700

    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 @@
                 <property name="border_width">12</property>
                 <property name="spacing">6</property>
                 <child>
-                  <object class="GtkVBox" id="vbox8">
+                  <object class="GtkTable" id="table1">
                     <property name="visible">True</property>
-                    <property name="spacing">6</property>
-                    <property name="homogeneous">True</property>
+                    <property name="n_rows">3</property>
+                    <property name="n_columns">2</property>
+                    <property name="column_spacing">6</property>
+                    <property name="row_spacing">6</property>
                     <child>
-                      <object class="GtkLabel" id="label4">
+                      <object class="GtkColorButton" id="normal_state_color_button">
                         <property name="visible">True</property>
-                        <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Normal state:</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="color">#000000000000</property>
+                        <accessibility>
+                          <relation type="labelled-by" target="label4"/>
+                        </accessibility>
                       </object>
                       <packing>
-                        <property name="expand">False</property>
-                        <property name="padding">6</property>
-                        <property name="position">0</property>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label7">
+                      <object class="GtkColorButton" id="mouse_over_color_button">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="color">#000000000000</property>
+                        <accessibility>
+                          <relation type="labelled-by" target="label7"/>
+                        </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>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label4">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Mouse over:</property>
+                        <property name="label" translatable="yes">Normal state:</property>
+                        <accessibility>
+                          <relation type="label-for" target="normal_state_color_button"/>
+                        </accessibility>
                       </object>
                       <packing>
-                        <property name="expand">False</property>
-                        <property name="padding">6</property>
-                        <property name="position">1</property>
+                        <property name="x_options">GTK_FILL</property>
                       </packing>
                     </child>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkVBox" id="vbox9">
-                    <property name="visible">True</property>
-                    <property name="spacing">6</property>
-                    <property name="homogeneous">True</property>
                     <child>
-                      <object class="GtkColorButton" id="normal_state_color_button">
+                      <object class="GtkLabel" id="label7">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="color">#000000000000</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Mouse over:</property>
+                        <accessibility>
+                          <relation type="label-for" target="mouse_over_color_button"/>
+                        </accessibility>
                       </object>
                       <packing>
-                        <property name="position">0</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkColorButton" id="mouse_over_color_button">
+                      <object class="GtkCheckButton" id="default_colors_checkbox">
+                        <property name="label" translatable="yes">Use Defaults</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="color">#000000000000</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
                       </object>
                       <packing>
-                        <property name="position">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</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 9e0566d..e3f933e 100644
--- a/data/caribou.schemas
+++ b/data/caribou.schemas
@@ -33,5 +33,16 @@
         <long></long>
       </locale>
     </schema>
+    <schema>
+      <key>/schemas/apps/caribou/osk/default_colors</key>
+      <applyto>/apps/caribou/osk/default_colors</applyto>
+      <owner>caribou</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>Use the default theme colors</short>
+        <long></long>
+      </locale>
+    </schema>
   </schemalist>
 </gconfschemafile>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]