diff options
author | dave <drykod@gmail.com> | 2009-10-29 06:18:53 (GMT) |
---|---|---|
committer | dave <drykod@gmail.com> | 2009-10-29 06:18:53 (GMT) |
commit | b0b64a0fc2e13dfbe0bc21a22053e43f4056d2f9 (patch) | |
tree | 07a6850230d11f570893d7ad151dfa2b52fa97cf | |
parent | 8340f12f9f7d3be373a8b94ce7866666abe5be80 (diff) |
open/close activity
-rw-r--r-- | addons/closeactivity.py | 170 | ||||
-rw-r--r-- | addons/openactivity.py | 82 |
2 files changed, 233 insertions, 19 deletions
diff --git a/addons/closeactivity.py b/addons/closeactivity.py new file mode 100644 index 0000000..fafbd28 --- /dev/null +++ b/addons/closeactivity.py @@ -0,0 +1,170 @@ +# Copyright (C) 2009, Tutorius.org +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import logging + +import gobject + +import gtk, gtk.gdk + +import os +import dbus + +from sugar.tutorius.filters import EventFilter +from sugar.tutorius.properties import TStringProperty, TArrayProperty, TIntProperty +from sugar.tutorius import overlayer +from sugar.tutorius.services import ObjectStore + +from sugar import profile + +from sugar.activity import activityfactory +from sugar.bundle.activitybundle import ActivityBundle +from jarabe.model import bundleregistry + +# for easy profile access +xo_line_color = profile.get_color().get_stroke_color() +xo_fill_color = profile.get_color().get_fill_color() + +class CloseActivity(EventFilter): + """ + CloseActivity + """ + message = TStringProperty("Message") + + def __init__(self, message=None): + """Constructor. + + @param message message to display + """ + super(CloseActivity,self).__init__() + + self.message = None + if message: + self.message = message + + self.overlay = None + self.msgnext = None + + self.act = None + + def install_handlers(self, callback, **kwargs): + """install_handlers creates the close activity message and shows it""" + super(CloseActivity,self).install_handlers(callback, **kwargs) + if not "activity" in kwargs: + raise TypeError("activity argument is Mandatory") + + self.act = kwargs["activity"] + + # get or inject overlayer + self.overlay = ObjectStore().activity._overlayer + + if not self.overlay: + self.overlay = ObjectStore().activity._overlayer + + self.msgnext = None + + #Create the close activity message + if not self.msgnext: + # create an eventbox + self.msgnext = gtk.EventBox() + self.msgnext.set_visible_window(True) + + # create a vbox + self.box = gtk.VBox() + + # get position (center of screen) + screen = gtk.gdk.Screen() + scr_width_half = screen.get_width()/2 #self.overlayer.get_screen().get_width()/2 + scr_height_half = screen.get_height()/2 #self.overlayer.get_screen().get_height()/2 + + # create a label (set message to display) + self._label = gtk.Label() + self._text = "<b>%s</b>" % self.message + self._label.set_markup(self._text) + self._label.set_line_wrap(True) + + self._colortext = gtk.gdk.color_parse("white") + self._label.modify_fg(gtk.STATE_NORMAL, self._colortext) + self._label.modify_fg(gtk.STATE_PRELIGHT, self._colortext) + self._label.modify_fg(gtk.STATE_ACTIVE, self._colortext) + self._label.modify_fg(gtk.STATE_INSENSITIVE, self._colortext) + + self._label.show() + + # create a hbox (holding button) + self._hbox = gtk.HBox() + + # create a button inside hbox + self._btnnext = gtk.Button("CLOSE") + self._btnnext.connect("clicked", self.btnnext_clicked) + + self._colorbtn = gtk.gdk.color_parse(xo_fill_color) + + self._btnnext.modify_bg(gtk.STATE_NORMAL, self._colorbtn) + self._btnnext.modify_bg(gtk.STATE_PRELIGHT, self._colorbtn) + self._btnnext.modify_bg(gtk.STATE_ACTIVE, self._colorbtn) + + self._btnnext.show() + + self._hbox.pack_end(self._btnnext, expand=False) + + self._hbox.show() + + self.box.pack_start(self._label, expand=True) + self.box.pack_start(self._hbox, expand=True) + + self.box.show() + + self.msgnext.add(self.box) + + self._colormsgnext = gtk.gdk.color_parse(xo_fill_color) + self.msgnext.modify_bg(gtk.STATE_NORMAL, self._colormsgnext) + + # add space around minimum need size + wid_width, wid_height = self.msgnext.size_request() + self.msgnext.set_size_request(wid_width+40, wid_height+40) + + self.msgnext.show() + + # set position + wid_width, wid_height = self.msgnext.size_request() + self.position = (scr_width_half-wid_width/2, scr_height_half-wid_height/2) + x, y = self.position + + self.overlay.put(self.msgnext, x, y) + + self.overlay.queue_draw() + + def remove_handlers(self): + """remove handler removes the close activity message""" + super(OpenActivity,self).remove_handlers() + + if self.msgnext: + self.msgnext.destroy() + self.msgnext = None + + def btnnext_clicked(self, widget): + self.act.close() + self.do_callback() + +__event__ = { + "name" : "CloseActivity", + "display_name" : "Close activity message", + "icon" : "message-bubble", + "class" : CloseActivity, + "mandatory_props" : ["message"] +} + diff --git a/addons/openactivity.py b/addons/openactivity.py index 1b4d4b7..53ca053 100644 --- a/addons/openactivity.py +++ b/addons/openactivity.py @@ -32,6 +32,7 @@ from sugar import profile from sugar.activity import activityfactory from sugar.bundle.activitybundle import ActivityBundle +from jarabe.model import bundleregistry # for easy profile access xo_line_color = profile.get_color().get_stroke_color() @@ -39,28 +40,41 @@ xo_fill_color = profile.get_color().get_fill_color() class OpenActivity(EventFilter): """ - IntroMessage is a special EventFilter that uses gobject - start button to trigger a state change after user click on it. - It must be used inside a gobject main loop to work. + OpenActivity """ message = TStringProperty("Message") + activity_name = TStringProperty("ActivityName") - def __init__(self, message=None): + def __init__(self, message=None, activity_name=None): """Constructor. @param message message to display """ super(OpenActivity,self).__init__() + self.message = None if message: self.message = message + # temporary activity name + #activity_name = "org.laptop.Terminal" + + self.activity_name = None + if activity_name: + self.activity_name = activity_name + self.overlay = None self.msgnext = None + self.act = None + def install_handlers(self, callback, **kwargs): """install_handlers creates the open activity message and shows it""" super(OpenActivity,self).install_handlers(callback, **kwargs) + if not "activity" in kwargs: + raise TypeError("activity argument is Mandatory") + + self.act = kwargs["activity"] # get or inject overlayer self.overlay = ObjectStore().activity._overlayer @@ -84,13 +98,8 @@ class OpenActivity(EventFilter): scr_width_half = screen.get_width()/2 #self.overlayer.get_screen().get_width()/2 scr_height_half = screen.get_height()/2 #self.overlayer.get_screen().get_height()/2 - # get user name - name = profile.get_nick_name() - if not name or not len(name): - name = "User" - - # create a label - self._label = gtk.Label("Hello " + name + "!\n\n" + self.message) + # create a label (set message to display) + self._label = gtk.Label() self._text = "<b>%s</b>" % self.message self._label.set_markup(self._text) self._label.set_line_wrap(True) @@ -156,20 +165,55 @@ class OpenActivity(EventFilter): self.msgnext = None def btnnext_clicked(self, widget): - # temporary activity name hardcoded - activity_name = "org.laptop.Terminal" + if self.activity_name: + bus = dbus.SessionBus() + proxy = bus.get_object('org.laptop.Shell', '/org/laptop/Shell') + path = dbus.Interface(proxy, 'org.laptop.Shell').GetBundlePath(self.activity_name) + if not path: + print 'Cannot find %s bundle.' % self.activity_name + else: + activity_bundle = ActivityBundle(path) + activityfactory.create(activity_bundle) + self.do_callback() + else: + self.open_activity_list() + def open_activity_list(self): bus = dbus.SessionBus() proxy = bus.get_object('org.laptop.Shell', '/org/laptop/Shell') - path = dbus.Interface(proxy, 'org.laptop.Shell').GetBundlePath(activity_name) - if not path: - print 'Cannot find %s bundle.' % activity_name - else: - activity = ActivityBundle(path) - activityfactory.create(activity) + + bregistry = bundleregistry.get_registry() + self.bundles = bregistry._bundles + + self.dlg = gtk.Dialog() + + combobox = gtk.combo_box_new_text() + self.dlg.add_action_widget(combobox, 0) + + # for each bundle (activity) + for bundle in self.bundles: + combobox.append_text(bundle.get_name()) + + combobox.connect('changed', self.changed_cb) + + self.dlg.show_all() + + return + + def changed_cb(self, combobox): + model = combobox.get_model() + index = combobox.get_active() + + if index: + #print 'About to start ', model[index][0], ' activity' + activityfactory.create(self.bundles[index]) + + self.dlg.destroy() self.do_callback() + return + __event__ = { "name" : "OpenActivity", "display_name" : "Open activity message", |