2007-09-30 12:42:48 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import hippo
|
|
|
|
|
2007-09-30 14:24:03 +02:00
|
|
|
from sugar.graphics.roundbox import CanvasRoundBox
|
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
from model.shellmodel import ShellModel
|
|
|
|
|
2007-09-30 12:42:48 +02:00
|
|
|
class Console(gtk.Window):
|
2007-09-30 14:24:03 +02:00
|
|
|
def __init__(self, shell_model):
|
2007-09-30 12:42:48 +02:00
|
|
|
gtk.Window.__init__(self)
|
|
|
|
|
2007-09-30 14:24:03 +02:00
|
|
|
self._shell_model = shell_model
|
2007-09-30 23:34:23 +02:00
|
|
|
self._home_model = shell_model.get_home()
|
|
|
|
self._shell_model.connect('notify::zoom-level',
|
|
|
|
self._zoom_level_changed_cb)
|
|
|
|
self._home_model.connect('active-activity-changed',
|
|
|
|
self._active_activity_changed_cb)
|
2007-09-30 14:24:03 +02:00
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
self.set_default_size(gtk.gdk.screen_width() * 5 / 6,
|
|
|
|
gtk.gdk.screen_height() * 5 / 6)
|
2007-09-30 12:42:48 +02:00
|
|
|
self.set_decorated(False)
|
|
|
|
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
|
|
|
|
self.connect('realize', self._realize_cb)
|
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
self.canvas = hippo.Canvas()
|
|
|
|
self.add(self.canvas)
|
|
|
|
self.canvas.show()
|
|
|
|
|
|
|
|
self.registry = Registry()
|
|
|
|
self.context = 'shell'
|
|
|
|
self._update_view()
|
2007-09-30 12:42:48 +02:00
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
def _update_view(self):
|
2007-09-30 14:24:03 +02:00
|
|
|
box = hippo.CanvasBox(padding=20, background_color=0x000000FF)
|
2007-09-30 23:34:23 +02:00
|
|
|
self.canvas.set_root(box)
|
2007-09-30 12:42:48 +02:00
|
|
|
|
|
|
|
for module in self.registry.view_modules:
|
2007-09-30 23:34:23 +02:00
|
|
|
box.append(module.create_view(self.context), hippo.PACK_EXPAND)
|
|
|
|
|
|
|
|
def _active_activity_changed_cb(self, home_model, activity):
|
|
|
|
if self._shell_model.get_zoom_level() == ShellModel.ZOOM_HOME:
|
|
|
|
self.context = 'activity:' + activity.get_type()
|
|
|
|
self._update_view()
|
|
|
|
|
|
|
|
def _zoom_level_changed_cb(self, shell_model, pspec):
|
|
|
|
if shell_model.props.zoom_level == ShellModel.ZOOM_HOME:
|
|
|
|
self.set_context('home')
|
|
|
|
elif shell_model.props.zoom_level == ShellModel.ZOOM_ACTIVITY:
|
|
|
|
activity = self._home_model.get_active_activity()
|
|
|
|
self.context = 'activity:' + activity.get_type()
|
|
|
|
self._update_view()
|
|
|
|
else:
|
|
|
|
self.set_context('mesh')
|
2007-09-30 12:42:48 +02:00
|
|
|
|
|
|
|
def _realize_cb(self, widget):
|
|
|
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
|
|
|
|
class Registry(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.view_modules = []
|
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
view_modules = [ 'console.logviewer' ]
|
|
|
|
for module in view_modules:
|
|
|
|
self.load_view_modules(module)
|
2007-09-30 12:42:48 +02:00
|
|
|
|
2007-09-30 23:34:23 +02:00
|
|
|
def load_view_modules(self, name):
|
2007-09-30 12:42:48 +02:00
|
|
|
module = __import__(name)
|
|
|
|
components = name.split('.')
|
|
|
|
for component in components[1:]:
|
|
|
|
module = getattr(module, component)
|
|
|
|
|
|
|
|
self.view_modules.append(module)
|