Skip to content

Commit

Permalink
Make GTK2 activities run properly outside Sugar.
Browse files Browse the repository at this point in the history
- Proper themes and scaling overriding XSETTINGS daemon
- Set activity icon
- Scale activity window in accordance to workarea
- Find acitivity root
  • Loading branch information
icarito committed May 17, 2016
1 parent 3c14c65 commit 1a80668
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/sugar/activity/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ReadActivity(activity.Activity):
from sugar.graphics.alert import Alert
from sugar.graphics.icon import Icon
from sugar.datastore import datastore
from sugar.bundle.activitybundle import get_bundle_instance
from sugar.session import XSMPClient
from sugar import wm

Expand Down Expand Up @@ -263,11 +264,20 @@ def __init__(self, handle, create_jobject=True):
icons_path = os.path.join(get_bundle_path(), 'icons')
gtk.icon_theme_get_default().append_search_path(icons_path)

sugar_theme = 'sugar-72'
if 'SUGAR_SCALING' in os.environ:
if os.environ['SUGAR_SCALING'] == '100':
sugar_theme = 'sugar-100'

# This code can be removed when we grow an xsettings daemon (the GTK+
# init routines will then automatically figure out the font settings)
settings = gtk.settings_get_default()
settings.set_property('gtk-font-name',
'%s %f' % (style.FONT_FACE, style.FONT_SIZE))
settings.set_property('gtk-theme-name', sugar_theme)
settings.set_property('gtk-icon-theme-name', 'sugar')
settings.set_property('gtk-icon-sizes', 'gtk-large-toolbar=%s,%s' %
(style.STANDARD_ICON_SIZE, style.STANDARD_ICON_SIZE))

Window.__init__(self)

Expand Down Expand Up @@ -366,6 +376,10 @@ def __init__(self, handle, create_jobject=True):
self.__jobject_updated_cb)
self.set_title(self._jobject.metadata['title'])

if 'SUGAR_VERSION' not in os.environ:
bundle = get_bundle_instance(get_bundle_path())
self.set_icon_from_file(bundle.get_icon())

def run_main_loop(self):
gtk.main()

Expand Down Expand Up @@ -505,11 +519,13 @@ def __window_state_event_cb(self, window, event):
self.move(0, 0)

def _adapt_window_to_screen(self):
screen = gtk.gdk.screen_get_default()
screen = gtk.gdk.get_default_root_window()
workarea = gtk.gdk.atom_intern('_NET_WORKAREA')
width, height = screen.property_get(workarea)[2][2:4]
self.set_geometry_hints(None,
screen.get_width(), screen.get_height(),
screen.get_width(), screen.get_height(),
screen.get_width(), screen.get_height(),
width, height,
width, height,
width, height,
1, 1, 1, 1)

def __session_quit_requested_cb(self, session):
Expand Down Expand Up @@ -555,7 +571,7 @@ def get_activity_root(self):
if os.environ.get('SUGAR_ACTIVITY_ROOT'):
return os.environ['SUGAR_ACTIVITY_ROOT']
else:
return '/'
return get_activity_root()

def read_file(self, file_path):
"""
Expand Down Expand Up @@ -695,7 +711,7 @@ def save(self):
if not self.metadata.get('activity_id', ''):
self.metadata['activity_id'] = self.get_id()

file_path = os.path.join(self.get_activity_root(), 'instance',
file_path = os.path.join(get_activity_root(), 'instance',
'%i' % time.time())
try:
self.write_file(file_path)
Expand Down Expand Up @@ -1019,7 +1035,16 @@ def get_activity_root():
if os.environ.get('SUGAR_ACTIVITY_ROOT'):
return os.environ['SUGAR_ACTIVITY_ROOT']
else:
raise RuntimeError('No SUGAR_ACTIVITY_ROOT set.')
profile_id = os.environ.get('SUGAR_PROFILE', 'default')
home_dir = os.environ.get('SUGAR_HOME', os.path.expanduser('~/.sugar'))
base = os.path.join(home_dir, profile_id)
activity_root = os.path.join(base, os.environ['SUGAR_BUNDLE_ID'])
try:
os.mkdir(activity_root)
except OSError, e:
if e.errno != EEXIST:
raise e
return activity_root


def show_object_in_journal(object_id):
Expand Down
12 changes: 12 additions & 0 deletions src/sugar/bundle/activitybundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
from sugar.bundle.bundleversion import InvalidVersionError


_bundle_instances = {}


class ActivityBundle(Bundle):
"""A Sugar activity bundle
Expand Down Expand Up @@ -76,6 +79,8 @@ def __init__(self, path):
if self._local_name == None:
self._local_name = self._name

_bundle_instances[path] = self

def _parse_info(self, info_file):
cp = ConfigParser()
cp.readfp(info_file)
Expand Down Expand Up @@ -339,3 +344,10 @@ def uninstall(self, install_path, force=False, delete_profile=False):

def is_user_activity(self):
return self.get_path().startswith(env.get_user_activities_path())


def get_bundle_instance(path):
global _bundle_instances
if path not in _bundle_instances:
_bundle_instances[path] = ActivityBundle(path)
return _bundle_instances[path]

0 comments on commit 1a80668

Please sign in to comment.