Show all activities output in the console, just

activate the tab for the current activity.
This commit is contained in:
Marco Pesenti Gritti 2006-08-11 15:21:11 +02:00
parent 628271959c
commit 884eef4bd5
3 changed files with 70 additions and 35 deletions

View File

@ -1,5 +1,20 @@
import gtk
class Console(gtk.ScrolledWindow):
def __init__(self):
gtk.ScrolledWindow.__init__(self)
self.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
self._textview = gtk.TextView()
self._textview.set_wrap_mode(gtk.WRAP_WORD)
self.add(self._textview)
self._textview.show()
def log(self, message):
buf = self._textview.get_buffer()
buf.insert(buf.get_end_iter(), message)
class ConsoleWindow(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
@ -9,18 +24,32 @@ class ConsoleWindow(gtk.Window):
self.set_title("Console")
self.connect("delete_event", lambda w, e: w.hide_on_delete())
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
self._nb = gtk.Notebook()
self.add(self._nb)
self._nb.show()
self._console = gtk.TextView()
self._console.set_wrap_mode(gtk.WRAP_WORD)
sw.add(self._console)
self._console.show()
self._consoles = {}
self.add(sw)
sw.show()
def _add_console(self, page_id):
console = Console()
page = self._nb.append_page(console, gtk.Label(page_id))
console.show()
def log(self, message):
buf = self._console.get_buffer()
buf.insert(buf.get_end_iter(), message)
self._consoles[page_id] = console
return console
def _get_console(self, page_id):
if not self._consoles.has_key(page_id):
console = self._add_console(page_id)
else:
console = self._consoles[page_id]
return console
def set_page(self, page_id):
page = self._nb.page_num(self._consoles[page_id])
self._nb.set_current_page(page)
def log(self, page_id, message):
console = self._get_console(page_id)
console.log(message)

View File

@ -31,9 +31,6 @@ class ShellDbusService(dbus.service.Object):
def __show_console_idle(self):
self._shell.show_console()
def __log_idle(self, (module_id, message)):
self._shell.log(module_id, message)
@dbus.service.method('com.redhat.Sugar.Shell')
def show_people(self):
gobject.idle_add(self.__show_people_idle)
@ -44,7 +41,7 @@ class ShellDbusService(dbus.service.Object):
@dbus.service.method('com.redhat.Sugar.Shell')
def log(self, module_id, message):
gobject.idle_add(self.__log_idle, (module_id, message))
self._shell.log(module_id, message)
class Shell(gobject.GObject):
__gsignals__ = {
@ -57,13 +54,14 @@ class Shell(gobject.GObject):
self._screen = wnck.screen_get_default()
self._registry = registry
self._hosts = {}
self._console_windows = {}
def start(self):
session_bus = dbus.SessionBus()
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()
@ -118,23 +116,13 @@ class Shell(gobject.GObject):
activity = self.get_current_activity()
activity.show_people()
def get_console(self, module_id):
if not self._console_windows.has_key(module_id):
dialog = ConsoleWindow()
self._console_windows[module_id] = dialog
else:
dialog = self._console_windows[module_id]
return dialog
def show_console(self):
self._console.show()
activity = self.get_current_activity()
if activity:
module = self._registry.get_activity(activity.get_default_type())
console = self.get_console(module.get_id())
activity.show_dialog(console)
else:
console = self.get_console('Shell')
console.show()
self._console.set_page(module.get_id())
def join_activity(self, service):
info = self._registry.get_activity(service.get_type())
@ -164,8 +152,7 @@ class Shell(gobject.GObject):
return None
def log(self, module_id, message):
console = self.get_console(module_id)
console.log(message)
self._console.log(module_id, message)
def get_registry(self):
return self._registry

View File

@ -1,8 +1,14 @@
import sys
import logging
import traceback
from cStringIO import StringIO
import dbus
import gobject
__sugar_shell = None
__console_id = None
class Handler(logging.Handler):
def __init__(self, shell, console_id):
logging.Handler.__init__(self)
@ -13,8 +19,8 @@ class Handler(logging.Handler):
def _log(self):
for message in self._messages:
# FIXME use a single dbus call
self._shell.log(self._console_id, message)
self._messages = []
return False
def emit(self, record):
@ -22,6 +28,12 @@ class Handler(logging.Handler):
if len(self._messages) == 1:
gobject.idle_add(self._log)
def __exception_handler(typ, exc, tb):
trace = StringIO()
traceback.print_exception(typ, exc, tb, None, trace)
__sugar_shell.log(__console_id, trace.getvalue())
def start(console_id, shell = None):
root_logger = logging.getLogger('')
root_logger.setLevel(logging.DEBUG)
@ -32,3 +44,10 @@ def start(console_id, shell = None):
shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Shell')
root_logger.addHandler(Handler(shell, console_id))
global __sugar_shell
global __console_id
__sugar_shell = shell
__console_id = console_id
sys.excepthook = __exception_handler