Make the icon pulse when connecting
This commit is contained in:
parent
b364612615
commit
32ac23ce27
@ -1,11 +1,11 @@
|
||||
from view.devices import deviceview
|
||||
from sugar.graphics import canvasicon
|
||||
|
||||
_ICON_NAME = 'device-battery'
|
||||
|
||||
class DeviceView(deviceview.DeviceView):
|
||||
class DeviceView(canvasicon.CanvasIcon):
|
||||
def __init__(self, model):
|
||||
deviceview.DeviceView.__init__(self, model)
|
||||
canvasicon.CanvasIcon.__init__(self)
|
||||
self._model = model
|
||||
|
||||
icon_name = canvasicon.get_icon_state(_ICON_NAME, 60)
|
||||
self.props.icon_name = icon_name
|
||||
|
@ -1,10 +1,5 @@
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
|
||||
class DeviceView(CanvasIcon):
|
||||
def __init__(self, model):
|
||||
CanvasIcon.__init__(self)
|
||||
self.model = model
|
||||
|
||||
def create(model):
|
||||
name = 'view.devices.' + model.get_type()
|
||||
|
||||
|
@ -17,14 +17,14 @@
|
||||
|
||||
from sugar.graphics import canvasicon
|
||||
from sugar.graphics import color
|
||||
from view.devices import deviceview
|
||||
from model.devices import wirelessnetwork
|
||||
from view.pulsingicon import PulsingIcon
|
||||
|
||||
_ICON_NAME = 'device-network-wireless'
|
||||
|
||||
class DeviceView(deviceview.DeviceView):
|
||||
class DeviceView(PulsingIcon):
|
||||
def __init__(self, model):
|
||||
deviceview.DeviceView.__init__(self, model)
|
||||
PulsingIcon.__init__(self)
|
||||
self._model = model
|
||||
|
||||
model.connect('notify::name', self._name_changed_cb)
|
||||
|
@ -23,16 +23,17 @@ from sugar.graphics.spreadbox import SpreadBox
|
||||
from sugar.graphics.snowflakebox import SnowflakeBox
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics import color
|
||||
from sugar.graphics import canvasicon
|
||||
from model import accesspointmodel
|
||||
from hardware import hardwaremanager
|
||||
from view.BuddyIcon import BuddyIcon
|
||||
from sugar.graphics import canvasicon
|
||||
from view.pulsingicon import PulsingIcon
|
||||
|
||||
_ICON_NAME = 'device-network-wireless'
|
||||
|
||||
class AccessPointView(CanvasIcon):
|
||||
class AccessPointView(PulsingIcon):
|
||||
def __init__(self, model):
|
||||
CanvasIcon.__init__(self)
|
||||
PulsingIcon.__init__(self)
|
||||
self._model = model
|
||||
|
||||
self.connect('activated', self._activate_cb)
|
||||
@ -41,6 +42,11 @@ class AccessPointView(CanvasIcon):
|
||||
model.connect('notify::name', self._name_changed_cb)
|
||||
model.connect('notify::state', self._state_changed_cb)
|
||||
|
||||
self.props.colors = [
|
||||
[ None, None ],
|
||||
[ color.ICON_FILL_INACTIVE, color.ICON_STROKE_INACTIVE ]
|
||||
]
|
||||
|
||||
self._update_icon()
|
||||
self._update_name()
|
||||
self._update_state()
|
||||
@ -71,14 +77,14 @@ class AccessPointView(CanvasIcon):
|
||||
self.props.icon_name = icon_name
|
||||
|
||||
def _update_state(self):
|
||||
# FIXME Change icon colors once we have real icons
|
||||
if self._model.props.state == accesspointmodel.STATE_CONNECTING:
|
||||
self.props.fill_color = color.ICON_FILL_INACTIVE
|
||||
self.props.stroke_color = color.ICON_STROKE_INACTIVE
|
||||
self.props.pulsing = True
|
||||
elif self._model.props.state == accesspointmodel.STATE_CONNECTED:
|
||||
self.props.pulsing = False
|
||||
self.props.fill_color = None
|
||||
self.props.stroke_color = None
|
||||
elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED:
|
||||
self.props.pulsing = False
|
||||
self.props.fill_color = color.ICON_FILL_INACTIVE
|
||||
self.props.stroke_color = color.ICON_STROKE_INACTIVE
|
||||
|
||||
|
78
shell/view/pulsingicon.py
Normal file
78
shell/view/pulsingicon.py
Normal file
@ -0,0 +1,78 @@
|
||||
# Copyright (C) 2006, Red Hat, Inc.
|
||||
#
|
||||
# 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
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
|
||||
class PulsingIcon(CanvasIcon):
|
||||
__gproperties__ = {
|
||||
'colors' : (object, None, None,
|
||||
gobject.PARAM_READWRITE),
|
||||
'pulsing' : (bool, None, None, False,
|
||||
gobject.PARAM_READWRITE)
|
||||
}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self._pulsing = False
|
||||
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)
|
||||
|
||||
if pspec.name == 'pulsing':
|
||||
self._pulsing = value
|
||||
if self._pulsing:
|
||||
self._start()
|
||||
else:
|
||||
self._stop()
|
||||
elif pspec.name == 'colors':
|
||||
self._colors = value
|
||||
self._pos = 0
|
||||
|
||||
def do_get_property(self, pspec):
|
||||
CanvasIcon.do_get_property(self, pspec, value)
|
||||
|
||||
if pspec.name == 'pulsing':
|
||||
return self._pulsing
|
||||
elif pspec.name == 'colors':
|
||||
return self._colors
|
||||
|
||||
def _pulse_timeout(self):
|
||||
if not self._colors:
|
||||
return
|
||||
|
||||
self.props.stroke_color = self._colors[self._pos][0]
|
||||
self.props.fill_color = self._colors[self._pos][1]
|
||||
|
||||
self._pos += 1
|
||||
if self._pos == len(self._colors):
|
||||
self._pos = 0
|
||||
|
||||
return True
|
||||
|
||||
def _start(self):
|
||||
if self._pulse_sid == 0:
|
||||
self._pulse_sid = gobject.timeout_add(1000, self._pulse_timeout)
|
||||
|
||||
def _stop(self):
|
||||
if self._pulse_sid:
|
||||
gobject.source_remove(self._pulse_sid)
|
||||
self._pulse_sid = 0
|
Loading…
Reference in New Issue
Block a user