Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArtActivity.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-05-25 22:12:48 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-05-25 22:12:48 (GMT)
commit29851fcbe3b4d392efd5a873f92666da27ec0e99 (patch)
tree27ce347b8465c907836a116d8752ddb7fab48c69 /TurtleArtActivity.py
parented303715f77f79e697e33b3d0df082843ffc1492 (diff)
patches to create confusion
Diffstat (limited to 'TurtleArtActivity.py')
-rw-r--r--TurtleArtActivity.py129
1 files changed, 128 insertions, 1 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 268f703..d9c89d7 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -43,6 +43,10 @@ from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.alert import (ConfirmationAlert, NotifyAlert)
from sugar.graphics import style
+from sugar.graphics.combobox import ComboBox
+from sugar.graphics.toolcombobox import ToolComboBox
+from sugar.graphics.objectchooser import ObjectChooser
+from sugar import mime
from sugar.datastore import datastore
from sugar import profile
@@ -90,6 +94,9 @@ class TurtleArtActivity(activity.Activity):
self._check_ver_change(get_path(activity, 'data'))
self.connect("notify::active", self._notify_active_cb)
+ self._level = 0
+ self._custom_filepath = None
+
self.has_toolbarbox = HAS_TOOLBARBOX
_logger.debug('_setup_toolbar')
self._setup_toolbar()
@@ -292,8 +299,10 @@ class TurtleArtActivity(activity.Activity):
return
if not self.has_toolbarbox:
self.palette_buttons[i].set_icon(palette_names[i] + 'on')
+ '''
else:
self._help_button.set_current_palette(palette_names[i])
+ '''
self.tw.show_palette(n=i)
self.do_showpalette()
@@ -341,6 +350,13 @@ class TurtleArtActivity(activity.Activity):
self.tw.eraser_button()
gobject.timeout_add(250, self.eraser_button.set_icon, 'eraseron')
+ def restore_challenge(self):
+ ''' Restore the current challange after a clear screen '''
+ if self._custom_filepath is None:
+ self._load_level()
+ else:
+ self._load_level(custom=True)
+
def do_run_cb(self, button):
''' Callback for run button (rabbit) '''
self.run_button.set_icon('run-faston')
@@ -500,6 +516,14 @@ class TurtleArtActivity(activity.Activity):
# Given the change in how overlays are handled (v123), there is no way
# to erase and then redraw the overlays.
+ def _do_help_cb(self, button):
+ if os.path.exists(os.path.join(
+ activity.get_bundle_path(), 'challenges',
+ 'help-' + str(self._level + 1) + '.ta')):
+ self.read_file(os.path.join(
+ activity.get_bundle_path(), 'challenges',
+ 'help-' + str(self._level + 1) + '.ta'))
+
def get_document_path(self, async_cb, async_err_cb):
''' View TA code as part of view source. '''
ta_code_path = self._dump_ta_code()
@@ -597,7 +621,11 @@ class TurtleArtActivity(activity.Activity):
self.palette_toolbar_button = ToolbarButton(
page=self._palette_toolbar, icon_name='palette')
- self._help_button = HelpButton(self)
+ self._help_button = self._add_button('help-toolbar',
+ _('Help'),
+ self._do_help_cb,
+ None)
+ # self._help_button = HelpButton(self)
self._make_load_save_buttons(self.activity_toolbar_button)
@@ -852,6 +880,9 @@ class TurtleArtActivity(activity.Activity):
self._overflow_box.remove(button)
if self._overflow_palette_button in self._palette_toolbar:
self._palette_toolbar.remove(self._overflow_palette_button)
+ if hasattr(self, '_levels_combo') and \
+ self._levels_tool in self._palette_toolbar:
+ self._palette_toolbar.remove(self._levels_tool)
for i in range(len(self.palette_buttons)):
if i < max_palettes:
@@ -870,6 +901,8 @@ class TurtleArtActivity(activity.Activity):
if self.tw.hw in [XO1, XO15, XO175, XO4]:
self._make_palette_buttons(self._palette_toolbar)
'''
+ self._make_confusion_combo(self._palette_toolbar)
+
self._palette_toolbar.show()
self._overflow_box.show_all()
self._overflow_palette.set_content(self._overflow_sw)
@@ -992,6 +1025,17 @@ class TurtleArtActivity(activity.Activity):
self._palette.popdown(immediate=True)
return
+ def _make_confusion_combo(self, toolbar):
+ if hasattr(self, '_levels_tools'):
+ toolbar.insert(self._levels_tools, -1)
+ else:
+ self._levels = self._get_levels(activity.get_bundle_path())
+ self._levels_combo, self._levels_tool = \
+ self._combo_factory(self._levels,
+ _('Select a challenge'),
+ toolbar,
+ self._levels_cb)
+
def _make_palette_buttons(self, toolbar, palette_button=False):
''' Creates the palette and block buttons for both toolbar types'''
if palette_button: # old-style toolbars need this button
@@ -1508,6 +1552,89 @@ in order to use the plugin.'))
help_strings[name] = tooltip
return button
+ def _combo_factory(self, options, tooltip, toolbar, callback, default=0):
+ ''' Combo box factory '''
+ combo = ComboBox()
+ if hasattr(combo, 'set_tooltip_text'):
+ combo.set_tooltip_text(tooltip)
+ combo.connect('changed', callback)
+ for i, option in enumerate(options):
+ combo.append_item(i, option.replace('-', ' '), None)
+ combo.set_active(default)
+ combo.show()
+ tool = ToolComboBox(combo)
+ tool.show()
+ if hasattr(toolbar, 'insert'):
+ toolbar.insert(tool, -1)
+ else:
+ toolbar.props.page.insert(tool, -1)
+ return combo, tool
+
+ def _get_levels(self, path):
+ ''' Look for level files in lessons directory. '''
+ level_files = []
+ """
+ if path is not None:
+ candidates = os.listdir(os.path.join(path, 'challenges'))
+ for filename in candidates:
+ level_files.append(filename.split('.')[0])
+ """
+ for i in range(40):
+ level_files.append('confusion-%d' % (i+1))
+
+ '''
+ '''
+ self.offsets = {}
+ offset_fd = open(os.path.join(activity.get_bundle_path(), 'challenges',
+ 'offsets'))
+ for line in offset_fd:
+ try:
+ idx, offsets = line.strip('\n').split(':')
+ xoffset, yoffset = offsets.split(',')
+ self.offsets[int(idx)] = (int(xoffset), int(yoffset))
+ except ValueError:
+ pass
+ offset_fd.close()
+ return level_files
+
+ def _levels_cb(self, combobox=None):
+ ''' The combo box has changed. '''
+ if hasattr(self, '_levels_combo'):
+ i = self._levels_combo.get_active()
+ if i != -1: # and i != self._level:
+ self._level = i
+ self._load_level()
+ self._custom_filepath = None
+
+ def _load_level(self, custom=False):
+ self.tw.canvas.clearscreen()
+ if custom:
+ self.tw.canvas.setxy(0, 0, pendown=False)
+ self.tw.lc.insert_image(center=True,
+ filepath=self._custom_filepath,
+ resize=True, offset=False)
+ else:
+ self.tw.canvas.setxy(int(-gtk.gdk.screen_width() / 2), 0,
+ pendown=False)
+ self.tw.lc.insert_image(center=False, resize=False,
+ filepath=os.path.join(
+ activity.get_bundle_path(), 'images',
+ 'turtle-a.png'))
+ # Slight offset to account for stroke width
+ if self._level + 1 in self.offsets:
+ xoffset = self.offsets[self._level + 1][0]
+ yoffset = self.offsets[self._level + 1][1]
+ else:
+ xoffset = 0
+ yoffset = 0
+ self.tw.canvas.setxy(-2.5 + xoffset, -2.5 + yoffset, pendown=False)
+ self.tw.lc.insert_image(center=False,
+ filepath=os.path.join(
+ activity.get_bundle_path(), 'challenges',
+ self._levels[self._level] + '.svg'), resize=False,
+ offset=True)
+ self.tw.canvas.setxy(0, 0, pendown=False)
+
def _radio_button_factory(self, button_name, toolbar, cb, arg, tooltip,
group, position=-1):
''' Add a radio button to a toolbar '''