Hi,

On Thu, Jul 2, 2009 at 6:21 PM, Tomeu Vizoso<to...@sugarlabs.org> wrote:
> On Thu, Jul 2, 2009 at 14:42, Walter Bender<walter.ben...@gmail.com> wrote:

<..snip snip>

>>
>> I had set up Turtle Art to be able to run outside of Sugar. It has a
>> .desktop file and should install under the Applications/Education menu
>> on the desktop. Or run it from the shell from turlteart.py.
>>
>> It has its problems: no access to the toolbar and no access to the
>> journal or sharing. But it runs.
>
> We have quite a bit of work until we can get it to work, but it's
> doable to have everything working out of the Sugar shell.
>

Attached is a written in half an hour python script, which runs most
of the activities installed in my system (not the jhbuild ones - but
the ones installed via yum groupinstall sugar-desktop)
It has probably got the highest possible number of bug per line, and
does no error checking of each kind, but it's a start. I don't know
when I'll be able to put more effort into this - but if anyone else is
interested, please feel free to go ahead.

Run it in the form of

run_activities_in_desktop.py Jukebox /home/sayamindu/abc.ogg

(note that Jukebox is case sensitive)

There is no way to view the neighbourhood, and there is no way to see
the journal, and for all I know, the journal service does not run in
the background as well - so objectchooser won't work.

Thanks,
Sayamindu


-- 
Sayamindu Dasgupta
[http://sayamindu.randomink.org/ramblings]
#!/usr/bin/env python

# Description:  Crude script to run Sugar Activities inside traditional desktops
# Author:       Sayamindu Dasgupta <sayami...@sugarlabs.org>

import os, sys
import gtk
import sugar.activity.activityhandle
import sugar.env
from sugar.presence import presenceservice
from sugar import util
import ConfigParser

ACTIVITIES_DIR = '/usr/share/sugar/activities'

def create_activity_id():
    """Generate a new, unique ID for this activity"""
    pservice = presenceservice.get_instance()

    # create a new unique activity ID
    i = 0
    act_id = None
    while i < 10:
        act_id = util.unique_id()
        i += 1

        # check through network activities
        found = False
        activities = pservice.get_activities()
        for act in activities:
            if act_id == act.props.id:
                found = True
                break
        if not found:
            return act_id
    raise RuntimeError("Cannot generate unique activity id.")


def _set_env(id, name, path, root, version):
    os.environ['SUGAR_BUNDLE_ID'] = id
    os.environ['SUGAR_BUNDLE_NAME'] = name
    os.environ['SUGAR_BUNDLE_PATH'] = path
    os.environ['SUGAR_ACTIVITY_ROOT'] = root
    os.environ['SUGAR_BUNDLE_VERSION'] = version

def _init_theme():
    s = gtk.settings_get_default()
    s.props.gtk_theme_name = 'sugar-100'
    s.props.gtk_icon_theme_name = 'sugar'

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print 'Please mention at least the activity name'
        sys.exit()
    
    _init_theme()
    activity_name = sys.argv[1]
    if len(sys.argv) > 2:
        uri = sys.argv[2]
    else:
        uri = None
    
    activity_dir = os.path.join(ACTIVITIES_DIR, activity_name+'.activity')
    activity_info_path = os.path.join(activity_dir, 'activity', 'activity.info')

    config = ConfigParser.ConfigParser()
    config.read(activity_info_path)

    try:
        service_name = config.get('Activity', 'service_name')
    except ConfigParser.NoOptionError:
        service_name = config.get('Activity', 'bundle_id')
    try:
        klass = config.get('Activity', 'class')
    except ConfigParser.NoOptionError:
        klass = config.get('Activity', 'exec').split(' ')[1]
    name = config.get('Activity', 'name')
    version = config.get('Activity', 'activity_version')
    id = create_activity_id()
    root = os.path.join(sugar.env.get_profile_path(), service_name)
    try:
        os.makedirs(os.path.join(root, 'data'))
        os.makedirs(os.path.join(root, 'instance'))
        os.makedirs(os.path.join(root, 'tmp'))
    except:
        pass

    _set_env(service_name, name, activity_dir, root, version)
    icons_path = os.path.join(activity_dir,'icons')
    gtk.icon_theme_get_default().append_search_path(icons_path)

    os.chdir(activity_dir)
    sys.path.append(activity_dir)
    exec('import %s' % klass.split('.')[0])

    handle = sugar.activity.activityhandle.ActivityHandle(id, uri = uri)

    exec('activity_instance = %s(handle)' % klass)

    activity_instance.maximize()
    activity_instance.show_all()

    gtk.main()
_______________________________________________
IAEP -- It's An Education Project (not a laptop project!)
IAEP@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/iaep

Reply via email to