[gnome-clocks] Use css to draw the alarm



commit 4230359ac258c86fe5f3be78a0fbf6a2330d7490
Author: Paolo Borelli <pborelli gnome org>
Date:   Wed Dec 5 15:07:55 2012 +0100

    Use css to draw the alarm
    
    We do not want day/night images there

 data/gtk-style.css     |   42 ++++++++++++++++++++++++++++++++++++++----
 gnomeclocks/alarm.py   |   17 ++---------------
 gnomeclocks/widgets.py |   12 +++++++++++-
 3 files changed, 51 insertions(+), 20 deletions(-)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index 1762926..d88de1f 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -15,10 +15,16 @@
 }
 
 .clocks-digital-renderer {
+    border-radius: 12px;
+}
+
+.clocks-digital-renderer.inner {
     border-radius: 9px;
 }
 
-.clocks-digital-renderer.light {
+/* world */
+
+.clocks-digital-renderer.light.inner {
     background-color: transparent;
     background-image: linear-gradient(to bottom,
                                       rgba(255, 255, 255, 0.9),
@@ -27,7 +33,7 @@
     color: black;
 }
 
-.clocks-digital-renderer.light:prelight {
+.clocks-digital-renderer.light.inner:prelight {
     background-color: transparent;
     background-image: linear-gradient(to bottom,
                                       rgb(255, 255, 255),
@@ -35,7 +41,35 @@
                                       );
 }
 
-.clocks-digital-renderer.dark {
+.clocks-digital-renderer.dark.inner {
+    background-color: transparent;
+    background-image: linear-gradient(to bottom,
+                                      rgba(255, 255, 255, 0.3),
+                                      rgba(255, 255, 255, 0.1)
+                                      );
+    color: white;
+}
+
+.clocks-digital-renderer.dark.inner:prelight {
+    background-color: transparent;
+    background-image: linear-gradient(to bottom,
+                                      rgba(255, 255, 255, 0.4),
+                                      rgba(255, 255, 255, 0.15)
+                                      );
+}
+
+/* alarms */
+
+.clocks-digital-renderer.active {
+    background-color: transparent;
+    background-image: linear-gradient(to bottom,
+                                      rgb(223, 0, 0),
+                                      rgb(164, 0, 0)
+                                      );
+    color: white;
+}
+
+.clocks-digital-renderer.active.inner {
     background-color: transparent;
     background-image: linear-gradient(to bottom,
                                       rgba(255, 255, 255, 0.3),
@@ -44,7 +78,7 @@
     color: white;
 }
 
-.clocks-digital-renderer.dark:prelight {
+.clocks-digital-renderer.active.inner:prelight {
     background-color: transparent;
     background-image: linear-gradient(to bottom,
                                       rgba(255, 255, 255, 0.4),
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index f5ced56..c7192cd 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -83,7 +83,6 @@ class AlarmItem:
 
         self.alarm_time_string = TimeString.format_time(self.alarm_time)
         self.alarm_repeat_string = self._get_alarm_repeat_string()
-        self.is_light = self._get_is_light()
         self.alert = Alert("alarm-clock-elapsed", name)
 
     def _update_expiration_time(self):
@@ -122,9 +121,6 @@ class AlarmItem:
                     days.append(LocalizedWeekdays.get_abbr(day_num))
             return ", ".join(days)
 
-    def _get_is_light(self):
-        return 7 <= self.hour <= 19
-
     def snooze(self):
         self.is_snoozing = True
         self.alert.stop()
@@ -390,11 +386,6 @@ class Alarm(Clock):
         self.notebook.set_show_border(False)
         self.add(self.notebook)
 
-        f = os.path.join(Dirs.get_image_dir(), "cities", "day.png")
-        self.daypixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(f, 160, 160)
-        f = os.path.join(Dirs.get_image_dir(), "cities", "night.png")
-        self.nightpixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(f, 160, 160)
-
         self.liststore = Gtk.ListStore(bool, str, object)
         self.iconview = SelectableIconView(self.liststore, 0, 1, self._thumb_data_func)
         self.iconview.connect("item-activated", self._on_item_activated)
@@ -419,12 +410,8 @@ class Alarm(Clock):
         alarm = store.get_value(i, 2)
         cell.text = alarm.alarm_time_string
         cell.subtext = alarm.alarm_repeat_string
-        if alarm.is_light:
-            cell.props.pixbuf = self.daypixbuf
-            cell.css_class = "light"
-        else:
-            cell.props.pixbuf = self.nightpixbuf
-            cell.css_class = "dark"
+        # FIXME: use a different class when we will have inactive alarms
+        cell.css_class = "active"
 
     def set_mode(self, mode):
         self.mode = mode
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index 7174667..f782685 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -83,11 +83,18 @@ class DigitalClockRenderer(Gtk.CellRendererPixbuf):
         cr.clip()
         cr.translate(cell_area.x, cell_area.y)
 
+        # draw background
+        Gtk.render_frame(context, cr, 0, 0, cell_area.width, cell_area.height)
+        Gtk.render_background(context, cr, 0, 0, cell_area.width, cell_area.height)
+
         # for now the space around the digital clock is hardcoded and
         # relative to the image width (not the width of the cell which
         # may be larger in case of long city names).
         # We need to know the width to create the pango layouts
-        pixbuf_margin = (cell_area.width - self.props.pixbuf.get_width()) // 2
+        if self.props.pixbuf:
+            pixbuf_margin = (cell_area.width - self.props.pixbuf.get_width()) // 2
+        else:
+            pixbuf_margin = 0
         margin = 12 + pixbuf_margin
         padding = 12
         w = cell_area.width - 2 * margin
@@ -120,6 +127,8 @@ class DigitalClockRenderer(Gtk.CellRendererPixbuf):
         x = margin
         y = (cell_area.height - h) / 2
 
+        context.add_class("inner")
+
         # draw inner rectangle background
         Gtk.render_frame(context, cr, x, y, w, h)
         Gtk.render_background(context, cr, x, y, w, h)
@@ -175,6 +184,7 @@ class SelectableIconView(Gtk.IconView):
 
         self.icon_renderer = DigitalClockRenderer()
         self.icon_renderer.set_alignment(0.5, 0.5)
+        self.icon_renderer.set_fixed_size(160, 160)
         self.pack_start(self.icon_renderer, False)
         self.add_attribute(self.icon_renderer, "active", selection_col)
         self.set_cell_data_func(self.icon_renderer, thumb_data_func, None)



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