Split the console service out of the shell, to remove dep

This commit is contained in:
Marco Pesenti Gritti 2006-08-12 16:19:47 +02:00
parent 0963329b47
commit 2636bc63d0
4 changed files with 37 additions and 26 deletions

View File

@ -1,6 +1,8 @@
import logging
import gtk
import dbus
import dbus.service
class Console(gtk.ScrolledWindow):
def __init__(self):
@ -37,6 +39,15 @@ class Console(gtk.ScrolledWindow):
else:
buf.insert(it, msg)
class ConsoleDbusService(dbus.service.Object):
def __init__(self, console, bus_name):
dbus.service.Object.__init__(self, bus_name, '/org/laptop/Sugar/Console')
self._console = console
@dbus.service.method('org.laptop.Sugar.Console')
def log(self, level, module_id, message):
self._console.log(level, module_id, message)
class ConsoleWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
@ -69,6 +80,10 @@ class ConsoleWindow(gtk.Window):
self._consoles = {}
session_bus = dbus.SessionBus()
bus_name = dbus.service.BusName('org.laptop.Sugar.Console', bus=session_bus)
ConsoleDbusService(self, bus_name)
def _add_console(self, page_id):
console = Console()
page = self._nb.append_page(console, gtk.Label(page_id))

View File

@ -7,11 +7,9 @@ import gtk
import gobject
import wnck
from sugar.LogWriter import LogWriter
from ActivityRegistry import ActivityRegistry
from HomeWindow import HomeWindow
from sugar import env
from ConsoleWindow import ConsoleWindow
from Owner import ShellOwner
from sugar.presence.PresenceService import PresenceService
from ActivityHost import ActivityHost
@ -39,10 +37,6 @@ class ShellDbusService(dbus.service.Object):
def show_console(self):
gobject.idle_add(self.__show_console_idle)
@dbus.service.method('com.redhat.Sugar.Shell')
def log(self, level, module_id, message):
self._shell.log(level, module_id, message)
class Shell(gobject.GObject):
__gsignals__ = {
'activity-closed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([str]))
@ -60,10 +54,6 @@ class Shell(gobject.GObject):
bus_name = dbus.service.BusName('com.redhat.Sugar.Shell', bus=session_bus)
ShellDbusService(self, bus_name)
self._console = ConsoleWindow()
sugar.logger.start('Shell', self)
self._owner = ShellOwner()
self._owner.announce()
@ -76,6 +66,9 @@ class Shell(gobject.GObject):
self._screen.connect('window-opened', self.__window_opened_cb)
self._screen.connect('window-closed', self.__window_closed_cb)
def set_console(self, console):
self._console = console
def __window_opened_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
self._hosts[window.get_xid()] = ActivityHost(self, window)
@ -156,9 +149,6 @@ class Shell(gobject.GObject):
logging.error('No such activity in the directory')
return None
def log(self, level, module_id, message):
self._console.log(level, module_id, message)
def get_registry(self):
return self._registry

View File

@ -9,6 +9,7 @@ import dbus.dbus_bindings
from sugar.presence import PresenceService
from Shell import Shell
from ConsoleWindow import ConsoleWindow
from session.Process import Process
import sugar.env
@ -69,6 +70,9 @@ class Session:
process = DbusProcess()
process.start()
console = ConsoleWindow()
sugar.logger.start('Shell', console)
process = MatchboxProcess()
process.start()
@ -76,6 +80,7 @@ class Session:
process.start()
shell = Shell(self._registry)
shell.set_console(console)
shell.start()
try:

View File

@ -6,20 +6,20 @@ from cStringIO import StringIO
import dbus
import gobject
__sugar_shell = None
__console = None
__console_id = None
class Handler(logging.Handler):
def __init__(self, shell, console_id):
def __init__(self, console, console_id):
logging.Handler.__init__(self)
self._console_id = console_id
self._shell = shell
self._console = console
self._records = []
def _log(self):
for record in self._records:
self._shell.log(record.levelno, self._console_id, record.msg)
self._console.log(record.levelno, self._console_id, record.msg)
self._records = []
return False
@ -32,22 +32,23 @@ def __exception_handler(typ, exc, tb):
trace = StringIO()
traceback.print_exception(typ, exc, tb, None, trace)
__sugar_shell.log(logging.ERROR, __console_id, trace.getvalue())
__console.log(logging.ERROR, __console_id, trace.getvalue())
def start(console_id, shell = None):
def start(console_id, console = None):
root_logger = logging.getLogger('')
root_logger.setLevel(logging.DEBUG)
if shell == None:
if console == None:
bus = dbus.SessionBus()
proxy_obj = bus.get_object('com.redhat.Sugar.Shell', '/com/redhat/Sugar/Shell')
shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Shell')
proxy_obj = bus.get_object('org.laptop.Sugar.Console',
'/org/laptop/Sugar/Console')
console = dbus.Interface(proxy_obj, 'org.laptop.Sugar.Console')
root_logger.addHandler(Handler(shell, console_id))
root_logger.addHandler(Handler(console, console_id))
global __sugar_shell
global __console
global __console_id
__sugar_shell = shell
__console = console
__console_id = console_id
sys.excepthook = __exception_handler