Change the feedback for connected/connecting/disconnected access point,

using two different types of pulsing.
This commit is contained in:
Marco Pesenti Gritti 2007-03-29 17:25:47 +02:00
parent d0fdf59486
commit f59fab783f
4 changed files with 45 additions and 37 deletions

View File

@ -19,13 +19,13 @@ from sugar.graphics import canvasicon
from sugar.graphics import color from sugar.graphics import color
from sugar.graphics import units from sugar.graphics import units
from model.devices.network import wireless from model.devices.network import wireless
from view.pulsingicon import PulsingIcon from sugar.graphics.canvasicon import CanvasIcon
_ICON_NAME = 'device-network-wireless' _ICON_NAME = 'device-network-wireless'
class DeviceView(PulsingIcon): class DeviceView(CanvasIcon):
def __init__(self, model): def __init__(self, model):
PulsingIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE) CanvasIcon.__init__(self, scale=units.MEDIUM_ICON_SCALE)
self._model = model self._model = model
model.connect('notify::name', self._name_changed_cb) model.connect('notify::name', self._name_changed_cb)

View File

@ -55,15 +55,8 @@ class AccessPointView(PulsingIcon):
sh.update(data) sh.update(data)
h = hash(sh.digest()) h = hash(sh.digest())
idx = h % len(xocolor._colors) idx = h % len(xocolor._colors)
self._inactive_stroke_color = xocolor._colors[idx][0] self._device_stroke = xocolor._colors[idx][0]
self._inactive_fill_color = xocolor._colors[idx][1] self._device_fill = xocolor._colors[idx][1]
self.props.colors = [
[ None, None ],
[ color.HTMLColor(self._inactive_stroke_color),
color.HTMLColor(self._inactive_fill_color)
]
]
self._update_icon() self._update_icon()
self._update_name() self._update_name()
@ -96,15 +89,27 @@ class AccessPointView(PulsingIcon):
def _update_state(self): def _update_state(self):
if self._model.props.state == accesspointmodel.STATE_CONNECTING: if self._model.props.state == accesspointmodel.STATE_CONNECTING:
self.props.pulsing = True self.props.pulse_time = 0.75
self.props.colors = [
[ color.HTMLColor(self._device_stroke),
color.HTMLColor(self._device_fill) ],
[ color.HTMLColor(self._device_stroke),
color.HTMLColor('#e2e2e2') ]
]
elif self._model.props.state == accesspointmodel.STATE_CONNECTED: elif self._model.props.state == accesspointmodel.STATE_CONNECTED:
self.props.pulsing = False self.props.pulse_time = 1.5
self.props.fill_color = None self.props.colors = [
self.props.stroke_color = None [ color.HTMLColor(self._device_stroke),
color.HTMLColor(self._device_fill) ],
[ color.HTMLColor('#ffffff'),
color.HTMLColor(self._device_fill) ]
]
elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED: elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED:
self.props.pulsing = False self.props.pulse_time = 0.0
self.props.fill_color = color.HTMLColor(self._inactive_fill_color) self.props.colors = [
self.props.stroke_color = color.HTMLColor(self._inactive_stroke_color) [ color.HTMLColor(self._device_stroke),
color.HTMLColor(self._device_fill) ]
]
class MeshDeviceView(CanvasIcon): class MeshDeviceView(CanvasIcon):
def __init__(self, nm_device): def __init__(self, nm_device):

View File

@ -20,14 +20,15 @@ from sugar.graphics.canvasicon import CanvasIcon
class PulsingIcon(CanvasIcon): class PulsingIcon(CanvasIcon):
__gproperties__ = { __gproperties__ = {
'colors' : (object, None, None, 'colors' : (object, None, None,
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
'pulsing' : (bool, None, None, False, 'pulse-time' : (float, None, None,
gobject.PARAM_READWRITE) 0.0, 500.0, 0.0,
gobject.PARAM_READWRITE),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._pulsing = False self._puls_time = 0.0
self._colors = None self._colors = None
self._pulse_sid = 0 self._pulse_sid = 0
self._pos = 0 self._pos = 0
@ -37,31 +38,32 @@ class PulsingIcon(CanvasIcon):
def do_set_property(self, pspec, value): def do_set_property(self, pspec, value):
CanvasIcon.do_set_property(self, pspec, value) CanvasIcon.do_set_property(self, pspec, value)
if pspec.name == 'pulsing': if pspec.name == 'pulse-time':
self._pulsing = value self._pulse_time = value
if self._pulsing: self._stop()
if self._pulse_time > 0.0:
self._start() self._start()
else:
self._stop()
elif pspec.name == 'colors': elif pspec.name == 'colors':
self._colors = value self._colors = value
self._pos = 0 self._pos = 0
self._update_colors()
def do_get_property(self, pspec): def do_get_property(self, pspec):
CanvasIcon.do_get_property(self, pspec) CanvasIcon.do_get_property(self, pspec)
if pspec.name == 'pulsing': if pspec.name == 'pulse-time':
return self._pulsing return self._pulse_time
elif pspec.name == 'colors': elif pspec.name == 'colors':
return self._colors return self._colors
def _pulse_timeout(self): def _update_colors(self):
if not self._colors:
return
self.props.stroke_color = self._colors[self._pos][0] self.props.stroke_color = self._colors[self._pos][0]
self.props.fill_color = self._colors[self._pos][1] self.props.fill_color = self._colors[self._pos][1]
def _pulse_timeout(self):
if self._colors:
self._update_colors()
self._pos += 1 self._pos += 1
if self._pos == len(self._colors): if self._pos == len(self._colors):
self._pos = 0 self._pos = 0
@ -70,7 +72,8 @@ class PulsingIcon(CanvasIcon):
def _start(self): def _start(self):
if self._pulse_sid == 0: if self._pulse_sid == 0:
self._pulse_sid = gobject.timeout_add(1000, self._pulse_timeout) self._pulse_sid = gobject.timeout_add(
self._pulse_time * 1000, self._pulse_timeout)
def _stop(self): def _stop(self):
if self._pulse_sid: if self._pulse_sid:

View File

@ -19,7 +19,7 @@ import dbus, dbus.glib, gobject
import Buddy, Service, Activity import Buddy, Service, Activity
_ENABLED = False _ENABLED = True
class ObjectCache(object): class ObjectCache(object):
def __init__(self): def __init__(self):