Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-06-20 02:39:57 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-06-20 02:39:57 (GMT)
commit8bcdb8f3dd25ab31da3ce4c76c477c3017f2f712 (patch)
tree466f1a30970278ae58ac298c2cfb6d9e59187d94 /sugar
parent5485a4f958d3bb9d7a6671b966fb55559dd9580c (diff)
Implement session shutdown. For now we are forcefully
killing activities. We will need to implement some sort of shutdown notification system but... for now this works.
Diffstat (limited to 'sugar')
-rw-r--r--sugar/session/session.py76
-rwxr-xr-xsugar/shell/shell.py49
-rwxr-xr-xsugar/sugar3
3 files changed, 80 insertions, 48 deletions
diff --git a/sugar/session/session.py b/sugar/session/session.py
index 76bd9a3..ea232c0 100644
--- a/sugar/session/session.py
+++ b/sugar/session/session.py
@@ -1,41 +1,59 @@
import os
+import signal
from ConfigParser import ConfigParser
import pygtk
pygtk.require('2.0')
import gtk
-from sugar.shell import shell
+from sugar.shell.shell import Shell
from sugar import env
-def start():
- shell.main()
+class Session:
+ def __init__(self):
+ self._activity_processes = {}
- activities = []
-
- activities_dirs = []
-
- for data_dir in env.get_data_dirs():
- act_dir = os.path.join(data_dir, env.get_activities_dir())
- activities_dirs.append(act_dir)
+ def start(self):
+ shell = Shell()
+ shell.connect('close', self._shell_close_cb)
+ shell.start()
+
+ activities = []
+ activities_dirs = []
+
+ for data_dir in env.get_data_dirs():
+ act_dir = os.path.join(data_dir, env.get_activities_dir())
+ activities_dirs.append(act_dir)
+
+ activities_dirs.append(os.path.join(env.get_user_dir(), 'activities'))
+
+ for activities_dir in activities_dirs:
+ if os.path.isdir(activities_dir):
+ for filename in os.listdir(activities_dir):
+ if filename.endswith(".activity"):
+ path = os.path.join(activities_dir, filename)
+ cp = ConfigParser()
+ cp.read([path])
+ python_class = cp.get('Activity', "python_class")
+ activities.append(python_class)
+
+ for activity in activities:
+ args = [ 'python', '-m', activity ]
+ pid = os.spawnvp(os.P_NOWAIT, 'python', args)
+ self._activity_processes[activity] = pid
- activities_dirs.append(os.path.join(env.get_user_dir(), 'activities'))
+ try:
+ gtk.main()
+ except KeyboardInterrupt:
+ print 'Ctrl+C pressed, exiting...'
+ self.shutdown()
+
+ def _shell_close_cb(self, shell):
+ self.shutdown()
- for activities_dir in activities_dirs:
- if os.path.isdir(activities_dir):
- for filename in os.listdir(activities_dir):
- if filename.endswith(".activity"):
- path = os.path.join(activities_dir, filename)
- cp = ConfigParser()
- cp.read([path])
- python_class = cp.get('Activity', "python_class")
- activities.append(python_class)
-
- for activity in activities:
- args = [ 'python', '-m', activity ]
- os.spawnvp(os.P_NOWAIT, 'python', args)
-
- try:
- gtk.main()
- except KeyboardInterrupt:
- print 'Ctrl+C pressed, exiting...'
+ def shutdown(self):
+ # FIXME Obviously we want to notify the activities to
+ # shutt down rather then killing them down forcefully.
+ for name in self._activity_processes.keys():
+ print 'Shutting down %s' % (name)
+ os.kill(self._activity_processes[name], signal.SIGTERM)
diff --git a/sugar/shell/shell.py b/sugar/shell/shell.py
index 2b1f6a3..3e5450c 100755
--- a/sugar/shell/shell.py
+++ b/sugar/shell/shell.py
@@ -472,31 +472,44 @@ class ConsoleLogger(dbus.service.Object):
buf = console.get_buffer()
buf.insert(buf.get_end_iter(), message)
-def main():
- console = ConsoleLogger()
+class Shell(gobject.GObject):
+ __gsignals__ = {
+ 'close': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([])),
+ }
- log_writer = LogWriter("Shell", False)
- log_writer.start()
+ def __init__(self):
+ gobject.GObject.__init__(self)
- session_bus = dbus.SessionBus()
- service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
+ def start(self):
+ console = ConsoleLogger()
- activity_container = ActivityContainer(service, session_bus)
- activity_container.show()
+ log_writer = LogWriter("Shell", False)
+ log_writer.start()
- wm = WindowManager(activity_container.window)
- wm.set_width(640, WindowManager.ABSOLUTE)
- wm.set_height(480, WindowManager.ABSOLUTE)
- wm.set_position(WindowManager.CENTER)
- wm.show()
- wm.manage()
-
- console.set_parent_window(activity_container.window)
+ session_bus = dbus.SessionBus()
+ service = dbus.service.BusName("com.redhat.Sugar.Shell", bus=session_bus)
+
+ activity_container = ActivityContainer(service, session_bus)
+ activity_container.window.connect('destroy', self.__activity_container_destroy_cb)
+ activity_container.show()
+
+ wm = WindowManager(activity_container.window)
+ wm.set_width(640, WindowManager.ABSOLUTE)
+ wm.set_height(480, WindowManager.ABSOLUTE)
+ wm.set_position(WindowManager.CENTER)
+ wm.show()
+ wm.manage()
+
+ console.set_parent_window(activity_container.window)
+
+ def __activity_container_destroy_cb(self, activity_container):
+ self.emit('close')
if __name__ == "__main__":
- main()
+ shell = Shell()
+ shell.start()
try:
gtk.main()
except KeyboardInterrupt:
print 'Ctrl+c pressed, exiting...'
- pass
diff --git a/sugar/sugar b/sugar/sugar
index 259e9b6..28544fc 100755
--- a/sugar/sugar
+++ b/sugar/sugar
@@ -81,8 +81,9 @@ if console:
os.environ['SUGAR_USE_CONSOLE'] = 'yes'
print 'Redirecting output to the console, press ctrl+d to open it.'
-from sugar.session import session
+from sugar.session.session import Session
+session = Session()
session.start()
if dbus_daemon_pid: