diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2008-02-20 15:50:21 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2008-02-20 15:50:21 (GMT) |
commit | 1c2ce9f1c374e85b3174a6a8868cb6fad15cb715 (patch) | |
tree | f999361182bf85493124594e88b6e722a9923286 /src | |
parent | 3677745a10fbc7481fa1da02bd7b4c63e28d0deb (diff) |
Move devices to the bottom frame.
Diffstat (limited to 'src')
-rw-r--r-- | src/view/devices/battery.py | 28 | ||||
-rw-r--r-- | src/view/devices/deviceview.py | 3 | ||||
-rw-r--r-- | src/view/devices/network/mesh.py | 40 | ||||
-rw-r--r-- | src/view/devices/network/wireless.py | 32 | ||||
-rw-r--r-- | src/view/frame/Makefile.am | 1 | ||||
-rw-r--r-- | src/view/frame/devicestray.py | 60 | ||||
-rw-r--r-- | src/view/frame/frame.py | 7 | ||||
-rw-r--r-- | src/view/home/HomeBox.py | 35 |
8 files changed, 122 insertions, 84 deletions
diff --git a/src/view/devices/battery.py b/src/view/devices/battery.py index 09c69df..98ce778 100644 --- a/src/view/devices/battery.py +++ b/src/view/devices/battery.py @@ -19,24 +19,26 @@ from gettext import gettext as _ import gtk from sugar import profile -from sugar.graphics.icon import CanvasIcon from sugar.graphics.icon import get_icon_state -from sugar.graphics import style +from sugar.graphics.tray import TrayIcon from sugar.graphics.palette import Palette +from view.frame.frameinvoker import FrameWidgetInvoker + _ICON_NAME = 'battery' _STATUS_CHARGING = 0 _STATUS_DISCHARGING = 1 _STATUS_FULLY_CHARGED = 2 -class DeviceView(CanvasIcon): +class DeviceView(TrayIcon): def __init__(self, model): - CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE, - xo_color=profile.get_color()) + TrayIcon.__init__(self, icon_name=_ICON_NAME, xo_color=profile.get_color()) + self._model = model - self._palette = BatteryPalette(_('My Battery life')) - self.set_palette(self._palette) + self.palette = BatteryPalette(_('My Battery life')) + self.palette.props.invoker = FrameWidgetInvoker(self) + self.palette.set_group_id('frame') model.connect('notify::level', self._battery_status_changed_cb) model.connect('notify::charging', self._battery_status_changed_cb) @@ -45,21 +47,21 @@ class DeviceView(CanvasIcon): def _update_info(self): name = get_icon_state(_ICON_NAME, self._model.props.level) - self.props.icon_name = name + self.get_icon().props.icon_name = name # Update palette if self._model.props.charging: status = _STATUS_CHARGING - self.props.badge_name = 'emblem-charging' + self.get_icon().props.badge_name = 'emblem-charging' elif self._model.props.discharging: status = _STATUS_DISCHARGING - self.props.badge_name = None + self.get_icon().props.badge_name = None else: status = _STATUS_FULLY_CHARGED - self.props.badge_name = None + self.get_icon().props.badge_name = None - self._palette.set_level(self._model.props.level) - self._palette.set_status(status) + self.palette.set_level(self._model.props.level) + self.palette.set_status(status) def _battery_status_changed_cb(self, pspec, param): self._update_info() diff --git a/src/view/devices/deviceview.py b/src/view/devices/deviceview.py index f58da02..90ebbf5 100644 --- a/src/view/devices/deviceview.py +++ b/src/view/devices/deviceview.py @@ -14,8 +14,6 @@ # 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.icon import CanvasIcon - def create(model): name = 'view.devices.' + model.get_type() @@ -25,3 +23,4 @@ def create(model): mod = getattr(mod, comp) return mod.DeviceView(model) + diff --git a/src/view/devices/network/mesh.py b/src/view/devices/network/mesh.py index 2543957..e700554 100644 --- a/src/view/devices/network/mesh.py +++ b/src/view/devices/network/mesh.py @@ -1,5 +1,5 @@ -# # Copyright (C) 2006-2007 Red Hat, Inc. +# Copyright (C) 2008 One Laptop Per Child # # 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 @@ -20,22 +20,24 @@ from gettext import gettext as _ import gtk from sugar import profile -from sugar.graphics.icon import CanvasIcon +from sugar.graphics.tray import TrayIcon from sugar.graphics import style -from model.devices import device - from sugar.graphics.palette import Palette -from model.devices.network import wireless +from model.devices import device +from model.devices.network import wireless from hardware import hardwaremanager +from view.frame.frameinvoker import FrameWidgetInvoker -class DeviceView(CanvasIcon): +class DeviceView(TrayIcon): def __init__(self, model): - CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE, - icon_name='network-mesh') + TrayIcon.__init__(self, icon_name='network-mesh') + self._model = model - self._palette = MeshPalette(_("Mesh Network"), model) - self.set_palette(self._palette) + + self.palette = MeshPalette(_("Mesh Network"), model) + self.palette.props.invoker = FrameWidgetInvoker(self) + self.palette.set_group_id('frame') model.connect('notify::state', self._state_changed_cb) model.connect('notify::activation-stage', self._state_changed_cb) @@ -47,24 +49,24 @@ class DeviceView(CanvasIcon): def _update_state(self): # FIXME Change icon colors once we have real icons state = self._model.props.state - self._palette.update_state(state) + self.palette.update_state(state) if state == device.STATE_ACTIVATING: - self.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() - self.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() + self.get_icon().props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() + self.get_icon().props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() elif state == device.STATE_ACTIVATED: - self.props.xo_color = profile.get_color() + self.get_icon().props.xo_color = profile.get_color() elif state == device.STATE_INACTIVE: - self.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() - self.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() + self.get_icon().props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() + self.get_icon().props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() if state == device.STATE_INACTIVE: - self._palette.set_primary_text(_("Mesh Network")) + self.palette.set_primary_text(_("Mesh Network")) else: chan = wireless.freq_to_channel(self._model.props.frequency) if chan > 0: - self._palette.set_primary_text(_("Mesh Network") + " %d" % chan) - self._palette.set_mesh_step(self._model.props.mesh_step, state) + self.palette.set_primary_text(_("Mesh Network") + " %d" % chan) + self.palette.set_mesh_step(self._model.props.mesh_step, state) class MeshPalette(Palette): def __init__(self, primary_text, model): diff --git a/src/view/devices/network/wireless.py b/src/view/devices/network/wireless.py index f4f8869..ad9f5c8 100644 --- a/src/view/devices/network/wireless.py +++ b/src/view/devices/network/wireless.py @@ -20,21 +20,21 @@ from gettext import gettext as _ import gtk from sugar.graphics.icon import get_icon_state -from sugar.graphics.icon import CanvasIcon +from sugar.graphics.tray import TrayIcon from sugar.graphics import style from sugar.graphics.palette import Palette from model.devices.network import wireless from model.devices import device - from hardware import hardwaremanager from hardware import nmclient +from view.frame.frameinvoker import FrameWidgetInvoker _ICON_NAME = 'network-wireless' -class DeviceView(CanvasIcon): +class DeviceView(TrayIcon): def __init__(self, model): - CanvasIcon.__init__(self, size=style.MEDIUM_ICON_SIZE) + TrayIcon.__init__(self) self._model = model meshdev = None @@ -44,10 +44,11 @@ class DeviceView(CanvasIcon): meshdev = device break - self._palette = WirelessPalette(self._get_palette_primary_text(), meshdev) - self.set_palette(self._palette) self._counter = 0 - self._palette.set_frequency(self._model.props.frequency) + self.palette = WirelessPalette(self._get_palette_primary_text(), meshdev) + self.palette.props.invoker = FrameWidgetInvoker(self) + self.palette.set_group_id('frame') + self.palette.set_frequency(self._model.props.frequency) model.connect('notify::name', self._name_changed_cb) model.connect('notify::strength', self._strength_changed_cb) @@ -65,7 +66,7 @@ class DeviceView(CanvasIcon): self._update_icon() # Only update frequency periodically if self._counter % 4 == 0: - self._palette.set_frequency(self._model.props.frequency) + self.palette.set_frequency(self._model.props.frequency) self._counter += 1 def _name_changed_cb(self, model, pspec): @@ -81,21 +82,22 @@ class DeviceView(CanvasIcon): strength = 0 icon_name = get_icon_state(_ICON_NAME, strength) if icon_name: - self.props.icon_name = icon_name + self.get_icon().props.icon_name = icon_name def _update_state(self): # FIXME Change icon colors once we have real icons state = self._model.props.state + icon = self.get_icon() if state == device.STATE_ACTIVATING: - self.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() - self.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() + icon.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() + icon.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() elif state == device.STATE_ACTIVATED: (stroke, fill) = self._model.get_active_network_colors() - self.props.stroke_color = stroke - self.props.fill_color = fill + icon.props.stroke_color = stroke + icon.props.fill_color = fill elif state == device.STATE_INACTIVE: - self.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() - self.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() + icon.props.fill_color = style.COLOR_INACTIVE_FILL.get_svg() + icon.props.stroke_color = style.COLOR_INACTIVE_STROKE.get_svg() class WirelessPalette(Palette): def __init__(self, primary_text, meshdev): diff --git a/src/view/frame/Makefile.am b/src/view/frame/Makefile.am index 1091b6a..979a351 100644 --- a/src/view/frame/Makefile.am +++ b/src/view/frame/Makefile.am @@ -6,6 +6,7 @@ sugar_PYTHON = \ activitybutton.py \ clipboardpanelwindow.py \ clipboardtray.py \ + devicestray.py \ frameinvoker.py \ friendstray.py \ eventarea.py \ diff --git a/src/view/frame/devicestray.py b/src/view/frame/devicestray.py new file mode 100644 index 0000000..e788bbf --- /dev/null +++ b/src/view/frame/devicestray.py @@ -0,0 +1,60 @@ +# Copyright (C) 2008 One Laptop Per Child +# +# 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 logging +from gettext import gettext as _ + +import gtk + +from sugar.graphics.tray import HTray +from sugar.graphics.icon import Icon +from sugar.graphics.palette import Palette +from sugar.graphics.menuitem import MenuItem + +from view.frame.frameinvoker import FrameWidgetInvoker +from view.devices import deviceview + +class DevicesTray(HTray): + def __init__(self, shell): + HTray.__init__(self) + self._device_icons = {} + + devices_model = shell.get_model().get_devices() + + for device in devices_model: + self._add_device(device) + + devices_model.connect('device-appeared', + self.__device_appeared_cb) + devices_model.connect('device-disappeared', + self.__device_disappeared_cb) + + def _add_device(self, device): + view = deviceview.create(device) + self.pack_end(view, expand=False, fill=False, padding=0) + view.show() + self._device_icons[device.get_id()] = view + + def _remove_device(self, device): + self.remove_item(self._device_icons[device.get_id()]) + del self._device_icons[device.get_id()] + + def __device_appeared_cb(self, model, device): + self._add_device(device) + + def __device_disappeared_cb(self, model, device): + self._remove_device(device) + diff --git a/src/view/frame/frame.py b/src/view/frame/frame.py index ac72127..ce9bc15 100644 --- a/src/view/frame/frame.py +++ b/src/view/frame/frame.py @@ -30,6 +30,7 @@ from view.frame.activitiestray import ActivitiesTray from view.frame import activitiestray2 from view.frame.zoomtray import ZoomTray from view.frame.friendstray import FriendsTray +from view.frame.devicestray import DevicesTray from view.frame.framewindow import FrameWindow from view.frame.clipboardpanelwindow import ClipboardPanelWindow from model.shellmodel import ShellModel @@ -180,8 +181,14 @@ class Frame(object): def _create_bottom_panel(self): panel = self._create_panel(gtk.POS_BOTTOM) + """ activities_tray = activitiestray2.ActivitiesTray(self._shell) panel.append(hippo.CanvasWidget(widget=activities_tray), hippo.PACK_EXPAND) + """ + + devices_tray = DevicesTray(self._shell) + panel.append(hippo.CanvasWidget(widget=devices_tray), hippo.PACK_EXPAND) + devices_tray.show() return panel diff --git a/src/view/home/HomeBox.py b/src/view/home/HomeBox.py index 8764887..d2105fe 100644 --- a/src/view/home/HomeBox.py +++ b/src/view/home/HomeBox.py @@ -32,7 +32,6 @@ from sugar.profile import get_profile from sugar import env from view.home.activitiesdonut import ActivitiesDonut -from view.devices import deviceview from view.home.MyIcon import MyIcon from model.shellmodel import ShellModel from hardware import schoolserver @@ -64,9 +63,6 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): self._my_icon = _MyIcon(shell, style.XLARGE_ICON_SIZE) self.append(self._my_icon, hippo.PACK_FIXED) - self._devices_box = _DevicesBox(shell_model.get_devices()) - bottom_box.append(self._devices_box) - shell_model.connect('notify::state', self._shell_state_changed_cb) @@ -114,37 +110,6 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): def release(self): pass -class _DevicesBox(hippo.CanvasBox): - def __init__(self, devices_model): - gobject.GObject.__init__(self, - orientation=hippo.ORIENTATION_HORIZONTAL, - xalign=hippo.ALIGNMENT_CENTER) - - self._device_icons = {} - - for device in devices_model: - self._add_device(device) - - devices_model.connect('device-appeared', - self._device_appeared_cb) - devices_model.connect('device-disappeared', - self._device_disappeared_cb) - - def _add_device(self, device): - view = deviceview.create(device) - self.append(view) - self._device_icons[device.get_id()] = view - - def _remove_device(self, device): - self.remove(self._device_icons[device.get_id()]) - del self._device_icons[device.get_id()] - - def _device_appeared_cb(self, model, device): - self._add_device(device) - - def _device_disappeared_cb(self, model, device): - self._remove_device(device) - class _MyIcon(MyIcon): def __init__(self, shell, scale): MyIcon.__init__(self, scale) |