[gnome-games/sudoku-css-theming: 4/4] move css to new file, fix background



commit 0b20f5b2332fd9751d356d0661883112ecd548ee
Author: John Stowers <john stowers gmail com>
Date:   Fri May 13 13:32:51 2011 +1200

    move css to new file, fix background

 gnome-sudoku/data/gnome-sudoku.css |   11 +++++++++
 gnome-sudoku/src/lib/number_box.py |   43 ++++++++++++++++--------------------
 2 files changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/gnome-sudoku/data/gnome-sudoku.css b/gnome-sudoku/data/gnome-sudoku.css
new file mode 100644
index 0000000..a06f791
--- /dev/null
+++ b/gnome-sudoku/data/gnome-sudoku.css
@@ -0,0 +1,11 @@
+NumberBox {
+    background-color: rgb(255, 0, 0);
+    color: rgb(0, 0, 255);
+    font: monospace 13;
+}
+
+NumberBox.entry {
+    background-color: rgb(0, 255, 0);
+    color: rgb(0, 127, 127);
+    font: monospace 5;
+}
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index d0447b3..819e9f9 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -1,13 +1,16 @@
 # -*- coding: utf-8 -*-
 #!/usr/bin/python
 
-from gi.repository import Gtk,Gdk,GObject,Pango,PangoCairo
+from gi.repository import Gtk,Gdk,GObject,Pango,PangoCairo, Gio
 import math
 import random
-import tracker_info
+import os.path
+
 from gettext import gettext as _
 
+import tracker_info
 from simple_debug import simple_debug
+from defaults import UI_DIR
 
 ERROR_HIGHLIGHT_COLOR = (1.0, 0, 0)
 
@@ -81,6 +84,7 @@ class NumberBox (Gtk.DrawingArea):
     border_color = None
 
     NOTE_STYLE_CLASS = Gtk.STYLE_CLASS_ENTRY
+    OVERRIDE_BACKGROUND_COLOR_STATES = (Gtk.StateFlags.INSENSITIVE, Gtk.StateFlags.NORMAL)
 
     __gtype_name__ = 'NumberBox'
     __gsignals__ = {
@@ -118,26 +122,21 @@ class NumberBox (Gtk.DrawingArea):
         #should probbably do this in style-updated (but that gets called heaps
         #because of how the background override is done...
         style_ctx = self.get_style_context()
-        #style_ctx.add_class(Gtk.STYLE_CLASS_BUTTON)
         self._layout = self.create_pango_layout(text)
         self._top_note_layout = Pango.Layout(self.create_pango_context())
         self._bottom_note_layout = Pango.Layout(self.create_pango_context())
 
         p = Gtk.CssProvider()
-        p.load_from_data("""
-NumberBox {
-    background-color: rgb(255, 0, 0);
-    color: rgb(0, 0, 255);
-    font: monospace 13;
-}
-
-NumberBox.entry {
-    background-color: rgb(0, 255, 0);
-    color: rgb(0, 127, 127);
-    font: monospace 5;
-}
-""", -1)
+        p.load_from_file(
+            Gio.file_new_for_path(os.path.join(UI_DIR, "gnome-sudoku.css")))
         style_ctx.add_provider(p, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
+
+        #save the background color for later
+        #FIXME: should not need to do this, see
+        #https://bugzilla.gnome.org/show_bug.cgi?id=649779
+        self._saved_background = {}
+        for s in self.OVERRIDE_BACKGROUND_COLOR_STATES:
+            self._saved_background[s] = style_ctx.get_background_color(s)
         
     def set_parent_win(self, new_parent):
         self.parent_win = new_parent
@@ -514,7 +513,6 @@ NumberBox.entry {
             Gtk.render_focus(style_ctx, cr, 0, 0, w, h)
 
         if self.border_color is not None:
-            assert False
             print "border"
             border_width = 3.0
             cr.set_source_rgb(*self.border_color)
@@ -564,13 +562,11 @@ NumberBox.entry {
         # Draw a shadow for tracked conflicts.  This is done to
         # differentiate between tracked and untracked conflicts.
         if self.shadow_color:
-            assert False
             cr.set_source_rgb(*self.shadow_color)
             for xoff, yoff in [(1,1),(2,2)]:
                 cr.move_to((BASE_SIZE/2)-(fontw/2) + xoff, (BASE_SIZE/2) - (fonth/2) + yoff)
                 PangoCairo.show_layout(cr, self._layout)
         if self.text_color:
-            assert False
             cr.set_source_rgb(*self.text_color)
 
         # And draw the text in the middle of the allocated space
@@ -597,25 +593,24 @@ NumberBox.entry {
         style_ctx.restore()
 
     def set_text_color (self, color, shadow = None):
+        print "text -", color
         self.shadow_color = shadow
         self.text_color = color
         self.queue_draw()
 
     def set_background_color (self, color):
         if color:
-            #convert tuple to correct type, None means restore to default so
-            #fall through
+            #convert tuple to correct type, None means restore to default so fall through
             color = Gdk.RGBA(*color)
 
         style_ctx = self.get_style_context()
-        for s in (Gtk.StateFlags.INSENSITIVE, Gtk.StateFlags.NORMAL):
+        for s in self.OVERRIDE_BACKGROUND_COLOR_STATES:
             if color:
                 self.override_background_color(s, color)
             else:
                 #FIXME: should not need to do this, see
                 #https://bugzilla.gnome.org/show_bug.cgi?id=649779
-                self.override_background_color(s, style_ctx.get_color(s))
-
+                self.override_background_color(s, self._saved_background[s])
 
     def set_border_color (self, color):
         self.border_color = color



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