Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/turtleconfusion.py
diff options
context:
space:
mode:
Diffstat (limited to 'turtleconfusion.py')
-rwxr-xr-xturtleconfusion.py96
1 files changed, 55 insertions, 41 deletions
diff --git a/turtleconfusion.py b/turtleconfusion.py
index 0cff962..e639e38 100755
--- a/turtleconfusion.py
+++ b/turtleconfusion.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#Copyright (c) 2007-8, Playful Invention Company
-#Copyright (c) 2008-11, Walter Bender
+#Copyright (c) 2008-12, Walter Bender
#Copyright (c) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
#Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -32,6 +32,7 @@ import os
import os.path
import cStringIO
import errno
+import ConfigParser
try:
# Try to use XDG Base Directory standard for config files.
@@ -51,8 +52,7 @@ import gettext
# from a git repository or the unzipped .xo file.
# gettext.bindtextdomain('org.laptop.TurtleArtActivity', 'locale')
-gettext.textdomain('org.laptop.TurtleArtActivity')
-_ = gettext.gettext
+import gettext
from TurtleArt.taconstants import OVERLAY_LAYER, DEFAULT_TURTLE_COLORS
from TurtleArt.tautils import data_to_string, data_from_string, get_save_name
@@ -64,13 +64,7 @@ from util.menubuilder import MenuBuilder
class TurtleMain():
- ''' Launch Turtle Art from outside of Sugar. '''
-
- _HELP_MSG = 'turtleart.py: ' + _('usage is') + '''
- \tturtleart.py
- \tturtleart.py project.ta
- \tturtleart.py --output_png project.ta
- \tturtleart.py -o project'''
+ ''' Launch Turtle Confusion from outside of Sugar. '''
_INSTALL_PATH = '/usr/share/sugar/activities/TurtleArt.activity'
_ALTERNATIVE_INSTALL_PATH = \
'/usr/local/share/sugar/activities/TurtleArt.activity'
@@ -78,12 +72,30 @@ class TurtleMain():
_GNOME_PLUGIN_SUBPATH = 'gnome_plugins'
def __init__(self):
+ self._abspath = os.path.abspath('.')
+ self._execdirname = self._get_execution_dir()
+ if self._execdirname is not None:
+ os.chdir(self._execdirname)
+ file_activity_info = ConfigParser.ConfigParser()
+ activity_info_path = os.path.abspath('./activity/activity.info')
+ file_activity_info.read(activity_info_path)
+ bundle_id = file_activity_info.get('Activity', 'bundle_id')
+ gettext.textdomain(bundle_id)
+ global _
+ _ = gettext.gettext
+ self._HELP_MSG = 'turtleart.py: ' + _('usage is') + '''
+ \tturtleconfusion.py
+ \tturtleconfusion.py project.ta
+ \tturtleconfusion.py --output_png project.ta
+ \tturtleconfusion.py -o project
+ \tturtleconfusion.py --run project.ta
+ \tturtleconfusion.py -r project'''
self._init_vars()
self._parse_command_line()
self._ensure_sugar_paths()
self._plugins = []
- if self.output_png:
+ if self._output_png:
# Fix me: We need to create a cairo surface to work with
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
gtk.gdk.screen_width(),
@@ -105,9 +117,9 @@ class TurtleMain():
def _get_gnome_plugin_home(self):
''' Use plugin directory associated with execution path. '''
- if os.path.exists(os.path.join(self._dirname,
+ if os.path.exists(os.path.join(self._execdirname,
self._GNOME_PLUGIN_SUBPATH)):
- return os.path.join(self._dirname, self._GNOME_PLUGIN_SUBPATH)
+ return os.path.join(self._execdirname, self._GNOME_PLUGIN_SUBPATH)
else:
return None
@@ -162,22 +174,23 @@ class TurtleMain():
''' Get a main window set up. '''
self.win.connect('configure_event', self.tw.update_overlay_position)
self.tw.parent = self.win
- if self.ta_file is None:
+ if self._ta_file is None:
self.tw.load_start()
else:
- print self.ta_file
- self.tw.load_start(self.ta_file)
+ print self._ta_file
+ self.tw.load_start(self._ta_file)
self.tw.lc.trace = 0
- self.tw.run_button(0)
+ if self._run_on_launch:
+ self._do_run_cb()
gtk.main()
def _draw_and_quit(self):
''' Non-interactive mode: run the project, save it to a file
and quit. '''
- self.tw.load_start(self.ta_file)
+ self.tw.load_start(self._ta_file)
self.tw.lc.trace = 0
self.tw.run_button(0)
- self.tw.save_as_image(self.ta_file)
+ self.tw.save_as_image(self._ta_file)
def _build_window(self, interactive=True):
''' Initialize the TurtleWindow instance. '''
@@ -193,18 +206,15 @@ class TurtleMain():
self.turtle_canvas = surface.create_similar(
cairo.CONTENT_COLOR, gtk.gdk.screen_width() * 2,
gtk.gdk.screen_height() * 2)
- self.tw = TurtleArtWindow(self.canvas, self._dirname,
+ self.tw = TurtleArtWindow(self.canvas, self._execdirname,
turtle_canvas=self.turtle_canvas)
self.tw.save_folder = os.path.expanduser('~')
def _init_vars(self):
''' If we are invoked to start a project from Gnome, we should make
sure our current directory is TA's source dir. '''
- self._dirname = self._get_execution_dir()
- if self._dirname is not None:
- os.chdir(self._dirname)
- self.ta_file = None
- self.output_png = False
+ self._ta_file = None
+ self._output_png = False
self.i = 0 # FIXME: use a better name for this variable
self.scale = 2.0
self.tw = None
@@ -212,32 +222,35 @@ class TurtleMain():
def _parse_command_line(self):
''' Try to make sense of the command-line arguments. '''
try:
- opts, args = getopt.getopt(argv[1:], 'ho',
- ['help', 'output_png'])
+ opts, args = getopt.getopt(argv[1:], 'hor',
+ ['help', '_output_png', 'run'])
except getopt.GetoptError, err:
print str(err)
print self._HELP_MSG
sys.exit(2)
+ self._run_on_launch = False
for o, a in opts:
if o in ('-h', '--help'):
print self._HELP_MSG
sys.exit()
if o in ('-o', '--output_png'):
- self.output_png = True
+ self._output_png = True
+ elif o in ('-r', '--run'):
+ self._run_on_launch = True
else:
assert False, _('No option action:') + ' ' + o
if args:
- self.ta_file = args[0]
+ self._ta_file = args[0]
- if len(args) > 1 or self.output_png and self.ta_file is None:
+ if len(args) > 1 or self._output_png and self._ta_file is None:
print self._HELP_MSG
sys.exit()
- if self.ta_file is not None:
- if not self.ta_file.endswith(('.ta')):
- self.ta_file += '.ta'
- if not os.path.exists(self.ta_file):
- assert False, ('%s: %s' % (self.ta_file, _('File not found')))
+ if self._ta_file is not None:
+ if not self._ta_file.endswith(('.ta')):
+ self._ta_file += '.ta'
+ if not os.path.exists(self._ta_file):
+ assert False, ('%s: %s' % (self._ta_file, _('File not found')))
def _ensure_sugar_paths(self):
''' Make sure Sugar paths are present. '''
@@ -286,8 +299,8 @@ class TurtleMain():
win.move(self.x, self.y)
win.maximize()
win.set_title(_('Turtle Art'))
- if os.path.exists(os.path.join(self._dirname, self._ICON_SUBPATH)):
- win.set_icon_from_file(os.path.join(self._dirname,
+ if os.path.exists(os.path.join(self._execdirname, self._ICON_SUBPATH)):
+ win.set_icon_from_file(os.path.join(self._execdirname,
self._ICON_SUBPATH))
win.connect('delete_event', self._quit_ta)
@@ -367,7 +380,6 @@ class TurtleMain():
MenuBuilder.make_menu_item(menu, _('Clean'), self._do_eraser_cb)
MenuBuilder.make_menu_item(menu, _('Run'), self._do_run_cb)
MenuBuilder.make_menu_item(menu, _('Step'), self._do_step_cb)
- MenuBuilder.make_menu_item(menu, _('Debug'), self._do_trace_cb)
MenuBuilder.make_menu_item(menu, _('Stop'), self._do_stop_cb)
turtle_menu = MenuBuilder.make_sub_menu(menu, _('Turtle'))
@@ -545,24 +557,26 @@ class TurtleMain():
def _do_run_cb(self, widget):
''' Callback for run button (rabbit). '''
self.tw.lc.trace = 0
- self.tw.run_button(0)
+ self.tw.hideblocks()
+ self.tw.run_button(0, running_from_button_push=True)
return
def _do_step_cb(self, widget):
''' Callback for step button (turtle). '''
self.tw.lc.trace = 0
- self.tw.run_button(3)
+ self.tw.run_button(3, running_from_button_push=True)
return
def _do_trace_cb(self, widget):
''' Callback for debug button (bug). '''
self.tw.lc.trace = 1
- self.tw.run_button(6)
+ self.tw.run_button(9, running_from_button_push=True)
return
def _do_stop_cb(self, widget):
''' Callback for stop button. '''
self.tw.lc.trace = 0
+ self.tw.showblocks()
self.tw.stop_button()
return