More work on devices, getting there
This commit is contained in:
parent
0f1adfe1de
commit
aec4fcf874
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user