Difference between revisions of "Activity Team/Compatibility Tips"
(15 intermediate revisions by 3 users not shown) | |||
Line 16: | Line 16: | ||
except: | except: | ||
# early versions of Sugar (656) didn't support get_activity_root() | # early versions of Sugar (656) didn't support get_activity_root() | ||
− | path = "/home/olpc/.sugar/default/ | + | path = "/home/olpc/.sugar/default/[your activity bundle id as specified in activity.info]" |
− | === | + | e.g., |
+ | path = "/home/olpc/.sugar/default/org.laptop.TurtleArtActivity" | ||
+ | |||
+ | === SVG === | ||
Some earlier OLPC builds (e.g., 656) use an older version of the gtk svg libraries that don't process svg files that use the <svg:tag> syntax. It seems that removing svg: resolves the rendering problem. | Some earlier OLPC builds (e.g., 656) use an older version of the gtk svg libraries that don't process svg files that use the <svg:tag> syntax. It seems that removing svg: resolves the rendering problem. | ||
Line 26: | Line 29: | ||
Another issue is with SVG paths. Some SVG editors, e.g., inkscape, sometimes omit the l in a path that uses relative line-tos. These paths will not render properly on old OLPC builds. | Another issue is with SVG paths. Some SVG editors, e.g., inkscape, sometimes omit the l in a path that uses relative line-tos. These paths will not render properly on old OLPC builds. | ||
− | <path d="m 100,100 10,10> won't work | + | <path d="m 100,100 10,10 /> won't work |
− | <path d="m 100,100 l 10,10> will work | + | <path d="m 100,100 l 10,10 /> will work |
+ | |||
+ | In recent Fedora/Sugar builds (F13/0.88) another SVG problem has been occurring. If you define a path without explicitly defining stroke and fill colors, it will render as black, even if you define stroke and fill colors in your initial <svg> block. | ||
+ | |||
+ | <svg ... stroke="&stoke_color;" fill="&fill_color;" ... > | ||
+ | <path ... /> won't work | ||
+ | <path ... stroke="&stoke_color;" fill="&fill_color;" /> will work | ||
+ | </svg> | ||
+ | |||
+ | === artwork === | ||
+ | |||
+ | Some Sugar icons are not present in old systems. If, for example, you want to use the filesave icon, you should include a copy in your bundle (in the icon subdirectory) to ensure that it is present on older systems. | ||
+ | |||
+ | Q: Is there a comprehensive list somewhere of which icons were added to sugar-artwork when? | ||
+ | |||
+ | === tool tips === | ||
+ | |||
+ | Older versions of Sugar did not support tool tips. You could catch the exception as per: | ||
+ | |||
+ | try: | ||
+ | self.activity.fullscreen_button.props.accelerator = '<Alt>Enter' | ||
+ | except AttributeError: | ||
+ | pass | ||
+ | |||
+ | Note that this is only relevant to pre-0.86 toolbars. | ||
− | === | + | === screen size === |
The screen size varies on different hardware platforms. If you develop in an emulator, it is worthwhile trying different sizes to make sure your activity scales properly. | The screen size varies on different hardware platforms. If you develop in an emulator, it is worthwhile trying different sizes to make sure your activity scales properly. | ||
Line 43: | Line 70: | ||
At some point, the behavior of the Python tarfile library seems to have changed (I've not yet hunted down the documentation.) In any case, on Build 767, it was generating .tar suffixes and on later builds (newer Python libraries?) it was generating .gtar suffixes. I got burnt by this in Turtle Art so now I check for both. | At some point, the behavior of the Python tarfile library seems to have changed (I've not yet hunted down the documentation.) In any case, on Build 767, it was generating .tar suffixes and on later builds (newer Python libraries?) it was generating .gtar suffixes. I got burnt by this in Turtle Art so now I check for both. | ||
− | if file_path[ | + | if file_path.endswith(('.gtar', '.tar')): |
+ | |||
+ | |||
+ | [[Category:Activity Team]] | ||
+ | |||
+ | === Sugar toolbar version === | ||
+ | |||
+ | Sugar toolbars changed in Sucrose v0.86. You can detect which version you are running by checking for an ImportError: | ||
+ | |||
+ | try: # 0.86 toolbar widgets | ||
+ | from sugar.activity.widgets import ActivityToolbarButton, StopButton | ||
+ | from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton | ||
+ | has_toolbarbox = True | ||
+ | except ImportError: | ||
+ | has_toolbarbox = False | ||
+ | |||
+ | Use the flag to determine whether to create old-style or new toolbars: | ||
+ | |||
+ | if has_toolbarbox: | ||
+ | # Use 0.86+ toolbar design | ||
+ | toolbar_box = ToolbarBox() | ||
+ | ... | ||
+ | else: | ||
+ | # Use pre-0.86 toolbar design | ||
+ | self.toolbox = activity.ActivityToolbox(self) | ||
+ | ... | ||
+ | |||
+ | You can share callbacks between versions, but take care to make sure you are using the proper context: | ||
+ | # 0.86+ | ||
+ | fullscreen_button.connect('clicked', self._do_fullscreen_cb) | ||
or | or | ||
+ | # pre-0.86 | ||
+ | self.viewToolbar = ViewToolbar(self) | ||
+ | ... | ||
+ | |||
+ | class ViewToolbar(gtk.Toolbar): | ||
+ | def __init__(self, pc): | ||
+ | self.activity = pc | ||
+ | ... | ||
+ | |||
+ | self.activity.fullscreen_button.connect('clicked', self.activity._do_fullscreen_cb) | ||
+ | |||
+ | === Python versions === | ||
+ | |||
+ | Some Sugar systems are running on older versions of Python. Take care to make sure you don't run into syntax errors do to changes in the Python language. For example, I was burned on the following: | ||
− | + | except Exception as e: # works fine with Python 2.6 but raises a syntax error with Python 2.5 | |
+ | except Exception, e: # works fine in both cases. | ||
+ | |||
+ | See python.org for more information on incompatibilities between versions. | ||
+ | |||
+ | === GNOME toolkit versions === | ||
+ | In older versions of gtk, e.g., 2.16.0, the set_size_request method does not work properly for label. | ||
+ | label = gtk.Label(string) | ||
+ | label.set_line_wrap(True) | ||
+ | label.set_size_request(width, -1) | ||
+ | Works fine on 2.22.0 | ||
− | + | ''I'll try to track down the relevant gtk patch.'' |
Latest revision as of 13:20, 23 January 2012
Compatibility Tips
SUGAR_BUNDLE_VERSION
Some earlier OLPC builds (e.g., 703) do not have a bundle version environment variable, so you need to catch an exception if you want to access the version.
try: version = os.environ['SUGAR_BUNDLE_VERSION'] except: version = "unknown"
get_activity_root()
Some earlier OLPC builds (e.g., 656) do not have activity.get_activity_root(), so you need to catch an exception if you want to access the version.
try: path = activity.get_activity_root() except: # early versions of Sugar (656) didn't support get_activity_root() path = "/home/olpc/.sugar/default/[your activity bundle id as specified in activity.info]"
e.g.,
path = "/home/olpc/.sugar/default/org.laptop.TurtleArtActivity"
SVG
Some earlier OLPC builds (e.g., 656) use an older version of the gtk svg libraries that don't process svg files that use the <svg:tag> syntax. It seems that removing svg: resolves the rendering problem.
<svg:path> won't work <path> will work
Another issue is with SVG paths. Some SVG editors, e.g., inkscape, sometimes omit the l in a path that uses relative line-tos. These paths will not render properly on old OLPC builds.
<path d="m 100,100 10,10 /> won't work <path d="m 100,100 l 10,10 /> will work
In recent Fedora/Sugar builds (F13/0.88) another SVG problem has been occurring. If you define a path without explicitly defining stroke and fill colors, it will render as black, even if you define stroke and fill colors in your initial <svg> block.
<svg ... stroke="&stoke_color;" fill="&fill_color;" ... > <path ... /> won't work <path ... stroke="&stoke_color;" fill="&fill_color;" /> will work </svg>
artwork
Some Sugar icons are not present in old systems. If, for example, you want to use the filesave icon, you should include a copy in your bundle (in the icon subdirectory) to ensure that it is present on older systems.
Q: Is there a comprehensive list somewhere of which icons were added to sugar-artwork when?
tool tips
Older versions of Sugar did not support tool tips. You could catch the exception as per:
try: self.activity.fullscreen_button.props.accelerator = '<Alt>Enter' except AttributeError: pass
Note that this is only relevant to pre-0.86 toolbars.
screen size
The screen size varies on different hardware platforms. If you develop in an emulator, it is worthwhile trying different sizes to make sure your activity scales properly.
Some useful utilities:
width = gtk.gdk.screen_width() height = gtk.gdk.screen_height()
toolbox = activity.ActivityToolbox(self) toolboxheight = toolbox._activity_toolbar.size_request()[1]
import tarfile
At some point, the behavior of the Python tarfile library seems to have changed (I've not yet hunted down the documentation.) In any case, on Build 767, it was generating .tar suffixes and on later builds (newer Python libraries?) it was generating .gtar suffixes. I got burnt by this in Turtle Art so now I check for both.
if file_path.endswith(('.gtar', '.tar')):
Sugar toolbar version
Sugar toolbars changed in Sucrose v0.86. You can detect which version you are running by checking for an ImportError:
try: # 0.86 toolbar widgets from sugar.activity.widgets import ActivityToolbarButton, StopButton from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton has_toolbarbox = True except ImportError: has_toolbarbox = False
Use the flag to determine whether to create old-style or new toolbars:
if has_toolbarbox: # Use 0.86+ toolbar design toolbar_box = ToolbarBox() ... else: # Use pre-0.86 toolbar design self.toolbox = activity.ActivityToolbox(self) ...
You can share callbacks between versions, but take care to make sure you are using the proper context:
# 0.86+ fullscreen_button.connect('clicked', self._do_fullscreen_cb)
or
# pre-0.86 self.viewToolbar = ViewToolbar(self) ...
class ViewToolbar(gtk.Toolbar): def __init__(self, pc): self.activity = pc ...
self.activity.fullscreen_button.connect('clicked', self.activity._do_fullscreen_cb)
Python versions
Some Sugar systems are running on older versions of Python. Take care to make sure you don't run into syntax errors do to changes in the Python language. For example, I was burned on the following:
except Exception as e: # works fine with Python 2.6 but raises a syntax error with Python 2.5 except Exception, e: # works fine in both cases.
See python.org for more information on incompatibilities between versions.
GNOME toolkit versions
In older versions of gtk, e.g., 2.16.0, the set_size_request method does not work properly for label.
label = gtk.Label(string) label.set_line_wrap(True) label.set_size_request(width, -1)
Works fine on 2.22.0
I'll try to track down the relevant gtk patch.