"Moved" the new console work on a branch.

This commit is contained in:
Marco Pesenti Gritti 2007-10-01 01:25:35 +02:00
parent 1be27d4b4a
commit f0afda2e30
5 changed files with 2 additions and 176 deletions

View File

@ -1 +0,0 @@
from console import Console

View File

@ -1,76 +0,0 @@
import os
import gtk
import hippo
from sugar.graphics.roundbox import CanvasRoundBox
from model.shellmodel import ShellModel
class Console(gtk.Window):
def __init__(self, shell_model):
gtk.Window.__init__(self)
self._shell_model = shell_model
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)
self.set_default_size(gtk.gdk.screen_width() * 5 / 6,
gtk.gdk.screen_height() * 5 / 6)
self.set_decorated(False)
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.connect('realize', self._realize_cb)
self.canvas = hippo.Canvas()
self.add(self.canvas)
self.canvas.show()
self.registry = Registry()
self.context = 'shell'
self._update_view()
def _update_view(self):
box = hippo.CanvasBox(padding=20, background_color=0x000000FF)
self.canvas.set_root(box)
for module in self.registry.view_modules:
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.context = 'shell'
self._update_view()
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.context = 'mesh'
self._update_view()
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 = []
view_modules = [ 'console.logviewer' ]
for module in view_modules:
self.load_view_modules(module)
def load_view_modules(self, name):
module = __import__(name)
components = name.split('.')
for component in components[1:]:
module = getattr(module, component)
self.view_modules.append(module)

View File

@ -1,83 +0,0 @@
import os
import gtk
import hippo
import gnomevfs
from louie import dispatcher
from sugar import env
class LogEntry(object):
def __init__(self, text):
self.text = text.strip()
class LogModel(list):
def __init__(self, path):
self.path = path
self.position = 0
self.read_lines()
gnomevfs.monitor_add('file://' + self.path,
gnomevfs.MONITOR_FILE,
self._log_file_changed_cb)
def read_lines(self):
log_file = open(self.path, 'r')
log_file.seek(self.position)
for line in log_file.readlines():
self.add_line(line)
self.position = log_file.tell()
log_file.close()
def add_line(self, line):
entry = LogEntry(line)
self.append(entry)
dispatcher.send('entry-added', self, entry)
def _log_file_changed_cb(self, monitor_uri, info_uri, event):
if event == gnomevfs.MONITOR_EVENT_CHANGED:
self.read_lines()
class LogView(hippo.CanvasBox):
def __init__(self, path):
hippo.CanvasBox.__init__(self)
self.model = LogModel(path)
scrollbars = hippo.CanvasScrollbars()
scrollbars.set_policy(hippo.ORIENTATION_HORIZONTAL,
hippo.SCROLLBAR_NEVER)
widget = scrollbars.props.widget
widget.props.vadjustment.connect('changed', self._vadj_changed_cb)
self.append(scrollbars, hippo.PACK_EXPAND)
self.box = hippo.CanvasBox(spacing=5, background_color=0xFFFFFFFF)
scrollbars.set_root(self.box)
for entry_model in self.model:
self.add_entry(entry_model)
dispatcher.connect(self._entry_added_cb, 'entry-added', self.model)
def add_entry(self, entry_model):
entry_box = hippo.CanvasBox(padding=5)
self.box.append(entry_box)
entry = hippo.CanvasText(text=entry_model.text,
xalign=hippo.ALIGNMENT_START,
size_mode=hippo.CANVAS_SIZE_WRAP_WORD)
entry_box.append(entry)
def _entry_added_cb(self, entry):
self.add_entry(entry)
def _vadj_changed_cb(self, adj):
adj.props.value = adj.upper - adj.page_size
def create_view(context):
name = context.replace('activity:', '')
path = os.path.join(env.get_profile_path(), 'logs', name + '.log')
return LogView(path)

View File

@ -36,7 +36,6 @@ from view.frame.frame import Frame
from view.keyhandler import KeyHandler
from view.home.HomeWindow import HomeWindow
from model.shellmodel import ShellModel
from console import Console
class Shell(gobject.GObject):
def __init__(self, model):
@ -65,8 +64,6 @@ class Shell(gobject.GObject):
home_model.connect('pending-activity-changed',
self._pending_activity_changed_cb)
self._console = Console(model)
gobject.idle_add(self._start_journal_idle)
def _start_journal_idle(self):
@ -168,12 +165,6 @@ class Shell(gobject.GObject):
return host
return None
def toggle_console_visibility(self):
if self._console.props.visible:
self._console.hide()
else:
self._console.show()
def toggle_chat_visibility(self):
act = self.get_current_activity()
if not act:

View File

@ -25,7 +25,6 @@ import gtk
from hardware import hardwaremanager
from model.shellmodel import ShellModel
from sugar._sugaruiext import KeyGrabber
import console
_BRIGHTNESS_STEP = 2
_VOLUME_STEP = 10
@ -48,7 +47,6 @@ _actions_table = {
'<alt>1' : 'screenshot',
'<alt>equal' : 'console',
'<alt>0' : 'console',
'<alt>9' : 'new_console',
'<alt>f' : 'frame',
'0x93' : 'frame',
'<alt>o' : 'overlay',
@ -147,9 +145,6 @@ class KeyHandler(object):
def handle_console(self):
gobject.idle_add(self._toggle_console_visibility_cb)
def handle_new_console(self):
self._shell.toggle_console_visibility()
def handle_frame(self):
self._shell.get_frame().notify_key_press()
@ -222,5 +217,5 @@ class KeyHandler(object):
bus = dbus.SessionBus()
proxy = bus.get_object('org.laptop.sugar.Console',
'/org/laptop/sugar/Console')
console_service = dbus.Interface(proxy, 'org.laptop.sugar.Console')
console_service.ToggleVisibility()
console = dbus.Interface(proxy, 'org.laptop.sugar.Console')
console.ToggleVisibility()