summaryrefslogtreecommitdiff
path: root/timer-applet/src/timerapplet/ui/PieMeter.py
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2012-06-12 17:49:56 +0200
committerStefano Karapetsas <[email protected]>2012-06-12 17:49:56 +0200
commit4bbd16182dab69da9ca7ad13309962af40529469 (patch)
treec77202017ea3739f137a86f817bdb2ecef381f80 /timer-applet/src/timerapplet/ui/PieMeter.py
parentc9b9454068f090a7132c6bea6ac07c91843ffb6e (diff)
downloadmate-applets-4bbd16182dab69da9ca7ad13309962af40529469.tar.bz2
mate-applets-4bbd16182dab69da9ca7ad13309962af40529469.tar.xz
add timer-applet
Diffstat (limited to 'timer-applet/src/timerapplet/ui/PieMeter.py')
-rw-r--r--timer-applet/src/timerapplet/ui/PieMeter.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/timer-applet/src/timerapplet/ui/PieMeter.py b/timer-applet/src/timerapplet/ui/PieMeter.py
new file mode 100644
index 00000000..f97d02d7
--- /dev/null
+++ b/timer-applet/src/timerapplet/ui/PieMeter.py
@@ -0,0 +1,77 @@
+# Copyright (C) 2008 Jimmy Do <[email protected]>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import math
+import gobject
+import gtk
+
+class PieMeter(gtk.Image):
+ _DEFAULT_SIZE = 24
+
+ def __init__(self):
+ gtk.Image.__init__(self)
+ self._progress = 0.0
+ self._fill_color = (0.0, 1.0, 0.0)
+
+ def set_progress(self, progress):
+ assert progress >= 0.0
+ assert progress <= 1.0
+ self._progress = progress
+ if self.window is not None:
+ self.window.invalidate_rect(self.allocation, True)
+
+ def set_fill_color(self, red, green, blue):
+ assert 0.0 <= red <= 1.0
+ assert 0.0 <= green <= 1.0
+ assert 0.0 <= blue <= 1.0
+ self._fill_color = (red, green, blue)
+
+ if self.window is not None:
+ self.window.invalidate_rect(self.allocation, True)
+
+ def do_size_request(self, requisition):
+ requisition.width = PieMeter._DEFAULT_SIZE
+ requisition.height = PieMeter._DEFAULT_SIZE
+
+ def do_expose_event(self, event):
+ context = event.window.cairo_create()
+
+ rect = self.allocation
+ x = rect.x + (rect.width / 2)
+ y = rect.y + (rect.height / 2)
+ radius = (min(rect.width, rect.height) / 2)
+
+ # Draw background circle
+ context.arc(x, y, radius, 0, 2 * math.pi)
+ context.set_source_rgba(0.8, 0.8, 0.8)
+ context.fill()
+
+ # Draw pie
+ context.arc(x, y, radius, (-0.5 * math.pi) + self._progress * 2 * math.pi, 1.5 * math.pi)
+ context.line_to(x, y)
+ context.close_path()
+ (red, green, blue) = self._fill_color
+ context.set_source_rgb(red, green, blue)
+ context.fill()
+
+ # Draw circle outline
+ context.arc(x, y, radius, 0, 2 * math.pi)
+ context.set_source_rgba(1, 1, 1)
+ context.set_line_width(1.0)
+ context.stroke()
+
+gobject.type_register(PieMeter)
+