From 1a806683c7a1dd58347285c1d3dfdc79deb13c2e Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 17 May 2016 02:23:16 -0500 Subject: [PATCH] Make GTK2 activities run properly outside Sugar. - Proper themes and scaling overriding XSETTINGS daemon - Set activity icon - Scale activity window in accordance to workarea - Find acitivity root --- src/sugar/activity/activity.py | 39 ++++++++++++++++++++++++------ src/sugar/bundle/activitybundle.py | 12 +++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index a0e2e113..dc1bc0b7 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -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 @@ -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) @@ -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() @@ -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): @@ -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): """ @@ -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) @@ -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): diff --git a/src/sugar/bundle/activitybundle.py b/src/sugar/bundle/activitybundle.py index 542fa00d..bfa05e78 100644 --- a/src/sugar/bundle/activitybundle.py +++ b/src/sugar/bundle/activitybundle.py @@ -36,6 +36,9 @@ from sugar.bundle.bundleversion import InvalidVersionError +_bundle_instances = {} + + class ActivityBundle(Bundle): """A Sugar activity bundle @@ -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) @@ -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]