Rework the console to use autoactivation, move it in services/

This commit is contained in:
Marco Pesenti Gritti 2007-01-08 18:06:59 +01:00
parent 764eee81e5
commit cae78d7041
54 changed files with 83 additions and 98 deletions

1
.gitignore vendored
View File

@ -53,3 +53,4 @@ lib/src/sugar-marshal.h
lib/src/stamp-sugar-marshal.c lib/src/stamp-sugar-marshal.c
lib/src/stamp-sugar-marshal.h lib/src/stamp-sugar-marshal.h
services/clipboard/org.laptop.Clipboard.service services/clipboard/org.laptop.Clipboard.service
services/console/org.laptop.sugar.Console.service

View File

@ -68,19 +68,19 @@ shell/view/Makefile
shell/view/home/Makefile shell/view/home/Makefile
shell/view/frame/Makefile shell/view/frame/Makefile
shell/model/Makefile shell/model/Makefile
shell/console/lib/Makefile services/console/lib/Makefile
shell/console/lib/procmem/Makefile services/console/lib/procmem/Makefile
shell/console/Makefile services/console/Makefile
shell/console/interface/Makefile services/console/interface/Makefile
shell/console/interface/xo/Makefile services/console/interface/xo/Makefile
shell/console/interface/memphis/plugins/clean_size/Makefile services/console/interface/memphis/plugins/clean_size/Makefile
shell/console/interface/memphis/plugins/dirty_size/Makefile services/console/interface/memphis/plugins/dirty_size/Makefile
shell/console/interface/memphis/plugins/Makefile services/console/interface/memphis/plugins/Makefile
shell/console/interface/memphis/plugins/memphis_init/Makefile services/console/interface/memphis/plugins/memphis_init/Makefile
shell/console/interface/memphis/plugins/cpu/Makefile services/console/interface/memphis/plugins/cpu/Makefile
shell/console/interface/memphis/Makefile services/console/interface/memphis/Makefile
shell/console/interface/logviewer/Makefile services/console/interface/logviewer/Makefile
shell/console/interface/terminal/Makefile services/console/interface/terminal/Makefile
sugar/Makefile sugar/Makefile
sugar/__installed__.py sugar/__installed__.py
sugar/activity/Makefile sugar/activity/Makefile

View File

@ -1 +1 @@
SUBDIRS = presence nm clipboard datastore SUBDIRS = presence nm clipboard datastore console

View File

@ -0,0 +1,17 @@
SUBDIRS = interface lib
servicedir = $(datadir)/dbus-1/services
service_in_files = org.laptop.sugar.Console.service.in
service_DATA = $(service_in_files:.service.in=.service)
$(service_DATA): $(service_in_files) Makefile
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
sugardir = $(pkgdatadir)/shell/console
sugar_PYTHON = \
__init__.py \
console.py
bin_SCRIPTS = sugar-console
DISTCLEANFILES = $(service_DATA)

View File

