Make the console contextual to the activity and use the

window manager to activate it.
This commit is contained in:
Marco Pesenti Gritti 2006-07-20 12:13:47 +02:00
parent 87cb115aa0
commit d6ec6db880
11 changed files with 80 additions and 95 deletions

View File

@ -14,6 +14,7 @@ class ActivityHost:
self._activity = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Activity')
self._id = self._activity.get_id()
self._default_type = self._activity.get_default_type()
self._window = gtk.gdk.window_foreign_new(xid)
def get_id(self):
@ -25,6 +26,9 @@ class ActivityHost:
def get_shared(self):
return self._activity.get_shared()
def get_default_type(self):
return self._default_type
def show_dialog(self, dialog):
dialog.show()
dialog.window.set_transient_for(self._window)

View File

@ -1,49 +0,0 @@
import gtk
import dbus.service
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.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 get_window(self):
return self._window
def _create_console(self, application):
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
console = gtk.TextView()
console.set_wrap_mode(gtk.WRAP_WORD)
sw.add(console)
console.show()
self._nb.append_page(sw, gtk.Label(application))
sw.show()
return console
@dbus.service.method('com.redhat.Sugar.Logger')
def log(self, application, message):
if self._consoles.has_key(application):
console = self._consoles[application]
else:
console = self._create_console(application)
self._consoles[application] = console
buf = console.get_buffer()
buf.insert(buf.get_end_iter(), message)

26
shell/ConsoleWindow.py Normal file
View File

@ -0,0 +1,26 @@
import gtk
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())
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
self._console = gtk.TextView()
self._console.set_wrap_mode(gtk.WRAP_WORD)
sw.add(self._console)
self._console.show()
self.add(sw)
sw.show()
def log(self, message):
buf = self._console.get_buffer()
buf.insert(buf.get_end_iter(), message)

View File

@ -9,6 +9,7 @@ class PeopleWindow(gtk.Window):
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.set_default_size(620, 440)
self.connect("delete_event", lambda w, e: w.hide_on_delete())
hbox = gtk.HBox(False, 12)
hbox.set_border_width(12)

View File

@ -9,9 +9,9 @@ from sugar.LogWriter import LogWriter
from ConsoleLogger import ConsoleLogger
from ActivityRegistry import ActivityRegistry
from HomeWindow import HomeWindow
from sugar import keybindings
from sugar import env
from PeopleWindow import PeopleWindow
from ConsoleWindow import ConsoleWindow
from Owner import ShellOwner
from PresenceService import PresenceService
from ActivityHost import ActivityHost
@ -24,22 +24,29 @@ class ShellDbusService(dbus.service.Object):
def __show_people_idle(self):
self._shell.show_people()
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)
@dbus.service.method('com.redhat.Sugar.Shell')
def toggle_console(self):
self._shell.toggle_console()
def show_console(self):
gobject.idle_add(self.__show_console_idle)
@dbus.service.method('com.redhat.Sugar.Shell')
def log(self, module_id, message):
gobject.idle_add(self.__log_idle, (module_id, message))
class Shell:
def __init__(self):
self._screen = wnck.screen_get_default()
def start(self):
self._console = ConsoleLogger()
keybindings.setup_global_keys(self._console.get_window(), self)
log_writer = LogWriter("Shell", False)
log_writer.start()
@ -55,16 +62,10 @@ class Shell:
self._registry.scan_directory(os.path.join(env.get_user_dir(), 'activities'))
self._home_window = HomeWindow(self)
keybindings.setup_global_keys(self._home_window, self)
self._home_window.show()
self._people_windows = {}
def _toggle_window_visibility(self, window):
if window.get_property('visible'):
window.hide()
else:
window.show()
self._console_windows = {}
def get_current_activity(self):
window = self._screen.get_active_window()
@ -73,25 +74,34 @@ class Shell:
else:
return None
def __people_dialog_delete_cb(self, window, event):
window.hide()
return True
def show_people(self):
activity = self.get_current_activity()
if activity:
if not self._people_windows.has_key(activity.get_id()):
dialog = PeopleWindow(self, activity)
dialog.connect('delete-event', self.__people_dialog_delete_cb)
keybindings.setup_global_keys(dialog, self)
self._people_windows[activity.get_id()] = dialog
else:
dialog = self._people_windows[activity.get_id()]
activity.show_dialog(dialog)
def toggle_console(self):
self._toggle_window_visibility(self._console.get_window())
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):
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)
def log(self, module_id, message):
console = self.get_console(module_id)
console.log(message)
def get_registry(self):
return self._registry

View File

@ -7,4 +7,5 @@
<Alt>c=close
f1=desktop
f2=!sugar-people
f3=!sugar-console
f4=!sugar-activity org.sugar.Terminal

8
shell/sugar-console Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/python
import dbus
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')
shell.show_console()

View File

@ -6,5 +6,3 @@ 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')
shell.show_people()

View File

@ -11,8 +11,8 @@ class LogWriter:
self._use_console = use_console
bus = dbus.SessionBus()
proxy_obj = bus.get_object('com.redhat.Sugar.Logger', '/com/redhat/Sugar/Logger')
self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Logger')
proxy_obj = bus.get_object('com.redhat.Sugar.Shell', '/com/redhat/Sugar/Shell')
self._logger = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Shell')
def start(self):
if self._use_console:

View File

@ -8,7 +8,6 @@ import gtk
import gobject
from sugar.LogWriter import LogWriter
from sugar import keybindings
import sugar.util
ACTIVITY_SERVICE_NAME = "com.redhat.Sugar.Activity"
@ -129,6 +128,12 @@ class ActivityDbusService(dbus.service.Object):
"""Get the activity identifier"""
return self._activity.get_id()
@dbus.service.method(ACTIVITY_SERVICE_NAME)
def get_default_type(self):
"""Get the activity default type"""
return self._activity.get_default_type()
@dbus.service.method(ACTIVITY_SERVICE_NAME)
def get_shared(self):
"""Get the activity identifier"""
@ -152,8 +157,6 @@ class Activity(gtk.Window):
self._activity_object = None
self._default_type = None
keybindings.setup_global_keys(self)
self.connect('realize', self.__realize)
self.present()

View File

@ -1,17 +0,0 @@
import gtk
import dbus
# FIXME These should be handled by the wm, but it's incovenient
# to do that with matchbox at the moment
def setup_global_keys(window, shell = None):
if not shell:
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')
window.connect("key-press-event", __key_press_event_cb, shell)
def __key_press_event_cb(window, event, shell):
if event.keyval == gtk.keysyms.F3:
shell.toggle_console()