---
 src/jarabe/frame/clock.py |  108 +++++++++++++++++++++++++++++++++++++++++++++
 src/jarabe/frame/frame.py |    7 +++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 src/jarabe/frame/clock.py

diff --git a/src/jarabe/frame/clock.py b/src/jarabe/frame/clock.py
new file mode 100644
index 0000000..ea8dbb2
--- /dev/null
+++ b/src/jarabe/frame/clock.py
@@ -0,0 +1,108 @@
+# Copyright (C) 2008 Martin Dengler
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+from gettext import gettext as _
+import gconf
+
+import gtk
+import gtk.gdk
+import pango
+import pangocairo
+import time
+
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.xocolor import XoColor
+
+
+CLOCK_TEXT_FONT = "Bitstream Vera Sans 36"
+
+
+class TextIcon(gtk.Image):
+    def __init__(self, *args, **kwargs):
+        gtk.Image.__init__(self, *args, **kwargs)
+        client = gconf.client_get_default()        
+        mycolor = XoColor(client.get_string('/desktop/sugar/user/color'))
+        self._fill_rgba = style.Color(mycolor.fill).get_rgba()
+        self._stroke_rgba = style.Color(mycolor.stroke).get_rgba()
+
+    def my_expose_event(self, widget_, event):
+        x, y, w, h = event.area
+        cr = self.window.cairo_create()
+        redraw_region = gtk.gdk.region_rectangle(self.allocation)
+        exposed_region = gtk.gdk.region_rectangle(event.area)
+        redraw_region.intersect(exposed_region)
+        cr.region(redraw_region)
+        cr.clip()
+        x, y, w_, h_ = self.allocation
+        cr.translate(x, y)
+        self.texticon_draw(cr)
+
+    def write(self, cr, text, x=0, y=0, font=None):
+        cr.save()
+        pcr = pangocairo.CairoContext(cr)
+        layout = pcr.create_layout()
+        if font is None:
+            font = CLOCK_TEXT_FONT
+        layout.set_font_description(pango.FontDescription(font))
+        layout.set_markup(text)
+        if x != 0 or y != 0:
+            cr.move_to(x, y)
+        pcr.layout_path(layout)
+        cr.set_source_rgba(*self._stroke_rgba)
+        cr.set_line_width(0.5)
+        cr.stroke_preserve()
+        cr.set_source_rgba(*self._fill_rgba)
+        cr.fill()
+        cr.restore()
+        self.set_size_request(*layout.get_pixel_size())
+
+    def texticon_draw(self, cr):
+        """
+        draw the widget on the provided cairo surface
+
+        Should be overridden by subclasses; example:
+
+        def texticon_draw(self, cr):
+            self.write(cr, time.strftime(_("%m/%d %H:%M"), time.localtime()))
+        """
+        raise Exception("TextIcon.texticon_draw(): subclasses must"
+                        " override this method")
+
+
+class DigitalClock(TextIcon):
+    def texticon_draw(self, cr):
+        self.write(cr, time.strftime(_("%m/%d %H:%M"), time.localtime()))
+
+
+class DigitalClockTrayItem(ToolButton):
+
+    FRAME_POSITION_RELATIVE = 50 # all the way on the right
+
+    def __init__(self):
+        ToolButton.__init__(self)
+        self._icon = DigitalClock()
+        self.set_icon_widget(self._icon)
+
+        # TODO: consider what happens when composite manager is involved
+        self.connect("expose-event", self._icon.my_expose_event)
+
+        self.props.sensitive = False
+        self._icon.show()
+
+
+def setup(tray):
+    tray.add_device(DigitalClockTrayItem())
diff --git a/src/jarabe/frame/frame.py b/src/jarabe/frame/frame.py
index 0bb8d92..79b508b 100644
--- a/src/jarabe/frame/frame.py
+++ b/src/jarabe/frame/frame.py
@@ -190,6 +190,13 @@ class Frame(object):
                 hippo.PACK_EXPAND)
         activities_tray.show()
 
+        import sys; sys.path.insert(0, ".")
+        from clock import DigitalClockTrayItem as clock
+        clockwidget = clock()
+        panel.append(hippo.CanvasWidget(widget=clockwidget), hippo.PACK_END)
+        clockwidget.show()
+        del sys.path[0]
+
         return panel
 
     def _create_bottom_panel(self):
-- 
1.6.0.6

_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to