Allow to run activities without Sugar shell.
- Handle lack of GSettings gracefully.
- Still requires sugar-datastore.
- Supports avoiding X11 docks/panels.
- Provides icons for Activity windows.
Try it outside Sugar. Go to an Activity directory and run 'sugar-activity'.
Tested it with Terminal, Finance, Write, Browse, Memorize under XFCE4.
Tested in Gnome under OLPC-OS.
Also works from Sugar Terminal Activity.
Does not affect regular Sugar operation.
This is patch v.2 -
Addresses most concerns:
- Removed commented code, sorry.
- Changed code to use profile.get_nickname and get_color where possible.
Couldn't the launcher just pass this info?
Maybe the launcher could set the activity root as well?
- It is intended to be usable from the command line also.
Should put sugar version in the environment
- It is intended to work even without Sugar Shell installed.
Why don't we always set the icon?
- On XO it might use some memory. I was concerned to degrade
performance.
Also, imports should be at the top of the file?
- Also a concern about performance on XO.
This way it is only loaded in this use case.
Maybe it is insignificant -moved as requested.
It would be nice if the changes to the POT for sugar-toolkit-gtk3
could be incorporated in this pull request, please.
- There were no changes to POT files as part of this patch. Maybe
it is worth translating low level command line tools, not sure.
Suggest packaged activities might also provide .desktop files.
- Intriguing but not sure within scope of this patch. You mean generate
a .desktop file automatically as an option? Sounds nice!
Suggest sugar-activity might also accept path to unpacked bundle.
- Implemented!
This commit is contained in:
Regular → Executable
+38
-9
@@ -35,8 +35,10 @@ DBusGMainLoop(set_as_default=True)
|
||||
from sugar3.activity import activityhandle
|
||||
from sugar3 import config
|
||||
from sugar3.bundle.activitybundle import ActivityBundle
|
||||
from sugar3.activity.activityfactory import get_environment
|
||||
from sugar3 import logger
|
||||
|
||||
from sugar3.bundle.bundle import MalformedBundleException
|
||||
|
||||
def create_activity_instance(constructor, handle):
|
||||
activity = constructor(handle)
|
||||
@@ -69,7 +71,13 @@ class SingleProcess(dbus.service.Object):
|
||||
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
usage = 'usage: %prog [options] [activity dir] [python class]'
|
||||
epilog = 'If you are running from a directory containing an Activity, ' \
|
||||
'the argument may be ommitted. Otherwise please provide either '\
|
||||
'a directory containing a Sugar Activity [activity dir], a '\
|
||||
'[python_class], or both.'
|
||||
|
||||
parser = OptionParser(usage=usage, epilog=epilog)
|
||||
parser.add_option('-b', '--bundle-id', dest='bundle_id',
|
||||
help='identifier of the activity bundle')
|
||||
parser.add_option('-a', '--activity-id', dest='activity_id',
|
||||
@@ -89,18 +97,34 @@ def main():
|
||||
|
||||
logger.start()
|
||||
|
||||
if 'SUGAR_BUNDLE_PATH' not in os.environ:
|
||||
print 'SUGAR_BUNDLE_PATH is not defined in the environment.'
|
||||
sys.exit(1)
|
||||
activity_class = None
|
||||
if len(args) == 2:
|
||||
activity_class = args[1]
|
||||
os.chdir(args[0])
|
||||
elif len(args) == 1:
|
||||
if os.path.isdir(args[0]):
|
||||
os.chdir(args[0])
|
||||
else:
|
||||
activity_class = args[0]
|
||||
|
||||
if len(args) == 0:
|
||||
print 'A python class must be specified as first argument.'
|
||||
sys.exit(1)
|
||||
os.environ['SUGAR_BUNDLE_PATH'] = os.path.abspath(os.curdir)
|
||||
|
||||
bundle_path = os.environ['SUGAR_BUNDLE_PATH']
|
||||
sys.path.append(bundle_path)
|
||||
|
||||
bundle = ActivityBundle(bundle_path)
|
||||
try:
|
||||
bundle = ActivityBundle(bundle_path)
|
||||
except MalformedBundleException:
|
||||
parser.print_help()
|
||||
exit(0)
|
||||
|
||||
if not activity_class:
|
||||
if bundle.get_command().startswith('sugar-activity'):
|
||||
print 'Guessing python class from activity.info!'
|
||||
activity_class = bundle.get_command().split(" ")[1]
|
||||
|
||||
if 'SUGAR_VERSION' not in os.environ:
|
||||
environ = get_environment(bundle)
|
||||
|
||||
os.environ['SUGAR_BUNDLE_ID'] = bundle.get_bundle_id()
|
||||
os.environ['SUGAR_BUNDLE_NAME'] = bundle.get_name()
|
||||
@@ -114,7 +138,7 @@ def main():
|
||||
gettext.bindtextdomain('sugar-toolkit-gtk3', config.locale_path)
|
||||
gettext.textdomain(bundle.get_bundle_id())
|
||||
|
||||
splitted_module = args[0].rsplit('.', 1)
|
||||
splitted_module = activity_class.rsplit('.', 1)
|
||||
module_name = splitted_module[0]
|
||||
class_name = splitted_module[1]
|
||||
|
||||
@@ -123,6 +147,11 @@ def main():
|
||||
module = getattr(module, comp)
|
||||
|
||||
activity_constructor = getattr(module, class_name)
|
||||
|
||||
if not options.activity_id:
|
||||
options.activity_id = bundle.get_name()
|
||||
options.bundle_id = bundle.get_bundle_id()
|
||||
|
||||
activity_handle = activityhandle.ActivityHandle(
|
||||
activity_id=options.activity_id,
|
||||
object_id=options.object_id, uri=options.uri,
|
||||
|
||||
Reference in New Issue
Block a user