Infrastructure for the home page devices

This commit is contained in:
Marco Pesenti Gritti 2007-02-20 11:48:03 +01:00
parent e24193c551
commit e0dd1f5232
16 changed files with 130 additions and 8 deletions

View File

@ -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

View File

@ -1,3 +1,5 @@
SUBDIRS = devices
sugardir = $(pkgdatadir)/shell/model
sugar_PYTHON = \
__init__.py \

View File

@ -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

View File

@ -0,0 +1,7 @@
sugardir = $(pkgdatadir)/shell/model/devices
sugar_PYTHON = \
__init__.py \
device.py \
devicesmodel.py \
battery.py \
network.py

View File

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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 \

View File

@ -0,0 +1,6 @@
sugardir = $(pkgdatadir)/shell/view/devices
sugar_PYTHON = \
__init__.py \
battery.py \
deviceview.py \
network.py

View File

View File

@ -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'

View File

@ -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)

View File

@ -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'

View File

@ -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