More work on devices, getting there

This commit is contained in:
Marco Pesenti Gritti 2007-02-28 15:42:41 +01:00
parent 0f1adfe1de
commit aec4fcf874
5 changed files with 49 additions and 32 deletions

View File

@ -1,6 +1,11 @@
from view.devices import deviceview from view.devices import deviceview
from sugar.graphics import canvasicon
_ICON_NAME = 'device-battery'
class DeviceView(deviceview.DeviceView): class DeviceView(deviceview.DeviceView):
def __init__(self, model): def __init__(self, model):
deviceview.DeviceView.__init__(self, model) deviceview.DeviceView.__init__(self, model)
self.props.icon_name = 'theme:stock-close'
icon_name = canvasicon.get_icon_state(_ICON_NAME, 60)
self.props.icon_name = icon_name

View File

@ -15,16 +15,12 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from sugar.graphics import canvasicon
from sugar.graphics import color
from view.devices import deviceview from view.devices import deviceview
from model.devices import wirelessnetwork from model.devices import wirelessnetwork
_strength_to_icon = { _ICON_NAME = 'device-network-wireless'
(0, 20) : 'stock-net-wireless-00',
(21, 40) : 'stock-net-wireless-21-40',
(41, 60) : 'stock-net-wireless-41-60',
(61, 80) : 'stock-net-wireless-61-80',
(81, 100) : 'stock-net-wireless-81-100'
}
class DeviceView(deviceview.DeviceView): class DeviceView(deviceview.DeviceView):
def __init__(self, model): def __init__(self, model):
@ -52,18 +48,20 @@ class DeviceView(deviceview.DeviceView):
self.props.tooltip = self._model.props.name self.props.tooltip = self._model.props.name
def _update_icon(self): def _update_icon(self):
strength = self._model.props.strength icon_name = canvasicon.get_icon_state(
for interval in _strength_to_icon.keys(): _ICON_NAME, self._model.props.strength)
if strength >= interval[0] and strength <= interval[1]: if icon_name:
stock_name = _strength_to_icon[interval] self.props.icon_name = icon_name
self.props.icon_name = 'theme:' + stock_name
def _update_state(self): def _update_state(self):
# FIXME Change icon colors once we have real icons # FIXME Change icon colors once we have real icons
state = self._model.props.state state = self._model.props.state
if state == wirelessnetwork.STATE_ACTIVATING: if state == wirelessnetwork.STATE_ACTIVATING:
self.props.background_color = 0xFF0000FF self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE
elif state == wirelessnetwork.STATE_ACTIVATED: elif state == wirelessnetwork.STATE_ACTIVATED:
self.props.background_color = 0x00FF00FF self.props.fill_color = None
self.props.stroke_color = None
elif state == wirelessnetwork.STATE_INACTIVE: elif state == wirelessnetwork.STATE_INACTIVE:
self.props.background_color = 0x00000000 self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE

View File

@ -22,17 +22,13 @@ import gobject
from sugar.graphics.spreadbox import SpreadBox from sugar.graphics.spreadbox import SpreadBox
from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.snowflakebox import SnowflakeBox
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import color
from model import accesspointmodel from model import accesspointmodel
from hardware import hardwaremanager from hardware import hardwaremanager
from view.BuddyIcon import BuddyIcon from view.BuddyIcon import BuddyIcon
from sugar.graphics import canvasicon
_strength_to_icon = { _ICON_NAME = 'device-network-wireless'
(0, 20) : 'stock-net-wireless-00',
(21, 40) : 'stock-net-wireless-21-40',
(41, 60) : 'stock-net-wireless-41-60',
(61, 80) : 'stock-net-wireless-61-80',
(81, 100) : 'stock-net-wireless-81-100'
}
class AccessPointView(CanvasIcon): class AccessPointView(CanvasIcon):
def __init__(self, model): def __init__(self, model):
@ -69,20 +65,22 @@ class AccessPointView(CanvasIcon):
self.props.tooltip = self._model.props.name self.props.tooltip = self._model.props.name
def _update_icon(self): def _update_icon(self):
strength = self._model.props.strength icon_name = canvasicon.get_icon_state(
for interval in _strength_to_icon.keys(): _ICON_NAME, self._model.props.strength)
if strength >= interval[0] and strength <= interval[1]: if icon_name:
stock_name = _strength_to_icon[interval] self.props.icon_name = icon_name
self.props.icon_name = 'theme:' + stock_name
def _update_state(self): def _update_state(self):
# FIXME Change icon colors once we have real icons # FIXME Change icon colors once we have real icons
if self._model.props.state == accesspointmodel.STATE_CONNECTING: if self._model.props.state == accesspointmodel.STATE_CONNECTING:
self.props.background_color = 0xFF0000FF self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE
elif self._model.props.state == accesspointmodel.STATE_CONNECTED: elif self._model.props.state == accesspointmodel.STATE_CONNECTED:
self.props.background_color = 0x00FF00FF self.props.fill_color = None
self.props.stroke_color = None
elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED: elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED:
self.props.background_color = 0x00000000 self.props.fill_color = color.ICON_FILL_INACTIVE
self.props.stroke_color = color.ICON_STROKE_INACTIVE
class ActivityView(SnowflakeBox): class ActivityView(SnowflakeBox):
def __init__(self, shell, menu_shell, model): def __init__(self, shell, menu_shell, model):

View File

@ -415,3 +415,15 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
Override this method for adding prelighting behavior. Override this method for adding prelighting behavior.
""" """
pass pass
def get_icon_state(base_name, perc):
step = 5
strength = round(perc / step) * step
icon_theme = gtk.icon_theme_get_default()
while strength <= 100:
icon_name = '%s-%03d' % (base_name, strength)
if icon_theme.has_icon(icon_name):
return 'theme:' + icon_name
strength = strength + step

View File

@ -21,7 +21,9 @@ _system_colors = {
'button-hover' : '#808080', 'button-hover' : '#808080',
'button-background-hover' : '#000000', 'button-background-hover' : '#000000',
'button-inactive' : '#808080', 'button-inactive' : '#808080',
'button-background-inactive' : '#424242' 'button-background-inactive' : '#424242',
'icon-stroke-inactive' : '#757575',
'icon-fill-inactive' : '#9D9FA1'
} }
def _html_to_rgb(html_color): def _html_to_rgb(html_color):
@ -100,3 +102,5 @@ BUTTON_HOVER = SystemColor('button-hover')
BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover') BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover')
BUTTON_INACTIVE = SystemColor('button-inactive') BUTTON_INACTIVE = SystemColor('button-inactive')
BUTTON_BACKGROUND_INACTIVE = SystemColor('button-background-inactive') BUTTON_BACKGROUND_INACTIVE = SystemColor('button-background-inactive')
ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive')
ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive')