Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/sugar-activity-qt
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sugar-activity-qt')
-rwxr-xr-xbin/sugar-activity-qt99
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/sugar-activity-qt b/bin/sugar-activity-qt
new file mode 100755
index 0000000..fc4d383
--- /dev/null
+++ b/bin/sugar-activity-qt
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2009, Tomeu Vizoso
+#
+# 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 os
+import sys
+import gettext
+from optparse import OptionParser
+
+import sugar
+from sugar import logger
+from sugar.bundle.activitybundle import ActivityBundle
+from sugar.activity import activityhandle
+
+parser = OptionParser()
+parser.add_option("-b", "--bundle-id", dest="bundle_id",
+ help="identifier of the activity bundle")
+parser.add_option("-a", "--activity-id", dest="activity_id",
+ help="identifier of the activity instance")
+parser.add_option("-o", "--object-id", dest="object_id",
+ help="identifier of the associated datastore object")
+parser.add_option("-u", "--uri", dest="uri",
+ help="URI to load")
+parser.add_option('-s', '--single-process', dest='single_process',
+ action='store_true',
+ help='start all the instances in the same process')
+(options, args) = parser.parse_args()
+
+logger.start()
+
+if 'SUGAR_BUNDLE_PATH' not in os.environ:
+ print 'SUGAR_BUNDLE_PATH is not defined in the environment.'
+ sys.exit(1)
+
+if len(args) == 0:
+ print 'A python class must be specified as first argument.'
+ sys.exit(1)
+
+bundle_path = os.environ['SUGAR_BUNDLE_PATH']
+sys.path.append(bundle_path)
+
+bundle = ActivityBundle(bundle_path)
+
+os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id()
+os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name()
+os.environ['SUGAR_BUNDLE_VERSION'] = str(bundle.get_activity_version())
+
+#gtk.icon_theme_get_default().append_search_path(bundle.get_icons_path())
+
+locale_path = None
+if 'SUGAR_LOCALEDIR' in os.environ:
+ locale_path = os.environ['SUGAR_LOCALEDIR']
+
+gettext.bindtextdomain(bundle.get_bundle_id(), locale_path)
+gettext.bindtextdomain('sugar-toolkit', sugar.locale_path)
+gettext.textdomain(bundle.get_bundle_id())
+
+splitted_module = args[0].rsplit('.', 1)
+module_name = splitted_module[0]
+class_name = splitted_module[1]
+
+module = __import__(module_name)
+for comp in module_name.split('.')[1:]:
+ module = getattr(module, comp)
+
+activity_constructor = getattr(module, class_name)
+activity_handle = activityhandle.ActivityHandle(
+ activity_id=options.activity_id,
+ object_id=options.object_id, uri=options.uri)
+
+from PyQt4 import QtGui
+app = QtGui.QApplication(sys.argv)
+
+print app.style().objectName()
+
+# TODO: the Sugar Gtk+ theme and engine should be enough?
+css_file = os.path.join(bundle_path, 'stylesheet.qss')
+if os.access(css_file, os.R_OK):
+ app.setStyleSheet(file(css_file).read())
+
+activity = activity_constructor(activity_handle)
+activity.show()
+
+sys.exit(app.exec_())
+