@ -17,6 +17,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import dbus import dbus
import dbus.glib
import dbus.service import dbus.service
import os import os
import sys import sys
@ -26,12 +27,9 @@ import gobject
sys.path.append(os.path.dirname(__file__) + '/lib') sys.path.append(os.path.dirname(__file__) + '/lib')
sys.path.append(os.path.dirname(__file__) + '/interface') sys.path.append(os.path.dirname(__file__) + '/interface')
DBUS_BUS = 'org.freedesktop.DBus' CONSOLE_BUS = 'org.laptop.sugar.Console'
DBUS_PATH = '/org/freedesktop/DBus' CONSOLE_PATH = '/org/laptop/sugar/Console'
CONSOLE_IFACE = 'org.laptop.sugar.Console'
CONSOLE_BUS = 'org.laptop.Sugar.DeveloperConsole'
CONSOLE_PATH = '/org/laptop/Sugar/DeveloperConsole'
CONSOLE_IFACE = 'org.laptop.Sugar.DeveloperConsole'
class Console: class Console:
@ -40,33 +38,16 @@ class Console:
# Main Window # Main Window
self.window = gtk.Window() self.window = gtk.Window()
self.window.set_title('Developer console') self.window.set_title('Developer console')
self.window.connect("delete-event", self._minimize_main_window) self.window.connect("delete-event", self._delete_event_cb)
self.default_width = gtk.gdk.screen_width() * 95 / 100 self.default_width = gtk.gdk.screen_width() * 95 / 100
self.default_height = gtk.gdk.screen_height() * 95 / 100 self.default_height = gtk.gdk.screen_height() * 95 / 100
self.default_mini_width = 150
self.default_mini_height = 30
self.window.set_default_size(self.default_width, self.default_height) self.window.set_default_size(self.default_width, self.default_height)
self.window.realize() self.window.realize()
self.window.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
# Minimize Window
self.mini_fixed = gtk.Fixed()
# Minimize buttons
button_restore = gtk.Button('Restore')
button_restore.connect("clicked", self._restore_window)
button_quit = gtk.Button('Quit')
button_quit.connect("clicked", gtk.main_quit)
mini_hbox = gtk.HBox()
mini_hbox.pack_start(button_restore, True, True, 0)
mini_hbox.pack_start(button_quit, True, True, 0)
self.mini_fixed.add(mini_hbox)
# Notebook # Notebook
self.notebook = gtk.Notebook() self.notebook = gtk.Notebook()
@ -77,14 +58,10 @@ class Console:
main_hbox = gtk.HBox() main_hbox = gtk.HBox()
main_hbox.pack_start(self.notebook, True, True, 0) main_hbox.pack_start(self.notebook, True, True, 0)
main_hbox.pack_start(self.mini_fixed, True, True, 0)
main_hbox.show() main_hbox.show()
self.notebook.show() self.notebook.show()
self.window.add(main_hbox) self.window.add(main_hbox)
self.window.show()
self.mini_fixed.hide()
def _load_interface(self, interface, label): def _load_interface(self, interface, label):
mod = __import__(interface) mod = __import__(interface)
@ -93,36 +70,21 @@ class Console:
self.notebook.append_page(widget, gtk.Label(label)) self.notebook.append_page(widget, gtk.Label(label))
def _delete_event_cb(self, window, gdkevent):
def _restore_window(self, button): window.hide()
self.mini_fixed.hide_all()
self.window.resize(self.default_mini_width, self.default_mini_height)
self.notebook.show_all()
def _minimize_main_window(self, window, gdkevent):
self.notebook.hide_all()
window.resize(self.default_mini_width, self.default_mini_height)
self.mini_fixed.show_all()
return True return True
# We're using a DBUS-Service to avoid open devconsole more than one time class Service(dbus.service.Object):
class Init_Service(dbus.service.Object):
def __init__(self, bus, object_path=CONSOLE_PATH): def __init__(self, bus, object_path=CONSOLE_PATH):
dbus.service.Object.__init__(self, bus, object_path) dbus.service.Object.__init__(self, bus, object_path)
CS = Console() self._console = Console()
@dbus.service.method(CONSOLE_IFACE)
def show(self):
self._console.window.present()
bus = dbus.SessionBus() bus = dbus.SessionBus()
obj = bus.get_object(DBUS_BUS, DBUS_PATH) name = dbus.service.BusName(CONSOLE_BUS, bus)
obj = Service(name)
dbus_iface = dbus.Interface(obj, DBUS_BUS)
services = dbus_iface.ListNames()
# A temporal way to check if the service is running
if not CONSOLE_BUS in services:
name = dbus.service.BusName(CONSOLE_BUS, bus)
obj = Init_Service(name)
gtk.main()
else:
sys.exit(1)
gtk.main()

View File

@ -0,0 +1,4 @@
[D-BUS Service]
Name = org.laptop.Console
Exec = @bindir@/sugar-console

