From 6eb7117c25bfea1c0970d67eff2e36f744aa3049 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 13 Aug 2006 02:57:12 +0200 Subject: [PATCH] Getting presence service logging to work. Don't lose debug state when switching tab. --- shell/ConsoleWindow.py | 10 ++++++++-- shell/session/Session.py | 11 +++++------ shell/sugar-presence-service | 2 +- sugar/logger.py | 23 +++++++++++++---------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/shell/ConsoleWindow.py b/shell/ConsoleWindow.py index be2e4a50..19866969 100644 --- a/shell/ConsoleWindow.py +++ b/shell/ConsoleWindow.py @@ -67,6 +67,8 @@ class ConsoleWindow(gtk.Window): toolbar.insert(self._debug_toggle, -1) self._debug_toggle.show() + self._ignore_toggle = False + vbox.pack_start(toolbar, False) toolbar.show() @@ -101,12 +103,16 @@ class ConsoleWindow(gtk.Window): return console def __debug_toggled_cb(self, button): - console = self._nb.get_nth_page(self._nb.get_current_page()) - console.set_show_debug(button.get_active()) + if not self._ignore_toggle: + console = self._nb.get_nth_page(self._nb.get_current_page()) + console.set_show_debug(button.get_active()) def __page_changed_cb(self, notebook, page, page_num): console = self._nb.get_nth_page(page_num) + + self._ignore_toggle = True self._debug_toggle.set_active(console.get_show_debug()) + self._ignore_toggle = False def set_page(self, page_id): page = self._nb.page_num(self._consoles[page_id]) diff --git a/shell/session/Session.py b/shell/session/Session.py index 9815897c..752e6eed 100644 --- a/shell/session/Session.py +++ b/shell/session/Session.py @@ -16,7 +16,7 @@ import sugar.env class DbusProcess(Process): def __init__(self): config = sugar.env.get_dbus_config() - cmd = "dbus-launch --exit-with-session --config-file %s" % config + cmd = "dbus-daemon --print-address --config-file %s" % config Process.__init__(self, cmd) def get_name(self): @@ -25,8 +25,7 @@ class DbusProcess(Process): def start(self): Process.start(self, True) dbus_file = os.fdopen(self._stdout) - regexp = re.compile('DBUS_SESSION_BUS_ADDRESS=\'(.*)\'\;') - addr = regexp.match(dbus_file.readline()).group(1) + addr = dbus_file.readline().strip() dbus_file.close() os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr @@ -54,14 +53,14 @@ class Session: process = DbusProcess() process.start() - console = ConsoleWindow() - sugar.logger.start('Shell', console) - PresenceService.start() process = MatchboxProcess() process.start() + console = ConsoleWindow() + sugar.logger.start('Shell', console) + shell = Shell(self._registry) shell.set_console(console) shell.start() diff --git a/shell/sugar-presence-service b/shell/sugar-presence-service index 202ce139..fda0d12c 100755 --- a/shell/sugar-presence-service +++ b/shell/sugar-presence-service @@ -4,7 +4,7 @@ import logging from PresenceService import PresenceService import sugar.logger -#sugar.logger.start('PresenceService') +sugar.logger.start('PresenceService') logging.info('Starting presence service') diff --git a/sugar/logger.py b/sugar/logger.py index 8c4ecff8..3ce4b09a 100644 --- a/sugar/logger.py +++ b/sugar/logger.py @@ -4,6 +4,7 @@ import traceback from cStringIO import StringIO import dbus +import dbus.dbus_bindings import gobject __console = None @@ -16,33 +17,35 @@ class Handler(logging.Handler): self._console_id = console_id self._console = console self._records = [] - self._console_started = False + self._idle_id = 0 bus = dbus.SessionBus() + self._console_started = dbus.dbus_bindings.bus_name_has_owner( + bus._connection, 'org.laptop.Sugar.Console') bus.add_signal_receiver(self.__name_owner_changed, dbus_interface = "org.freedesktop.DBus", signal_name = "NameOwnerChanged") def __name_owner_changed(self, service_name, old_name, new_name): - if new_name != None: - self._console_started = True - else: - self._console_started = False + if service_name == 'org.laptop.Sugar.Console': + if new_name != None: + self._console_started = True + self._idle_id = gobject.idle_add(self._log) + else: + self._console_started = False def _log(self): - if not self._console_started: - return True - for record in self._records: self._console.log(record.levelno, self._console_id, record.msg) self._records = [] + self._idle_id = 0 return False def emit(self, record): self._records.append(record) - if len(self._records) == 1: - gobject.idle_add(self._log) + if self._console_started and self._idle_id == 0: + self._idle_id = gobject.idle_add(self._log) def __exception_handler(typ, exc, tb): trace = StringIO()