[hamster-applet] theme color fixes (bug 623917) - try to grab style from the realised widget where possible



commit c18d8858ba41e9e01f08bc95f1eb2c292422748a
Author: Toms Bauģis <toms baugis gmail com>
Date:   Mon Jul 12 13:26:54 2010 +0100

    theme color fixes (bug 623917) - try to grab style from the realised widget where possible

 src/hamster/charting.py              |   24 ++++-----------------
 src/hamster/stats.py                 |    6 +----
 src/hamster/stuff.py                 |   29 --------------------------
 src/hamster/widgets/__init__.py      |    7 +++--
 src/hamster/widgets/activityentry.py |   37 ++++++++++++++++++++++------------
 src/hamster/widgets/dayline.py       |   13 +++++++----
 src/hamster/widgets/facttree.py      |   18 ++++++++++++---
 src/hamster/widgets/tags.py          |    4 ++-
 src/hamster/widgets/timechart.py     |   22 ++++++++------------
 9 files changed, 68 insertions(+), 92 deletions(-)
---
diff --git a/src/hamster/charting.py b/src/hamster/charting.py
index a823707..d4f0132 100644
--- a/src/hamster/charting.py
+++ b/src/hamster/charting.py
@@ -99,18 +99,11 @@ class Chart(graphics.Scene):
 
     def find_colors(self):
         bg_color = self.get_style().bg[gtk.STATE_NORMAL].to_string()
-        if self.colors.is_light(bg_color):
-            self.bar_color = self.colors.darker(bg_color,  30)
-        else:
-            self.bar_color = self.colors.darker(bg_color,  -30)
-
+        self.bar_color = self.colors.contrast(bg_color, 30)
 
         # now for the text - we want reduced contrast for relaxed visuals
         fg_color = self.get_style().fg[gtk.STATE_NORMAL].to_string()
-        if self.colors.is_light(fg_color):
-            self.label_color = self.colors.darker(fg_color,  80)
-        else:
-            self.label_color = self.colors.darker(fg_color,  -80)
+        self.label_color = self.colors.contrast(fg_color,  80)
 
 
     def on_mouse_over(self, scene, targets):
@@ -258,7 +251,7 @@ class HorizontalDayChart(graphics.Scene):
 
         # TODO - should handle the layout business in graphics
         self.layout = context.create_layout()
-        default_font = pango.FontDescription(gtk.Style().font_desc.to_string())
+        default_font = pango.FontDescription(self.get_style().font_desc.to_string())
         default_font.set_size(8 * pango.SCALE)
         self.layout.set_font_description(default_font)
 
@@ -290,11 +283,7 @@ class HorizontalDayChart(graphics.Scene):
 
         # now for the text - we want reduced contrast for relaxed visuals
         fg_color = self.get_style().fg[gtk.STATE_NORMAL].to_string()
-        if self.colors.is_light(fg_color):
-            label_color = self.colors.darker(fg_color,  80)
-        else:
-            label_color = self.colors.darker(fg_color,  -80)
-
+        label_color = self.colors.contrast(fg_color,  80)
 
         self.layout.set_alignment(pango.ALIGN_RIGHT)
         self.layout.set_ellipsize(pango.ELLIPSIZE_END)
@@ -306,10 +295,7 @@ class HorizontalDayChart(graphics.Scene):
 
         # determine bar color
         bg_color = self.get_style().bg[gtk.STATE_NORMAL].to_string()
-        if self.colors.is_light(bg_color):
-            base_color = self.colors.darker(bg_color,  30)
-        else:
-            base_color = self.colors.darker(bg_color,  -30)
+        base_color = self.colors.contrast(bg_color,  30)
 
         for i, label in enumerate(keys):
             g.set_color(label_color)
