Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2007-01-14 19:22:12 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2007-01-14 19:22:12 (GMT)
commit8e614af2dede35adba39c904cc956d0cedfd1e30 (patch)
tree89249ce7c89f5f66504ec58b07a3581a319aad24
parentff2776ef252518778a36ea1cdf90317c0723e0fe (diff)
Precompute color fade values; longer redraw interval
cycles be precious, don't waste them
-rw-r--r--shell/view/home/activitiesdonut.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/shell/view/home/activitiesdonut.py b/shell/view/home/activitiesdonut.py
index 4796a37..82f283b 100644
--- a/shell/view/home/activitiesdonut.py
+++ b/shell/view/home/activitiesdonut.py
@@ -45,17 +45,18 @@ def html_to_rgb(html_color):
return (r, g, b)
class ActivityIcon(CanvasIcon):
- _LEVEL_MAX = 1.6
- _LEVEL_MIN = 0.0
- _INTERVAL = 100
+ _INTERVAL = 150
def __init__(self, activity):
icon_name = activity.get_icon_name()
self._orig_color = profile.get_color()
+
+ self._icon_colors = self._compute_icon_colors()
self._direction = 0
- self._level = self._LEVEL_MAX
- color = self._get_icon_color_for_level()
+ self._level_max = len(self._icon_colors) - 1
+ self._level = self._level_max
+ color = self._icon_colors[self._level]
CanvasIcon.__init__(self, icon_name=icon_name, color=color)
style.apply_stylesheet(self, 'ring.ActivityIcon')
@@ -68,32 +69,42 @@ class ActivityIcon(CanvasIcon):
self.cleanup()
def cleanup(self):
- logging.debug("removing source %s" % self._pulse_id)
if self._pulse_id > 0:
gobject.source_remove(self._pulse_id)
self._pulse_id = 0
- def _get_icon_color_for_level(self):
- factor = math.sin(self._level)
+ def _compute_icon_colors(self):
+ _LEVEL_MAX = 1.6
+ _LEVEL_STEP = 0.16
+ _LEVEL_MIN = 0.0
+ icon_colors = {}
+ level = _LEVEL_MIN
+ for i in range(0, int(_LEVEL_MAX / _LEVEL_STEP)):
+ icon_colors[i] = self._get_icon_color_for_level(level)
+ level += _LEVEL_STEP
+ return icon_colors
+
+ def _get_icon_color_for_level(self, level):
+ factor = math.sin(level)
h, s, v = colorsys.rgb_to_hsv(*html_to_rgb(self._orig_color.get_fill_color()))
new_fill = rgb_to_html(*colorsys.hsv_to_rgb(h, s * factor, v))
h, s, v = colorsys.rgb_to_hsv(*html_to_rgb(self._orig_color.get_stroke_color()))
new_stroke = rgb_to_html(*colorsys.hsv_to_rgb(h, s * factor, v))
- return iconcolor.IconColor("%s,%s" % (new_fill, new_stroke))
+ return iconcolor.IconColor("%s,%s" % (new_stroke, new_fill))
def _pulse_cb(self):
if self._direction == 1:
- self._level += 0.1
- if self._level >= self._LEVEL_MAX:
+ self._level += 1
+ if self._level > self._level_max:
self._direction = 0
- self._level = self._LEVEL_MAX
+ self._level = self._level_max
elif self._direction == 0:
- self._level -= 0.1
- if self._level <= self._LEVEL_MIN:
+ self._level -= 1
+ if self._level <= 0:
self._direction = 1
- self._level = self._LEVEL_MIN
+ self._level = 0
- self.props.color = self._get_icon_color_for_level()
+ self.props.color = self._icon_colors[self._level]
self.emit_paint_needed(0, 0, -1, -1)
return True