Refactor a bit to simply __init__

This commit is contained in:
Marco Pesenti Gritti 2006-12-24 02:51:37 +01:00
parent 5bd97cf5a1
commit dce69ef995
2 changed files with 48 additions and 21 deletions

View File

@ -57,24 +57,10 @@ class Shell(gobject.GObject):
self._key_grabber = KeyGrabber()
self._key_grabber.connect('key-pressed',
self.__global_key_pressed_cb)
self._key_pressed_cb)
self._key_grabber.connect('key-released',
self.__global_key_released_cb)
self._key_grabber.grab('F1')
self._key_grabber.grab('F2')
self._key_grabber.grab('F3')
self._key_grabber.grab('F4')
self._key_grabber.grab('F5')
self._key_grabber.grab('F6')
self._key_grabber.grab('F7')
self._key_grabber.grab('F8')
self._key_grabber.grab('0xDC') # Camera key
self._key_grabber.grab('0xE0') # Overlay key
self._key_grabber.grab('0x93') # Frame key
# For non-OLPC machines
self._key_grabber.grab('<shft><alt>F9')
self._key_grabber.grab('<shft><alt>F10')
self._key_released_cb)
self._grab_keys()
self._home_window = HomeWindow(self)
self._home_window.show()
@ -95,7 +81,24 @@ class Shell(gobject.GObject):
self.start_activity('org.laptop.CameraActivity')
def __global_key_pressed_cb(self, grabber, key):
def _grab_keys(self):
self._key_grabber.grab('F1')
self._key_grabber.grab('F2')
self._key_grabber.grab('F3')
self._key_grabber.grab('F4')
self._key_grabber.grab('F5')
self._key_grabber.grab('F6')
self._key_grabber.grab('F7')
self._key_grabber.grab('F8')
self._key_grabber.grab('0xDC') # Camera key
self._key_grabber.grab('0xE0') # Overlay key
self._key_grabber.grab('0x93') # Frame key
# For non-OLPC machines
self._key_grabber.grab('<shft><alt>F9')
self._key_grabber.grab('<shft><alt>F10')
def _key_pressed_cb(self, grabber, key):
if key == 'F1':
self.set_zoom_level(sugar.ZOOM_MESH)
elif key == 'F2':
@ -123,7 +126,7 @@ class Shell(gobject.GObject):
elif key == '0x93': # Frame key
self._frame.notify_key_press()
def __global_key_released_cb(self, grabber, key):
def _key_released_cb(self, grabber, key):
if key == '<shft><alt>F9':
self._frame.notify_key_release()
elif key == '0x93':

View File

@ -22,8 +22,10 @@ import dbus
import dbus.service
import gtk
import gobject
import datetime
from sugar.presence import PresenceService
from sugar.datastore import datastore
from sugar import activity
from sugar import env
import sugar.util
@ -95,11 +97,13 @@ class Activity(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect('destroy', self.__destroy_cb)
self.connect('destroy', self._destroy_cb)
self.connect('notify::title', self._title_changed_cb)
self._shared = False
self._activity_id = None
self._service = None
self._journal_object = None
self._pservice = PresenceService.get_instance()
self.realize()
@ -117,8 +121,20 @@ class Activity(gtk.Window):
return
self._activity_id = sugar.util.unique_id()
ds = datastore.get_instance()
self._journal_object = ds.create('', {}, self._activity_id)
date = datetime.datetime.now()
self._journal_jobject.set_properties({'date' : date,
'title' : self.get_title()})
self.present()
def get_journal_object(self):
"""Returns the journal object associated with the activity."""
return self._journal_object
def get_type(self):
"""Gets the activity type."""
return env.get_bundle_service_name()
@ -158,6 +174,9 @@ class Activity(gtk.Window):
else:
logging.error('Cannot join the activity')
ds = datastore.get_instance()
self._journal_object = ds.get_activity_object(self._activity_id)
self.present()
def share(self):
@ -172,9 +191,14 @@ class Activity(gtk.Window):
"""Execute the given command with args"""
return False
def __destroy_cb(self, window):
def _destroy_cb(self, window):
if self._bus:
del self._bus
self._bus = None
if self._service:
self._pservice.unregister_service(self._service)
def _title_changed_cb(self, window, spec):
jobject = self.get_journal_object()
if jobject:
jobject.set_properties({'title' : self.props.title})