diff --git a/src/hamster/stats.py b/src/hamster/stats.py
index 3ba64ff..4fe3fd3 100644
--- a/src/hamster/stats.py
+++ b/src/hamster/stats.py
@@ -140,11 +140,7 @@ class Stats(object):
             def on_enter_frame(self, scene, context):
                 # now for the text - we want reduced contrast for relaxed visuals
                 fg_color = self.get_style().fg[gtk.STATE_NORMAL].to_string()
-                if self.colors.is_light(fg_color):
-                    label_color = self.colors.darker(fg_color,  80)
-                else:
-                    label_color = self.colors.darker(fg_color,  -80)
-                self.label.color = label_color
+                self.label.color = self.colors.contrast(fg_color,  80)
 
                 self.label.width = self.width
 
diff --git a/src/hamster/stuff.py b/src/hamster/stuff.py
index be601b9..d8b1cad 100644
--- a/src/hamster/stuff.py
+++ b/src/hamster/stuff.py
@@ -164,33 +164,6 @@ def locale_first_weekday():
 
     return first_weekday
 
-class CategoryCell(gtk.CellRendererText):
-    def __init__(self):
-        gtk.CellRendererText.__init__(self)
-        self.set_property('alignment', pango.ALIGN_RIGHT)
-
-        insensitive_color = gtk.Label().style.fg[gtk.STATE_INSENSITIVE]
-        self.set_property('foreground-gdk', insensitive_color)
-        self.set_property('scale', pango.SCALE_SMALL)
-        self.set_property('yalign', 0.0)
-
-
-insensitive_color = gtk.Label().style.fg[gtk.STATE_INSENSITIVE].to_string()
-def format_activity(name, category, description, pad_description = False):
-    "returns pango markup for activity with category and description"
-    text = name
-    if category and category != _("Unsorted"):
-        text += """ - <span color="%s" size="x-small">%s</span>""" % (insensitive_color, category)
-
-    if description:
-        text+= "\n"
-        if pad_description:
-            text += " " * 23
-
-        text += """<span style="italic" size="small">%s</span>""" % description
-
-    return text
-
 
 def totals(iter, keyfunc, sumfunc):
     """groups items by field described in keyfunc and counts totals using value
@@ -205,8 +178,6 @@ def totals(iter, keyfunc, sumfunc):
     return res
 
 
-
-
 def dateDict(date, prefix = ""):
     """converts date into dictionary, having prefix for all the keys"""
     res = {}
diff --git a/src/hamster/widgets/__init__.py b/src/hamster/widgets/__init__.py
index 76bc507..b3837ca 100644
--- a/src/hamster/widgets/__init__.py
+++ b/src/hamster/widgets/__init__.py
@@ -56,15 +56,16 @@ def add_hint(entry, hint):
             return
 
         self.modify_text(gtk.STATE_NORMAL, gtk.gdk.Color("gray"))
-        hint_font = pango.FontDescription(gtk.Style().font_desc.to_string())
+        hint_font = pango.FontDescription(self.get_style().font_desc.to_string())
         hint_font.set_style(pango.STYLE_ITALIC)
         self.modify_font(hint_font)
 
         self.set_text(self.hint)
 
     def _set_normal(self, widget, event):
-        self.modify_text(gtk.STATE_NORMAL, gtk.Style().fg[gtk.STATE_NORMAL])
-        hint_font = pango.FontDescription(gtk.Style().font_desc.to_string())
+        self.modify_text(gtk.STATE_NORMAL, self.get_style().fg[gtk.STATE_NORMAL])
+        hint_font = pango.FontDescription(self.get_style().font_desc.to_string())
+        hint_font.set_style(pango.STYLE_NORMAL)
         self.modify_font(hint_font)
 
         if self.real_get_text() == self.hint:
diff --git a/src/hamster/widgets/activityentry.py b/src/hamster/widgets/activityentry.py
index 5d5af18..4f9c1f4 100644
--- a/src/hamster/widgets/activityentry.py
+++ b/src/hamster/widgets/activityentry.py
@@ -17,11 +17,11 @@
 # You should have received a copy of the GNU General Public License
 # along with Project Hamster.  If not, see <http://www.gnu.org/licenses/>.
 
-import gtk, gobject
+import gtk, gobject, pango
 import datetime as dt
 
 from ..configuration import runtime
-from .. import stuff
+from .. import stuff, graphics
 from ..stuff import format_duration
 from .. import external
 
@@ -51,21 +51,17 @@ class ActivityEntry(gtk.Entry):
         self.tree.set_headers_visible(False)
         self.tree.set_hover_selection(True)
 
-        bgcolor = gtk.Style().bg[gtk.STATE_NORMAL].to_string()
-        time_cell = gtk.CellRendererPixbuf()
-        time_cell.set_property("icon-name", "appointment-new")
-        time_cell.set_property("cell-background", bgcolor)
+        self.time_icon_cell = gtk.CellRendererPixbuf()
+        self.time_icon_cell.set_property("icon-name", "appointment-new")
 
-        self.time_icon_column = gtk.TreeViewColumn("",
-                                              time_cell)
+        self.time_icon_column = gtk.TreeViewColumn("", self.time_icon_cell)
         self.tree.append_column(self.time_icon_column)
 
-        time_cell = gtk.CellRendererText()
-        time_cell.set_property("scale", 0.8)
-        time_cell.set_property("cell-background", bgcolor)
+        self.time_cell = gtk.CellRendererText()
+        self.time_cell.set_property("scale", 0.8)
 
         self.time_column = gtk.TreeViewColumn("Time",
-                                              time_cell,
+                                              self.time_cell,
                                               text = 3)
         self.tree.append_column(self.time_column)
 
@@ -76,8 +72,13 @@ class ActivityEntry(gtk.Entry):
         self.activity_column.set_expand(True)
         self.tree.append_column(self.activity_column)
 
+        self.category_cell = gtk.CellRendererText()
+        self.category_cell.set_property('alignment', pango.ALIGN_RIGHT)
+        self.category_cell.set_property('scale', pango.SCALE_SMALL)
+        self.category_cell.set_property('yalign', 0.0)
+
         self.category_column = gtk.TreeViewColumn("Category",
-                                                  stuff.CategoryCell(),
+                                                  self.category_cell,
                                                   text=2)
         self.tree.append_column(self.category_column)
 
@@ -147,6 +148,16 @@ class ActivityEntry(gtk.Entry):
         self.category_column.set_visible(self.filter.find("@") == -1)
 
 
+        #set proper background color (we can do that only on a realised widget)
+        bgcolor = self.get_style().bg[gtk.STATE_NORMAL]
+        self.time_icon_cell.set_property("cell-background", bgcolor)
+        self.time_cell.set_property("cell-background", bgcolor)
+
+        text_color = self.get_style().text[gtk.STATE_NORMAL]
+        category_color = graphics.Colors.contrast(text_color,  100)
+        self.category_cell.set_property('foreground-gdk', graphics.Colors.gdk(category_color))
+
+
         #move popup under the widget
         alloc = self.get_allocation()
 
diff --git a/src/hamster/widgets/dayline.py b/src/hamster/widgets/dayline.py
index 7d2dbca..f1e6f25 100644
--- a/src/hamster/widgets/dayline.py
+++ b/src/hamster/widgets/dayline.py
@@ -314,17 +314,22 @@ class DayLine(graphics.Scene):
 
         #time scale
         g.set_color("#000")
+
+        background = self.get_style().bg[gtk.STATE_NORMAL].to_string()
+        text = self.get_style().text[gtk.STATE_NORMAL].to_string()
+
+        tick_color = g.colors.contrast(background, 80)
+
         layout = g.create_layout(size = 8)
         for i in range(self.scope_hours * 60):
             label_time = (self.view_time + dt.timedelta(minutes=i))
 
+            g.set_color(tick_color)
             if label_time.minute == 0:
-                g.set_color((0.8, 0.8, 0.8))
                 g.move_to(round(i / minute_pixel) + 0.5, bottom - 15)
                 g.line_to(round(i / minute_pixel) + 0.5, bottom)
                 g.stroke()
             elif label_time.minute % 15 == 0:
-                g.set_color((0.8, 0.8, 0.8))
                 g.move_to(round(i / minute_pixel) + 0.5, bottom - 5)
                 g.line_to(round(i / minute_pixel) + 0.5, bottom)
                 g.stroke()
@@ -333,20 +338,18 @@ class DayLine(graphics.Scene):
 
             if label_time.minute == 0 and label_time.hour % 4 == 0:
                 if label_time.hour == 0:
-                    g.set_color((0.8, 0.8, 0.8))
                     g.move_to(round(i / minute_pixel) + 0.5, self.plot_area.y)
                     g.line_to(round(i / minute_pixel) + 0.5, bottom)
                     label_minutes = label_time.strftime("%b %d")
                 else:
                     label_minutes = label_time.strftime("%H<small><sup>%M</sup></small>")
 
-                g.set_color((0.4, 0.4, 0.4))
+                g.set_color(text)
                 layout.set_markup(label_minutes)
                 label_w, label_h = layout.get_pixel_size()
 
                 g.move_to(round(i / minute_pixel) + 2, 0)
                 context.show_layout(layout)
-        g.stroke()
 
         #current time
         if self.view_time < dt.datetime.now() < self.view_time + dt.timedelta(hours = self.scope_hours):
diff --git a/src/hamster/widgets/facttree.py b/src/hamster/widgets/facttree.py
index 03377fc..c06187e 100644
--- a/src/hamster/widgets/facttree.py
+++ b/src/hamster/widgets/facttree.py
@@ -24,7 +24,7 @@ import cairo
 import datetime as dt
 
 from .. import stuff, graphics
-from ..stuff import format_duration, format_activity
+from ..stuff import format_duration
 from .tags import Tag
 
 import pango
@@ -349,8 +349,8 @@ class FactCellRenderer(gtk.GenericCellRenderer):
 
         default_font = gtk.Style().font_desc.to_string()
 
-        self.selected_color = gtk.Style().text[gtk.STATE_SELECTED]
-        self.normal_color = gtk.Style().text[gtk.STATE_NORMAL]
+        self.selected_color = None
+        self.normal_color = None
 
         self.col_padding = 10
         self.row_padding = 4
@@ -428,12 +428,20 @@ class FactCellRenderer(gtk.GenericCellRenderer):
         if not bounds:
             return -1
         x, y, cell_width, h = bounds
+
         g = graphics.Graphics(context)
 
+        # set the colors
+        self.selected_color = widget.get_style().text[gtk.STATE_SELECTED]
+        self.normal_color = widget.get_style().text[gtk.STATE_NORMAL]
+
         fact = self.data
 
         current_fact = widget.get_selected_fact()
+
+
         text_color = self.normal_color
+
         selected = False
         # if we are selected, change font color appropriately
         if current_fact and isinstance(current_fact, dt.date) == False \
@@ -477,7 +485,9 @@ class FactCellRenderer(gtk.GenericCellRenderer):
         if fact["category"]:
             self.category_label.text = " - <small>%s</small>" % stuff.escape_pango(fact["category"])
             if not selected:
-                self.category_label.color = widget.get_style().text[gtk.STATE_INSENSITIVE]
+                category_color = graphics.Colors.contrast(text_color,  100)
+
+                self.category_label.color = category_color
             else:
                 self.category_label.color = text_color
             category_width = self.category_label.width
diff --git a/src/hamster/widgets/tags.py b/src/hamster/widgets/tags.py
index c36c36d..321a182 100644
--- a/src/hamster/widgets/tags.py
+++ b/src/hamster/widgets/tags.py
@@ -45,7 +45,6 @@ class TagsEntry(gtk.Entry):
         self.tag_box = TagBox()
         self.tag_box.connect("tag-selected", self.on_tag_selected)
         self.tag_box.connect("tag-unselected", self.on_tag_unselected)
-        self.tag_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65536.0,65536.0,65536.0))
 
 
         viewport.add(self.tag_box)
@@ -123,6 +122,9 @@ class TagsEntry(gtk.Entry):
 
         height = self.tag_box.count_height(w)
 
+
+        self.tag_box.modify_bg(gtk.STATE_NORMAL, self.get_style().base[gtk.STATE_NORMAL])
+
         self.scroll_box.set_size_request(w, height)
         self.popup.resize(w, height)
         self.popup.show_all()
diff --git a/src/hamster/widgets/timechart.py b/src/hamster/widgets/timechart.py
index 3f6374e..ff8ed2a 100644
--- a/src/hamster/widgets/timechart.py
+++ b/src/hamster/widgets/timechart.py
@@ -31,7 +31,7 @@ DAY = dt.timedelta(1)
 WEEK = dt.timedelta(7)
 
 class VerticalBar(graphics.Sprite):
-    def __init__(self, key, format, value, normalized, label_color):
+    def __init__(self, key, format, value, normalized):
         graphics.Sprite.__init__(self)
 
         self.key, self.format = key, format,
@@ -42,7 +42,7 @@ class VerticalBar(graphics.Sprite):
         self.width = 20
         self.fill = None
 
-        self.key_label = graphics.Label(key.strftime(format), x=2, y=0, size=8, color=label_color)
+        self.key_label = graphics.Label(key.strftime(format), x=2, y=0, size=8, color="#000")
         self.show_label = True
 
         self.add_child(self.key_label)
@@ -168,21 +168,14 @@ class TimeChart(graphics.Scene):
 
         # figure out colors
         bg_color = self.get_style().bg[gtk.STATE_NORMAL].to_string()
-        if g.colors.is_light(bg_color):
-            self.bar_color = g.colors.darker(bg_color,  30)
-            self.tick_color = g.colors.darker(bg_color,  50)
-        else:
-            self.bar_color = g.colors.darker(bg_color,  -30)
-            self.tick_color = g.colors.darker(bg_color,  -50)
+        self.bar_color = g.colors.contrast(bg_color,  30)
+        self.tick_color = g.colors.contrast(bg_color,  50)
 
 
 
         # now for the text - we want reduced contrast for relaxed visuals
         fg_color = self.get_style().fg[gtk.STATE_NORMAL].to_string()
-        if g.colors.is_light(fg_color):
-            label_color = g.colors.darker(fg_color,  70)
-        else:
-            label_color = g.colors.darker(fg_color,  -70)
+        label_color = g.colors.contrast(fg_color,  70)
 
 
         g.set_line_style(width=1)
@@ -218,6 +211,8 @@ class TimeChart(graphics.Scene):
         remaining_ticks = len(ticks)
 
 
+        self.text_color = self.get_style().text[gtk.STATE_NORMAL].to_string()
+
         for i, bar in enumerate(self.bars):
             if bar.key in ticks:
                 x += 2
@@ -226,6 +221,7 @@ class TimeChart(graphics.Scene):
             bar.x = x
             bar.width = bar_width - 1
             bar.height = self.height
+            bar.key_label.color = self.text_color
 
             if not bar.fill:
                 bar.fill = self.bar_color
@@ -365,6 +361,6 @@ class TimeChart(graphics.Scene):
 
         self.bars = []
         for key, value, normalized in zip(fractions, hours, normalized_hours):
-            bar = VerticalBar(key, step_format, value, normalized, "#000")
+            bar = VerticalBar(key, step_format, value, normalized)
             self.add_child(bar)
             self.bars.append(bar)



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