Precompute color fade values; longer redraw interval
cycles be precious, don't waste them
This commit is contained in:
parent
ff2776ef25
commit
8e614af2de
@ -45,17 +45,18 @@ def html_to_rgb(html_color):
|
|||||||
return (r, g, b)
|
return (r, g, b)
|
||||||
|
|
||||||
class ActivityIcon(CanvasIcon):
|
class ActivityIcon(CanvasIcon):
|
||||||
_LEVEL_MAX = 1.6
|
_INTERVAL = 150
|
||||||
_LEVEL_MIN = 0.0
|
|
||||||
_INTERVAL = 100
|
|
||||||
|
|
||||||
def __init__(self, activity):
|
def __init__(self, activity):
|
||||||
icon_name = activity.get_icon_name()
|
icon_name = activity.get_icon_name()
|
||||||
self._orig_color = profile.get_color()
|
self._orig_color = profile.get_color()
|
||||||
|
|
||||||
|
self._icon_colors = self._compute_icon_colors()
|
||||||
|
|
||||||
self._direction = 0
|
self._direction = 0
|
||||||
self._level = self._LEVEL_MAX
|
self._level_max = len(self._icon_colors) - 1
|
||||||
color = self._get_icon_color_for_level()
|
self._level = self._level_max
|
||||||
|
color = self._icon_colors[self._level]
|
||||||
|
|
||||||
CanvasIcon.__init__(self, icon_name=icon_name, color=color)
|
CanvasIcon.__init__(self, icon_name=icon_name, color=color)
|
||||||
style.apply_stylesheet(self, 'ring.ActivityIcon')
|
style.apply_stylesheet(self, 'ring.ActivityIcon')
|
||||||
@ -68,32 +69,42 @@ class ActivityIcon(CanvasIcon):
|
|||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
logging.debug("removing source %s" % self._pulse_id)
|
|
||||||
if self._pulse_id > 0:
|
if self._pulse_id > 0:
|
||||||
gobject.source_remove(self._pulse_id)
|
gobject.source_remove(self._pulse_id)
|
||||||
self._pulse_id = 0
|
self._pulse_id = 0
|
||||||
|
|
||||||
def _get_icon_color_for_level(self):
|
def _compute_icon_colors(self):
|
||||||
factor = math.sin(self._level)
|
_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()))
|
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))
|
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()))
|
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))
|
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):
|
def _pulse_cb(self):
|
||||||
if self._direction == 1:
|
if self._direction == 1:
|
||||||
self._level += 0.1
|
self._level += 1
|
||||||
if self._level >= self._LEVEL_MAX:
|
if self._level > self._level_max:
|
||||||
self._direction = 0
|
self._direction = 0
|
||||||
self._level = self._LEVEL_MAX
|
self._level = self._level_max
|
||||||
elif self._direction == 0:
|
elif self._direction == 0:
|
||||||
self._level -= 0.1
|
self._level -= 1
|
||||||
if self._level <= self._LEVEL_MIN:
|
if self._level <= 0:
|
||||||
self._direction = 1
|
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)
|
self.emit_paint_needed(0, 0, -1, -1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user