11
services/console/sugar-console Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import os, sys
from sugar import env
sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/console'))
import console

View File

@ -1,11 +1,9 @@
SUBDIRS = data model view console SUBDIRS = data model view
bin_SCRIPTS = \ bin_SCRIPTS = \
sugar-activity \ sugar-activity \
sugar-activity-factory \ sugar-activity-factory \
sugar-shell \ sugar-shell
sugar-shutdown \
sugar-devel-console
sugardir = $(pkgdatadir)/shell sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \ sugar_PYTHON = \

View File

@ -1,6 +0,0 @@
SUBDIRS = interface lib
sugardir = $(pkgdatadir)/shell/console
sugar_PYTHON = \
__init__.py \
console.py

View File

@ -6,6 +6,4 @@
<Alt>p=prev <Alt>p=prev
<Alt>c=close <Alt>c=close
<Alt><Shift>F12=!sugar-devel-console
<Alt>q=!sugar-emulator-shutdown <Alt>q=!sugar-emulator-shutdown
<Alt><Shift>Escape=!sugar-shutdown

View File

@ -1,12 +0,0 @@
#!/usr/bin/env python
# Sugar developer console launcher
import pygtk
pygtk.require('2.0')
import os, sys
from sugar import env
sys.path.insert(0, os.path.join(env.get_data_dir(), 'shell'))
import console.console

View File

@ -1,4 +0,0 @@
#!/bin/sh
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

View File

@ -94,6 +94,8 @@ class Shell(gobject.GObject):
self._key_grabber.grab('F12') self._key_grabber.grab('F12')
self._key_grabber.grab('<alt>F5') self._key_grabber.grab('<alt>F5')
self._key_grabber.grab('<alt>F8') self._key_grabber.grab('<alt>F8')
self._key_grabber.grab('<alt>=')
self._key_grabber.grab('<alt>0')
self._key_grabber.grab('0xDC') # Camera key self._key_grabber.grab('0xDC') # Camera key
self._key_grabber.grab('0xE0') # Overlay key self._key_grabber.grab('0xE0') # Overlay key
@ -135,6 +137,8 @@ class Shell(gobject.GObject):
self._hw_manager.set_display_mode(HardwareManager.COLOR_MODE) self._hw_manager.set_display_mode(HardwareManager.COLOR_MODE)
elif key == '<alt>F8': elif key == '<alt>F8':
self._hw_manager.set_display_mode(HardwareManager.B_AND_W_MODE) self._hw_manager.set_display_mode(HardwareManager.B_AND_W_MODE)
elif key == '<alt>=' or key == '<alt>0':
self._show_console()
elif key == '<shft><alt>F9': elif key == '<shft><alt>F9':
self._frame.notify_key_press() self._frame.notify_key_press()
elif key == '<shft><alt>F10': elif key == '<shft><alt>F10':
@ -154,6 +158,13 @@ class Shell(gobject.GObject):
box = self._home_window.get_home_box() box = self._home_window.get_home_box()
box.grab_and_rotate() box.grab_and_rotate()
def _show_console(self):
bus = dbus.SessionBus()
proxy = bus.get_object('org.laptop.sugar.Console',
'/org/laptop/sugar/Console')
mgr = dbus.Interface(proxy, 'org.laptop.sugar.Console')
mgr.show()
def _shutdown(self): def _shutdown(self):
bus = dbus.SystemBus() bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.Hal', proxy = bus.get_object('org.freedesktop.Hal',

View File

@ -63,6 +63,11 @@ if sourcedir:
util.write_service('org.laptop.sugar.DataStore', bin, util.write_service('org.laptop.sugar.DataStore', bin,
env.get_user_service_dir()) env.get_user_service_dir())
bin = os.path.join(sourcedir,
'services/console/sugar-console')
util.write_service('org.laptop.sugar.Console', bin,
env.get_user_service_dir())
from sugar.emulator import Emulator from sugar.emulator import Emulator
program = 'sugar-shell' program = 'sugar-shell'