2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-08-11 17:05:06 +02:00
|
|
|
import logging
|
|
|
|
|
2006-07-20 12:13:47 +02:00
|
|
|
import gtk
|
2006-08-12 16:19:47 +02:00
|
|
|
import dbus
|
|
|
|
import dbus.service
|
2006-07-20 12:13:47 +02:00
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
class Console(gtk.ScrolledWindow):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.ScrolledWindow.__init__(self)
|
2006-08-11 17:05:06 +02:00
|
|
|
|
|
|
|
self._show_debug = False
|
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
self.set_policy(gtk.POLICY_AUTOMATIC,
|
|
|
|
gtk.POLICY_AUTOMATIC)
|
2006-08-11 17:05:06 +02:00
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
self._textview = gtk.TextView()
|
|
|
|
self._textview.set_wrap_mode(gtk.WRAP_WORD)
|
|
|
|
self.add(self._textview)
|
|
|
|
self._textview.show()
|
|
|
|
|
|
|
|
buf = self._textview.get_buffer()
|
2006-08-11 17:05:06 +02:00
|
|
|
self._debug_tag = buf.create_tag("debug")
|
|
|
|
self._debug_tag.set_property("invisible", True)
|
|
|
|
|
|
|
|
def get_show_debug(self):
|
|
|
|
return self._show_debug
|
|
|
|
|
|
|
|
def set_show_debug(self, show_debug):
|
|
|
|
self._show_debug = show_debug
|
|
|
|
self._debug_tag.set_property("invisible", not show_debug)
|
|
|
|
|
|
|
|
def log(self, level, message):
|
|
|
|
msg = message + '\n'
|
|
|
|
buf = self._textview.get_buffer()
|
|
|
|
it = buf.get_end_iter()
|
|
|
|
|
|
|
|
if level == logging.DEBUG:
|
|
|
|
buf.insert_with_tags(it, msg, self._debug_tag)
|
|
|
|
else:
|
|
|
|
buf.insert(it, msg)
|
2006-08-12 16:19:47 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-08-14 12:18:58 +02:00
|
|
|
@dbus.service.method('org.laptop.Sugar.Console',
|
|
|
|
in_signature="saias", out_signature="")
|
|
|
|
def log(self, module_id, levels, messages):
|
2006-08-16 00:30:50 +02:00
|
|
|
self._console.log(module_id, levels, messages)
|
2006-08-12 16:19:47 +02:00
|
|
|
|
2006-07-20 12:13:47 +02:00
|
|
|
class ConsoleWindow(gtk.Window):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Window.__init__(self)
|
|
|
|
|
|
|
|
self.set_default_size(620, 440)
|
|
|
|
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
self.set_title("Console")
|
|
|
|
self.connect("delete_event", lambda w, e: w.hide_on_delete())
|
|
|
|
|
2006-08-11 17:05:06 +02:00
|
|
|
vbox = gtk.VBox()
|
|
|
|
|
|
|
|
toolbar = gtk.Toolbar()
|
|
|
|
|
|
|
|
self._debug_toggle = gtk.ToggleToolButton()
|
|
|
|
self._debug_toggle.connect('toggled', self.__debug_toggled_cb)
|
|
|
|
self._debug_toggle.set_label('Debug')
|
|
|
|
toolbar.insert(self._debug_toggle, -1)
|
|
|
|
self._debug_toggle.show()
|
|
|
|
|
2006-08-13 02:57:12 +02:00
|
|
|
self._ignore_toggle = False
|
|
|
|
|
2006-08-11 17:05:06 +02:00
|
|
|
vbox.pack_start(toolbar, False)
|
|
|
|
toolbar.show()
|
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
self._nb = gtk.Notebook()
|
2006-08-11 17:05:06 +02:00
|
|
|
self._nb.connect('switch-page', self.__page_changed_cb)
|
|
|
|
vbox.pack_start(self._nb)
|
2006-08-11 15:21:11 +02:00
|
|
|
self._nb.show()
|
2006-07-20 12:13:47 +02:00
|
|
|
|
2006-08-11 17:05:06 +02:00
|
|
|
self.add(vbox)
|
|
|
|
vbox.show()
|
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
self._consoles = {}
|
|
|
|
|
2006-08-12 16:19:47 +02:00
|
|
|
session_bus = dbus.SessionBus()
|
|
|
|
bus_name = dbus.service.BusName('org.laptop.Sugar.Console', bus=session_bus)
|
|
|
|
ConsoleDbusService(self, bus_name)
|
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
def _add_console(self, page_id):
|
|
|
|
console = Console()
|
|
|
|
page = self._nb.append_page(console, gtk.Label(page_id))
|
|
|
|
console.show()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2006-08-11 17:05:06 +02:00
|
|
|
def __debug_toggled_cb(self, button):
|
2006-08-13 02:57:12 +02:00
|
|
|
if not self._ignore_toggle:
|
|
|
|
console = self._nb.get_nth_page(self._nb.get_current_page())
|
2006-08-17 20:49:04 +02:00
|
|
|
if console:
|
|
|
|
console.set_show_debug(button.get_active())
|
2006-08-11 17:05:06 +02:00
|
|
|
|
|
|
|
def __page_changed_cb(self, notebook, page, page_num):
|
|
|
|
console = self._nb.get_nth_page(page_num)
|
2006-08-13 02:57:12 +02:00
|
|
|
|
|
|
|
self._ignore_toggle = True
|
2006-08-11 17:05:06 +02:00
|
|
|
self._debug_toggle.set_active(console.get_show_debug())
|
2006-08-13 02:57:12 +02:00
|
|
|
self._ignore_toggle = False
|
2006-08-11 17:05:06 +02:00
|
|
|
|
2006-08-11 15:21:11 +02:00
|
|
|
def set_page(self, page_id):
|
|
|
|
page = self._nb.page_num(self._consoles[page_id])
|
|
|
|
self._nb.set_current_page(page)
|
|
|
|
|
2006-08-16 00:30:50 +02:00
|
|
|
def log(self, page_id, levels, messages):
|
2006-08-11 15:21:11 +02:00
|
|
|
console = self._get_console(page_id)
|
2006-08-16 00:30:50 +02:00
|
|
|
i = 0
|
|
|
|
while i < len(levels):
|
|
|
|
console.log(levels[i], messages[i])
|
|
|
|
i += 1
|