2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2007-02-28 16:19:01 +01:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
import gobject
|
|
|
|
|
2007-08-25 13:15:28 +02:00
|
|
|
from sugar.graphics.icon import CanvasIcon
|
2007-02-28 16:19:01 +01:00
|
|
|
|
|
|
|
class PulsingIcon(CanvasIcon):
|
|
|
|
__gproperties__ = {
|
2007-03-30 01:08:44 +02:00
|
|
|
'paused' : (bool, None, None, False,
|
|
|
|
gobject.PARAM_READWRITE),
|
2007-03-29 17:25:47 +02:00
|
|
|
'colors' : (object, None, None,
|
|
|
|
gobject.PARAM_READWRITE),
|
|
|
|
'pulse-time' : (float, None, None,
|
|
|
|
0.0, 500.0, 0.0,
|
|
|
|
gobject.PARAM_READWRITE),
|
2007-02-28 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
2007-03-30 01:08:44 +02:00
|
|
|
self._paused = False
|
2007-03-29 20:41:41 +02:00
|
|
|
self._pulse_time = 0.0
|
2007-02-28 16:19:01 +01:00
|
|
|
self._colors = None
|
|
|
|
self._pulse_sid = 0
|
|
|
|
self._pos = 0
|
|
|
|
|
|
|
|
CanvasIcon.__init__(self, **kwargs)
|
|
|
|
|
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
CanvasIcon.do_set_property(self, pspec, value)
|
|
|
|
|
2007-03-29 17:25:47 +02:00
|
|
|
if pspec.name == 'pulse-time':
|
|
|
|
self._pulse_time = value
|
|
|
|
self._stop()
|
2007-03-30 01:08:44 +02:00
|
|
|
if not self._paused and self._pulse_time > 0.0:
|
2007-02-28 16:19:01 +01:00
|
|
|
self._start()
|
|
|
|
elif pspec.name == 'colors':
|
|
|
|
self._colors = value
|
|
|
|
self._pos = 0
|
2007-03-29 17:25:47 +02:00
|
|
|
self._update_colors()
|
2007-03-30 01:08:44 +02:00
|
|
|
elif pspec.name == 'paused':
|
|
|
|
self._paused = value
|
|
|
|
if not self._paused and self._pulse_time > 0.0:
|
|
|
|
self._start()
|
|
|
|
else:
|
|
|
|
self._stop()
|
2007-02-28 16:19:01 +01:00
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
2007-03-26 16:38:19 +02:00
|
|
|
CanvasIcon.do_get_property(self, pspec)
|
2007-02-28 16:19:01 +01:00
|
|
|
|
2007-03-29 17:25:47 +02:00
|
|
|
if pspec.name == 'pulse-time':
|
|
|
|
return self._pulse_time
|
2007-02-28 16:19:01 +01:00
|
|
|
elif pspec.name == 'colors':
|
|
|
|
return self._colors
|
|
|
|
|
2007-03-29 17:25:47 +02:00
|
|
|
def _update_colors(self):
|
2007-02-28 16:19:01 +01:00
|
|
|
self.props.stroke_color = self._colors[self._pos][0]
|
|
|
|
self.props.fill_color = self._colors[self._pos][1]
|
|
|
|
|
2007-03-29 17:25:47 +02:00
|
|
|
def _pulse_timeout(self):
|
|
|
|
if self._colors:
|
|
|
|
self._update_colors()
|
|
|
|
|
2007-02-28 16:19:01 +01:00
|
|
|
self._pos += 1
|
|
|
|
if self._pos == len(self._colors):
|
|
|
|
self._pos = 0
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _start(self):
|
|
|
|
if self._pulse_sid == 0:
|
2007-03-29 17:25:47 +02:00
|
|
|
self._pulse_sid = gobject.timeout_add(
|
2007-03-29 17:48:35 +02:00
|
|
|
int(self._pulse_time * 1000), self._pulse_timeout)
|
2007-02-28 16:19:01 +01:00
|
|
|
|
|
|
|
def _stop(self):
|
|
|
|
if self._pulse_sid:
|
|
|
|
gobject.source_remove(self._pulse_sid)
|
|
|
|
self._pulse_sid = 0
|