From aec4fcf874f7262a63bd08368d4cf3c16b122f44 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 28 Feb 2007 15:42:41 +0100 Subject: [PATCH] More work on devices, getting there --- shell/view/devices/battery.py | 7 ++++++- shell/view/devices/wirelessnetwork.py | 28 +++++++++++++-------------- shell/view/home/MeshBox.py | 28 +++++++++++++-------------- sugar/graphics/canvasicon.py | 12 ++++++++++++ sugar/graphics/color.py | 6 +++++- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/shell/view/devices/battery.py b/shell/view/devices/battery.py index a13304e2..332590af 100644 --- a/shell/view/devices/battery.py +++ b/shell/view/devices/battery.py @@ -1,6 +1,11 @@ from view.devices import deviceview +from sugar.graphics import canvasicon + +_ICON_NAME = 'device-battery' class DeviceView(deviceview.DeviceView): def __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 diff --git a/shell/view/devices/wirelessnetwork.py b/shell/view/devices/wirelessnetwork.py index 9164810c..f85700ea 100644 --- a/shell/view/devices/wirelessnetwork.py +++ b/shell/view/devices/wirelessnetwork.py @@ -15,16 +15,12 @@ # along with this program; if not, write to the Free Software # 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 model.devices import wirelessnetwork -_strength_to_icon = { - (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' -} +_ICON_NAME = 'device-network-wireless' class DeviceView(deviceview.DeviceView): def __init__(self, model): @@ -52,18 +48,20 @@ class DeviceView(deviceview.DeviceView): self.props.tooltip = self._model.props.name def _update_icon(self): - strength = self._model.props.strength - for interval in _strength_to_icon.keys(): - if strength >= interval[0] and strength <= interval[1]: - stock_name = _strength_to_icon[interval] - self.props.icon_name = 'theme:' + stock_name + icon_name = canvasicon.get_icon_state( + _ICON_NAME, self._model.props.strength) + if icon_name: + self.props.icon_name = icon_name def _update_state(self): # FIXME Change icon colors once we have real icons state = self._model.props.state 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: - self.props.background_color = 0x00FF00FF + self.props.fill_color = None + self.props.stroke_color = None 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 diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py index ad94bef1..3521c14a 100644 --- a/shell/view/home/MeshBox.py +++ b/shell/view/home/MeshBox.py @@ -22,17 +22,13 @@ import gobject from sugar.graphics.spreadbox import SpreadBox from sugar.graphics.snowflakebox import SnowflakeBox from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics import color from model import accesspointmodel from hardware import hardwaremanager from view.BuddyIcon import BuddyIcon +from sugar.graphics import canvasicon -_strength_to_icon = { - (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' -} +_ICON_NAME = 'device-network-wireless' class AccessPointView(CanvasIcon): def __init__(self, model): @@ -69,20 +65,22 @@ class AccessPointView(CanvasIcon): self.props.tooltip = self._model.props.name def _update_icon(self): - strength = self._model.props.strength - for interval in _strength_to_icon.keys(): - if strength >= interval[0] and strength <= interval[1]: - stock_name = _strength_to_icon[interval] - self.props.icon_name = 'theme:' + stock_name + icon_name = canvasicon.get_icon_state( + _ICON_NAME, self._model.props.strength) + if icon_name: + 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.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: - self.props.background_color = 0x00FF00FF + self.props.fill_color = None + self.props.stroke_color = None 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): def __init__(self, shell, menu_shell, model): diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 56423d8e..4b1134c6 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -415,3 +415,15 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): Override this method for adding prelighting behavior. """ 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 diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index 864e8e39..5ff4c928 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -21,7 +21,9 @@ _system_colors = { 'button-hover' : '#808080', 'button-background-hover' : '#000000', '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): @@ -100,3 +102,5 @@ BUTTON_HOVER = SystemColor('button-hover') BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover') BUTTON_INACTIVE = SystemColor('button-inactive') BUTTON_BACKGROUND_INACTIVE = SystemColor('button-background-inactive') +ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive') +ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive')