Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/sugar-activity-qt
blob: fc4d383dcc901484c666e60a727ba83b9f1c30cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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_())