Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/addons/openactivity.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/openactivity.py')
-rw-r--r--addons/openactivity.py180
1 files changed, 180 insertions, 0 deletions
diff --git a/addons/openactivity.py b/addons/openactivity.py
new file mode 100644
index 0000000..1b4d4b7
--- /dev/null
+++ b/addons/openactivity.py
@@ -0,0 +1,180 @@
+# 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
+
+# for easy profile access
+xo_line_color = profile.get_color().get_stroke_color()
+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.
+ """
+ message = TStringProperty("Message")
+
+ def __init__(self, message=None):
+ """Constructor.
+
+ @param message message to display
+ """
+ super(OpenActivity,self).__init__()
+
+ if message:
+ self.message = message
+
+ self.overlay = None
+ self.msgnext = None
+
+ def install_handlers(self, callback, **kwargs):
+ """install_handlers creates the open activity message and shows it"""
+ super(OpenActivity,self).install_handlers(callback, **kwargs)
+
+ # get or inject overlayer
+ self.overlay = ObjectStore().activity._overlayer
+
+ if not self.overlay:
+ self.overlay = ObjectStore().activity._overlayer
+
+ self.msgnext = None
+
+ #Create the open 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
+
+ # 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)
+ 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("OPEN")
+ 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 open activity message"""
+ super(OpenActivity,self).remove_handlers()
+
+ if self.msgnext:
+ self.msgnext.destroy()
+ self.msgnext = None
+
+ def btnnext_clicked(self, widget):
+ # temporary activity name hardcoded
+ activity_name = "org.laptop.Terminal"
+
+ 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)
+
+ self.do_callback()
+
+__event__ = {
+ "name" : "OpenActivity",
+ "display_name" : "Open activity message",
+ "icon" : "message-bubble",
+ "class" : OpenActivity,
+ "mandatory_props" : ["message"]
+}
+