More cleanups and some fixes

This commit is contained in:
Marco Pesenti Gritti 2006-07-12 14:02:29 +02:00
parent ca2b08f8b6
commit be806eb191
10 changed files with 78 additions and 105 deletions

27
shell/Emulator.py Normal file
View File

@ -0,0 +1,27 @@
import os
from Process import Process
class XephyrProcess(Process):
def __init__(self):
# FIXME How to pick a free display number?
self._display = 100
cmd = 'Xephyr :%d -ac -screen 640x480' % (self._display)
Process.__init__(self, cmd)
def get_name(self):
return 'Xephyr'
def start(self):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class Emulator:
"""The OLPC emulator"""
def __init__(self):
pass
def start(self):
process = XephyrProcess()
process.start()

View File

@ -2,12 +2,14 @@ bin_SCRIPTS = sugar
sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \
__init__.py \
__init__.py \
ActivityRegistry.py \
ConsoleLogger.py \
Owner.py \
Emulator.py \
Owner.py \
HomeWindow.py \
PresenceWindow.py \
Process.py \
Session.py \
Shell.py

16
shell/Process.py Normal file
View File

@ -0,0 +1,16 @@
import gobject
class Process:
def __init__(self, command):
self._pid = None
self._command = command
def get_name(self):
return self._command
def start(self):
args = self._command.split()
flags = gobject.SPAWN_SEARCH_PATH or gobject.SPAWN_STDERR_TO_DEV_NULL
result = gobject.spawn_async(args, flags=flags, standard_output=True)
self._pid = result[0]
self._stdout = result[2]

View File

@ -1,30 +1,9 @@
import os
import signal
import gobject
import gtk
import sugar.theme
from Shell import Shell
class Process:
def __init__(self, command):
self._pid = None
self._command = command
def get_name(self):
return self._command
def start(self):
splitted_cmd = self._command.split()
try:
self._pid = os.spawnvp(os.P_NOWAIT, splitted_cmd[0], splitted_cmd)
except Exception, e:
logging.error('Cannot run %s' % (self.get_name()))
def stop(self):
# FIXME Obviously we want to notify the processes to
# shut down rather then killing them down forcefully.
print 'Stopping %s (%d)' % (self.get_name(), self._pid)
os.kill(self._pid, signal.SIGTERM)
from Process import Process
class ActivityProcess(Process):
def __init__(self, module):
@ -36,17 +15,15 @@ class ActivityProcess(Process):
class DbusProcess(Process):
def __init__(self):
Process.__init__(self, "/bin/dbus-daemon --session --print-address")
Process.__init__(self, "dbus-daemon --session --print-address")
def get_name(self):
return 'Dbus'
def start(self):
args = self._command.split()
(self._pid, ign1, dbus_stdout, ign3) = gobject.spawn_async(
args, flags=gobject.SPAWN_STDERR_TO_DEV_NULL, standard_output=True)
dbus_file = os.fdopen(dbus_stdout)
Process.start(self)
dbus_file = os.fdopen(self._stdout)
addr = dbus_file.readline()
addr = addr.strip()
dbus_file.close()
@ -59,61 +36,29 @@ class MatchboxProcess(Process):
def get_name(self):
return 'Matchbox'
class XephyrProcess(Process):
def __init__(self):
# FIXME How to pick a free display number?
self._display = 100
cmd = 'Xephyr :%d -ac -screen 640x480' % (self._display)
Process.__init__(self, cmd)
def get_name(self):
return 'Xephyr'
def start(self):
Process.start(self)
os.environ['DISPLAY'] = ":%d" % (self._display)
class Session:
"""Takes care of running the shell and all the sugar processes"""
def __init__(self):
self._processes = []
sugar.theme.setup()
self._shell = Shell()
self._shell.connect('close', self._shell_close_cb)
self._shell.start()
def start(self):
"""Start the session"""
# FIXME We should not start this on the olpc
process = XephyrProcess()
self._processes.insert(0, process)
process.start()
process = DbusProcess()
self._processes.insert(0, process)
process.start()
process = MatchboxProcess()
self._processes.insert(0, process)
process.start()
registry = self._shell.get_registry()
for activity_module in registry.list_activities():
process = ActivityProcess(activity_module)
self._processes.insert(0, process)
process.start()
try:
import gtk
gtk.main()
except KeyboardInterrupt:
print 'Ctrl+C pressed, exiting...'
self.shutdown()
def _shell_close_cb(self, shell):
self.shutdown()
def shutdown(self):
for process in self._processes:
process.stop()

View File

@ -1,6 +1,5 @@
import dbus
import gtk
import gobject
import wnck
from sugar.LogWriter import LogWriter
@ -33,15 +32,8 @@ class ShellDbusService(dbus.service.Object):
def toggle_console(self):
self._shell.toggle_console()
class Shell(gobject.GObject):
__gsignals__ = {
'close': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([])),
}
class Shell:
def __init__(self):
gobject.GObject.__init__(self)
self._screen = wnck.screen_get_default()
def start(self):
@ -132,11 +124,3 @@ class Shell(gobject.GObject):
def get_registry(self):
return self._registry
if __name__ == "__main__":
shell = Shell()
shell.start()
try:
gtk.main()
except KeyboardInterrupt:
print 'Ctrl+c pressed, exiting...'

View File

@ -5,6 +5,8 @@ import os
import pwd
import random
from Emulator import Emulator
def add_to_python_path(path):
sys.path.insert(0, path)
if os.environ.has_key('PYTHONPATH'):
@ -13,6 +15,10 @@ def add_to_python_path(path):
else:
os.environ['PYTHONPATH'] = path
# FIXE Don't run the emulator on the OLPC
emulator = Emulator()
emulator.start()
i = 0
for arg in sys.argv:
if arg == '--test-user':

View File

@ -7,6 +7,7 @@ sugar_PYTHON = \
bots.py \
env.py \
keybindings.py \
theme.py \
util.py \
LogWriter.py

View File

@ -1,11 +0,0 @@
import pygtk
pygtk.require('2.0')
import gtk
settings = gtk.settings_get_default()
if settings.get_property('gtk-theme-name') != 'olpc':
settings.set_string_property('gtk-theme-name', 'olpc', '')
if settings.get_property('gtk-icon-theme-name') != 'olpc':
settings.set_string_property('gtk-icon-theme-name', 'olpc', '')

View File

@ -11,6 +11,7 @@ import gtk, gobject
from sugar.LogWriter import LogWriter
from sugar import keybindings
import sugar.util
import sugar.theme
SHELL_SERVICE_NAME = "caom.redhat.Sugar.Shell"
SHELL_SERVICE_PATH = "/com/redhat/Sugar/Shell"
@ -82,18 +83,10 @@ def create(activity_name, service = None, args = None):
else:
factory.create()
def _get_registry():
bus = dbus.SessionBus()
proxy_obj = bus.get_object("com.redhat.Sugar.ActivityRegistry",
"/com/redhat/Sugar/ActivityRegistry")
return dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityRegistry")
def list_activities():
registry = _get_registry()
return registry.list_activities()
def main(activity_name, activity_class):
"""Starts the activity main loop."""
sugar.theme.setup()
log_writer = LogWriter(activity_name)
log_writer.start()

10
sugar/theme.py Normal file
View File

@ -0,0 +1,10 @@
import gtk
def setup():
settings = gtk.settings_get_default()
if settings.get_property('gtk-theme-name') != 'olpc':
settings.set_string_property('gtk-theme-name', 'olpc', '')
if settings.get_property('gtk-icon-theme-name') != 'olpc':
settings.set_string_property('gtk-icon-theme-name', 'olpc', '')