From 8a9d0b657c0f0b01e854353fa4c7361b88db1583 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Tue, 16 May 2006 19:21:52 -0400 Subject: [PATCH] Add a gui console so I can see output in --- sugar/browser/browser.py | 14 ++++++----- sugar/chat/chat.py | 12 +++++---- sugar/shell/shell.py | 54 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/sugar/browser/browser.py b/sugar/browser/browser.py index 03a3f145..f311ba14 100755 --- a/sugar/browser/browser.py +++ b/sugar/browser/browser.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import sys + import dbus import dbus.service import dbus.glib @@ -10,6 +12,7 @@ import gtk import geckoembed +from sugar.session.LogWriter import LogWriter from sugar.shell import activity from sugar.p2p.Group import LocalGroup import sugar.env @@ -315,9 +318,8 @@ class BrowserShell(dbus.service.Object): self.__browsers.append(browser) browser.activity_connect_to_shell() -def main(): - BrowserShell.get_instance().open_web_activity() - gtk.main() - -if __name__ == "__main__": - main() +sys.stdout = LogWriter("Web Browser") +sys.stderr = LogWriter("Web Browser") + +BrowserShell.get_instance().open_web_activity() +gtk.main() diff --git a/sugar/chat/chat.py b/sugar/chat/chat.py index 4d595f71..0ed0e1ce 100755 --- a/sugar/chat/chat.py +++ b/sugar/chat/chat.py @@ -1,6 +1,8 @@ #!/usr/bin/python -t # -*- tab-width: 4; indent-tabs-mode: t -*- +import sys + import dbus import dbus.service import dbus.glib @@ -15,6 +17,7 @@ from sugar.p2p.Group import LocalGroup from sugar.p2p.Service import Service from sugar.p2p.StreamReader import StreamReader from sugar.p2p.StreamWriter import StreamWriter +from sugar.session.LogWriter import LogWriter import sugar.env import richtext @@ -396,9 +399,8 @@ class ChatShell(dbus.service.Object): def send_message(self, message): self._group_chat.send_message(message) -def main(): - ChatShell.get_instance().open_group_chat() - gtk.main() +sys.stdout = LogWriter("Chat") +sys.stderr = LogWriter("Chat") -if __name__ == "__main__": - main() +ChatShell.get_instance().open_group_chat() +gtk.main() diff --git a/sugar/shell/shell.py b/sugar/shell/shell.py index a72a864f..4d16a45d 100755 --- a/sugar/shell/shell.py +++ b/sugar/shell/shell.py @@ -1,6 +1,8 @@ #!/usr/bin/python # -*- tab-width: 4; indent-tabs-mode: t -*- +import sys + import dbus import dbus.service import dbus.glib @@ -9,6 +11,8 @@ pygtk.require('2.0') import gtk import pango +from sugar.session.LogWriter import LogWriter + activity_counter = 0 class ActivityHost(dbus.service.Object): @@ -287,10 +291,60 @@ class ActivityContainer(dbus.service.Object): print " %d: owner=%s activity_object_name=%s" % (i, owner, activity.dbus_object_name) i += 1 +class ConsoleLogger(dbus.service.Object): + def __init__(self): + session_bus = dbus.SessionBus() + bus_name = dbus.service.BusName('com.redhat.Sugar.Logger', bus=session_bus) + object_path = '/com/redhat/Sugar/Logger' + dbus.service.Object.__init__(self, bus_name, object_path) + + self._window = gtk.Window() + self._window.set_title("Console") + self._window.set_default_size(640, 480) + self._window.connect("delete_event", lambda w, e: w.hide_on_delete()) + + self._nb = gtk.Notebook() + self._window.add(self._nb) + self._nb.show() + + self._consoles = {} + + def set_parent_window(self, window): + window.connect("key-press-event", self.__key_press_event_cb) + self._window.connect("key-press-event", self.__key_press_event_cb) + + def __key_press_event_cb(self, window, event): + if event.keyval == gtk.keysyms.d and \ + event.state & gtk.gdk.CONTROL_MASK: + if self._window.get_property('visible'): + self._window.hide() + else: + self._window.show() + + @dbus.service.method('com.redhat.Sugar.Logger') + def log(self, application, message): + if self._consoles.has_key(application): + console = self._consoles[application] + else: + console = gtk.TextView() + self._nb.append_page(console, gtk.Label(application)) + console.show() + self._consoles[application] = console + + buf = console.get_buffer() + buf.insert(buf.get_end_iter(), message) def main(): + console = ConsoleLogger() + session_bus = dbus.SessionBus() service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus) activityContainer = ActivityContainer(service, session_bus) activityContainer.show() + + console.set_parent_window(activityContainer.window) + +if __name__ == "__main__": + main() + gtk.main()