More work on the new console

This commit is contained in:
Marco Pesenti Gritti 2007-09-30 12:42:48 +02:00
parent 03a4f01c25
commit c8b5ab290e
4 changed files with 86 additions and 22 deletions

20
shell/console/__init__.py Normal file
View File

@ -0,0 +1,20 @@
from console import Console
console = None
def show():
global console
if not console:
console = Console()
console.show()
def hide():
if console:
console.hide()
def toggle_visibility():
if not console or not console.props.visible:
show()
else:
hide()

45
shell/console/console.py Normal file
View File

@ -0,0 +1,45 @@
import os
import gtk
import hippo
class Console(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.set_default_size(gtk.gdk.screen_width() * 3 / 4,
gtk.gdk.screen_height() * 3 / 4)
self.set_decorated(False)
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
self.connect('realize', self._realize_cb)
canvas = hippo.Canvas()
self.add(canvas)
canvas.show()
box = hippo.CanvasBox(padding=20, border_color=0x000000FF,
border=3)
canvas.set_root(box)
self.registry = Registry()
for module in self.registry.view_modules:
box.append(module.create_view('shell'), hippo.PACK_EXPAND)
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 = []
base_extensions = [ 'console.logviewer' ]
for extension in base_extensions:
self.load_extension(extension)
def load_extension(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,9 +1,12 @@
import os
import gtk
import hippo
import gnomevfs
from louie import dispatcher
from sugar.graphics.roundbox import CanvasRoundBox
from sugar import env
class LogEntry(object):
def __init__(self, text):
@ -39,20 +42,20 @@ class LogModel(list):
if event == gnomevfs.MONITOR_EVENT_CHANGED:
self.read_lines()
class LogView(hippo.Canvas):
def __init__(self, model):
hippo.Canvas.__init__(self)
class LogView(hippo.CanvasBox):
def __init__(self, path):
hippo.CanvasBox.__init__(self)
self.model = model
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.set_root(scrollbars)
self.append(scrollbars, hippo.PACK_EXPAND)
self.box = hippo.CanvasBox(spacing=5, padding=20)
self.box = hippo.CanvasBox(spacing=5)
scrollbars.set_root(self.box)
for entry_model in self.model:
@ -74,18 +77,9 @@ class LogView(hippo.Canvas):
def _vadj_changed_cb(self, adj):
adj.props.value = adj.upper - adj.page_size
if __name__ == "__main__":
import sys
def get_tags():
return [ 'log' ]
window = gtk.Window()
window.set_default_size(800, 600)
model = LogModel(sys.argv[1])
log_view = LogView(model)
window.add(log_view)
log_view.show()
window.show()
gtk.main()
def create_view(context):
path = os.path.join(env.get_profile_path(), 'logs', context + '.log')
return LogView(path)

View File

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