From e0dd1f52322090687410cc20a4255a8eb00f8928 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 20 Feb 2007 11:48:03 +0100 Subject: [PATCH] Infrastructure for the home page devices --- configure.ac | 4 +++- shell/model/Makefile.am | 2 ++ shell/model/ShellModel.py | 5 +++++ shell/model/devices/Makefile.am | 7 +++++++ shell/model/devices/__init__.py | 0 shell/model/devices/battery.py | 11 +++++++++++ shell/model/devices/device.py | 11 +++++++++++ shell/model/devices/devicesmodel.py | 29 +++++++++++++++++++++++++++++ shell/model/devices/network.py | 11 +++++++++++ shell/view/Makefile.am | 4 ++-- shell/view/devices/Makefile.am | 6 ++++++ shell/view/devices/__init__.py | 0 shell/view/devices/battery.py | 6 ++++++ shell/view/devices/deviceview.py | 16 ++++++++++++++++ shell/view/devices/network.py | 6 ++++++ shell/view/home/HomeBox.py | 20 +++++++++++++++----- 16 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 shell/model/devices/Makefile.am create mode 100644 shell/model/devices/__init__.py create mode 100644 shell/model/devices/battery.py create mode 100644 shell/model/devices/device.py create mode 100644 shell/model/devices/devicesmodel.py create mode 100644 shell/model/devices/network.py create mode 100644 shell/view/devices/Makefile.am create mode 100644 shell/view/devices/__init__.py create mode 100644 shell/view/devices/battery.py create mode 100644 shell/view/devices/deviceview.py create mode 100644 shell/view/devices/network.py diff --git a/configure.ac b/configure.ac index 9e6f0b51..f6abe908 100644 --- a/configure.ac +++ b/configure.ac @@ -117,9 +117,11 @@ services/datastore/Makefile shell/Makefile shell/data/Makefile shell/view/Makefile -shell/view/home/Makefile +shell/view/devices/Makefile shell/view/frame/Makefile +shell/view/home/Makefile shell/model/Makefile +shell/model/devices/Makefile services/console/lib/Makefile services/console/lib/procmem/Makefile services/console/Makefile diff --git a/shell/model/Makefile.am b/shell/model/Makefile.am index 010f000e..e21b3d4a 100644 --- a/shell/model/Makefile.am +++ b/shell/model/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = devices + sugardir = $(pkgdatadir)/shell/model sugar_PYTHON = \ __init__.py \ diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index 7e982e0c..abfff21c 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -24,6 +24,7 @@ from model.Friends import Friends from model.MeshModel import MeshModel from model.homemodel import HomeModel from model.Owner import ShellOwner +from model.devices.devicesmodel import DevicesModel from sugar import env class ShellModel(gobject.GObject): @@ -54,6 +55,7 @@ class ShellModel(gobject.GObject): self._friends = Friends() self._mesh = MeshModel(self._bundle_registry) self._home = HomeModel(self._bundle_registry) + self._devices = DevicesModel() for path in env.get_data_dirs(): bundles_path = os.path.join(path, 'activities') @@ -86,3 +88,6 @@ class ShellModel(gobject.GObject): def get_owner(self): return self._owner + + def get_devices(self): + return self._devices diff --git a/shell/model/devices/Makefile.am b/shell/model/devices/Makefile.am new file mode 100644 index 00000000..c987bb7b --- /dev/null +++ b/shell/model/devices/Makefile.am @@ -0,0 +1,7 @@ +sugardir = $(pkgdatadir)/shell/model/devices +sugar_PYTHON = \ + __init__.py \ + device.py \ + devicesmodel.py \ + battery.py \ + network.py diff --git a/shell/model/devices/__init__.py b/shell/model/devices/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/model/devices/battery.py b/shell/model/devices/battery.py new file mode 100644 index 00000000..1d325ac8 --- /dev/null +++ b/shell/model/devices/battery.py @@ -0,0 +1,11 @@ +from model.devices import device + +class Device(device.Device): + def __init__(self): + device.Device.__init__(self) + + def get_type(self): + return 'network' + + def get_level(self): + return 0 diff --git a/shell/model/devices/device.py b/shell/model/devices/device.py new file mode 100644 index 00000000..02afd3cd --- /dev/null +++ b/shell/model/devices/device.py @@ -0,0 +1,11 @@ +from sugar import util + +class Device(object): + def __init__(self): + self._id = util.unique_id() + + def get_type(self): + return 'unknown' + + def get_id(self): + return self._id diff --git a/shell/model/devices/devicesmodel.py b/shell/model/devices/devicesmodel.py new file mode 100644 index 00000000..e5a06389 --- /dev/null +++ b/shell/model/devices/devicesmodel.py @@ -0,0 +1,29 @@ +import gobject + +from model.devices import device +from model.devices import network +from model.devices import battery + +class DevicesModel(gobject.GObject): + __gsignals__ = { + 'device-appeared' : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'device-disappeared': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) + } + + def __init__(self): + gobject.GObject.__init__(self) + + self._devices = [] + + self.add_device(network.Device()) + self.add_device(battery.Device()) + + def __iter__(self): + return iter(self._devices) + + def add_device(self, device): + self._devices.append(device) diff --git a/shell/model/devices/network.py b/shell/model/devices/network.py new file mode 100644 index 00000000..1d325ac8 --- /dev/null +++ b/shell/model/devices/network.py @@ -0,0 +1,11 @@ +from model.devices import device + +class Device(device.Device): + def __init__(self): + device.Device.__init__(self) + + def get_type(self): + return 'network' + + def get_level(self): + return 0 diff --git a/shell/view/Makefile.am b/shell/view/Makefile.am index 302c953c..39307dbd 100644 --- a/shell/view/Makefile.am +++ b/shell/view/Makefile.am @@ -1,6 +1,6 @@ -SUBDIRS = frame home +SUBDIRS = devices frame home -sugardir = $(pkgdatadir)/shell/view +sugardir = $(pkgdatadir)/shell/view/devices sugar_PYTHON = \ __init__.py \ ActivityHost.py \ diff --git a/shell/view/devices/Makefile.am b/shell/view/devices/Makefile.am new file mode 100644 index 00000000..54290e03 --- /dev/null +++ b/shell/view/devices/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/shell/view/devices +sugar_PYTHON = \ + __init__.py \ + battery.py \ + deviceview.py \ + network.py diff --git a/shell/view/devices/__init__.py b/shell/view/devices/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/view/devices/battery.py b/shell/view/devices/battery.py new file mode 100644 index 00000000..149e9b24 --- /dev/null +++ b/shell/view/devices/battery.py @@ -0,0 +1,6 @@ +from view.devices import deviceview + +class DeviceView(deviceview.DeviceView) + def __init__(self, model): + deviceview.DeviceView.__init__(self, model) + self.props.icon_name = 'theme:stock-close' diff --git a/shell/view/devices/deviceview.py b/shell/view/devices/deviceview.py new file mode 100644 index 00000000..f35f0824 --- /dev/null +++ b/shell/view/devices/deviceview.py @@ -0,0 +1,16 @@ +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() + + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + + return mod.DeviceView(model) diff --git a/shell/view/devices/network.py b/shell/view/devices/network.py new file mode 100644 index 00000000..a13304e2 --- /dev/null +++ b/shell/view/devices/network.py @@ -0,0 +1,6 @@ +from view.devices import deviceview + +class DeviceView(deviceview.DeviceView): + def __init__(self, model): + deviceview.DeviceView.__init__(self, model) + self.props.icon_name = 'theme:stock-close' diff --git a/shell/view/home/HomeBox.py b/shell/view/home/HomeBox.py index bdc66210..13032a62 100644 --- a/shell/view/home/HomeBox.py +++ b/shell/view/home/HomeBox.py @@ -16,12 +16,14 @@ import hippo -from view.home.activitiesdonut import ActivitiesDonut -from view.home.MyIcon import MyIcon -from model.ShellModel import ShellModel from sugar.graphics import units from sugar.graphics.iconcolor import IconColor +from view.home.activitiesdonut import ActivitiesDonut +from view.devices import deviceview +from view.home.MyIcon import MyIcon +from model.ShellModel import ShellModel + class HomeBox(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarHomeBox' @@ -36,8 +38,16 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem): self._my_icon = MyIcon(units.XLARGE_ICON_SCALE) self.append(self._my_icon, hippo.PACK_FIXED) - shell.get_model().connect('notify::state', - self._shell_state_changed_cb) + shell_model = shell.get_model() + shell_model.connect('notify::state', + self._shell_state_changed_cb) + + for device in shell_model.get_devices(): + self._add_device(device) + + def _add_device(self, device): + view = deviceview.create(device) + self.append(view, hippo.PACK_FIXED) def _shell_state_changed_cb(self, model, pspec): # FIXME handle all possible mode switches