Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArt/tabasics.py14
-rw-r--r--TurtleArt/talogo.py5
-rw-r--r--TurtleArt/tapalette.py4
-rw-r--r--TurtleArt/taprimitive.py14
-rw-r--r--TurtleArt/taturtle.py1
-rw-r--r--TurtleArt/tatype.py2
-rw-r--r--TurtleArt/tawindow.py22
-rw-r--r--TurtleArtActivity.py29
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py4
-rwxr-xr-xsetup.py4
-rwxr-xr-xturtleblocks.py5
11 files changed, 73 insertions, 31 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 3d88ce4..d66345b 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -198,7 +198,8 @@ turtle'))
Primitive(self.tw.lc.clear_value_blocks),
Primitive(self.tw.lc.reset_internals),
Primitive(self.tw.canvas.clearscreen),
- Primitive(self.tw.turtles.reset_turtles)
+ Primitive(self.tw.turtles.reset_turtles),
+ Primitive(self.tw.lc.active_turtle)
])]))
palette.add_block('left',
@@ -445,7 +446,8 @@ in place of a number block)'),
value_block=True,
prim_name='shade',
logo_command=':shade')
- self.tw.lc.def_prim('shade', 0, Primitive(Turtle.get_shade))
+ self.tw.lc.def_prim('shade', 0,
+ Primitive(Turtle.get_shade, return_type=TYPE_NUMBER))
palette.add_block('gray',
style='box-style',
@@ -894,7 +896,7 @@ number of seconds'))
style='clamp-style',
label=_('forever'),
prim_name='forever',
- default=[None, None],
+ default=[None],
logo_command='forever',
help_string=_('loops forever'))
self.tw.lc.def_prim(
@@ -908,7 +910,7 @@ number of seconds'))
style='clamp-style-1arg',
label=_('repeat'),
prim_name='repeat',
- default=[4, None, None],
+ default=[4, None],
logo_command='repeat',
special_name=_('repeat'),
help_string=_('loops specified number of times'))
@@ -926,7 +928,7 @@ number of seconds'))
style='clamp-style-boolean',
label=[_('if'), _('then'), ''],
prim_name='if',
- default=[None, None, None],
+ default=[None, None],
special_name=_('if then'),
logo_command='if',
help_string=_('if-then operator that uses boolean \
@@ -942,7 +944,7 @@ operators from Numbers palette'))
style='clamp-style-else',
label=[_('if'), _('then'), _('else')],
prim_name='ifelse',
- default=[None, None, None, None],
+ default=[None, None, None],
logo_command='ifelse',
special_name=_('if then else'),
help_string=_('if-then-else operator that uses \
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 775af0f..ba76085 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -735,6 +735,11 @@ class LogoCode:
""" Stop execution of a stack """
self.procstop = True
+ def active_turtle(self):
+ ''' NOP used to add get_active_turtle to Python export '''
+ # turtle = self.tw.turtles.get_turtle()
+ pass
+
def prim_turtle(self, name):
self.tw.turtles.set_turtle(name)
diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py
index 9332155..fd8fac7 100644
--- a/TurtleArt/tapalette.py
+++ b/TurtleArt/tapalette.py
@@ -176,7 +176,7 @@ class Palette():
logo_command=None, hidden=False, colors=None,
string_or_number=False):
""" Add a new block to the palette """
- block = Block(block_name)
+ block = _ProtoBlock(block_name)
block.set_style(style)
if label is not None:
block.set_label(label)
@@ -251,7 +251,7 @@ def define_logo_function(key, value):
logo_functions[key] = value
-class Block():
+class _ProtoBlock():
""" a class for defining new block primitives """
def __init__(self, name):
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index b689de5..197a8d8 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -373,7 +373,15 @@ class Primitive(object):
loop_ast = ast.While(test=condition_ast,
body=new_arg_asts[1],
orelse=[])
- return loop_ast
+ # Until always executes its body once.
+ if controller == Primitive.controller_until:
+ loop_list = []
+ for arg_ast in new_arg_asts[1]:
+ loop_list.append(arg_ast)
+ loop_list.append(loop_ast)
+ return loop_list
+ else:
+ return loop_ast
# conditionals
elif self in (LogoCode.prim_if, LogoCode.prim_ifelse):
@@ -494,6 +502,10 @@ class Primitive(object):
return [get_call_ast('logo.prim_turtle', new_arg_asts),
ast_extensions.ExtraCode(text)]
+ elif self == LogoCode.active_turtle:
+ text = 'turtle = turtles.get_active_turtle()'
+ return ast_extensions.ExtraCode(text)
+
# comment
elif self == Primitive.comment:
if isinstance(new_arg_asts[0], ast.Str):
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index c35125b..11336d7 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -653,7 +653,6 @@ class Turtle:
def draw_pixbuf(self, pixbuf, a, b, x, y, w, h, path, share=True):
''' Draw a pixbuf '''
-
self._turtles.turtle_window.canvas.draw_pixbuf(
pixbuf, a, b, x, y, w, h, self._heading)
diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py
index 3ca47b9..0fcfc3c 100644
--- a/TurtleArt/tatype.py
+++ b/TurtleArt/tatype.py
@@ -439,5 +439,3 @@ def get_call_ast(func_name, args=None, kwargs=None, return_type=None):
else:
return TypedCall(func=func_ast, args=args, keywords=keywords,
return_type=return_type)
-
-
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index c5ab0c6..81b1251 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1640,10 +1640,7 @@ before making changes to your program'))
elif blk.name == 'restore':
self.restore_latest_from_trash()
elif blk.name == 'empty':
- if self.running_sugar:
- self.activity.empty_trash_alert()
- else:
- self.empty_trash()
+ self.empty_trash()
elif blk.name == 'trashall':
for b in self.just_blocks():
if b.type != 'trash':
@@ -2203,10 +2200,26 @@ before making changes to your program'))
def empty_trash(self):
''' Permanently remove all blocks presently in the trash can. '''
+ title = _('empty trash')
+ msg = _('Do you really want to empty the trash?')
+ if self.running_sugar:
+ self.activity.empty_trash_alert(title, msg)
+ else:
+ dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK_CANCEL, msg)
+ dialog.set_title(title)
+ res = dialog.run()
+ dialog.destroy()
+ if res == gtk.RESPONSE_OK:
+ self._empty_trash()
+
+ def _empty_trash(self):
for blk in self.block_list.list:
if blk.type == 'trash':
blk.type = 'deleted'
blk.spr.hide()
+ for blk in self.block_list.list:
+ if blk.type == 'deleted':
+ self.block_list.list.remove(blk)
self.trash_stack = []
if 'trash' in palette_names:
self.show_toolbar_palette(palette_names.index('trash'),
@@ -3686,6 +3699,7 @@ before making changes to your program'))
self.keyboard = KEY_DICT[self.keypress]
else:
self.keyboard = 0
+ self.keypress = ''
def get_keyboard(self):
""" Return cached keyboard input """
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 47627ef..f15650e 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -82,6 +82,7 @@ if HAS_TOOLBARBOX:
class TurtleArtActivity(activity.Activity):
''' Activity subclass for Turtle Art '''
_HOVER_HELP = '/desktop/sugar/activities/turtleart/hoverhelp'
+ _ORIENTATION = '/desktop/sugar/activities/turtleart/orientation'
_COORDINATE_SCALE = '/desktop/sugar/activities/turtleart/coordinatescale'
def __init__(self, handle):
@@ -108,12 +109,7 @@ class TurtleArtActivity(activity.Activity):
self._setup_toolbar()
_logger.debug('_setup_canvas')
- self._canvas = self._setup_canvas(self._setup_scrolled_window())
-
- # FIX ME: not sure how or why self.canvas gets overwritten
- # It is set to self.sw in _setup_canvas but None here.
- # We need self.canvas for generating the preview image
- self.canvas = self.sw
+ self._setup_canvas(self._setup_scrolled_window())
_logger.debug('_setup_palette_toolbar')
self._setup_palette_toolbar()
@@ -166,14 +162,23 @@ class TurtleArtActivity(activity.Activity):
self.init_complete = True
def update_palette_from_metadata(self):
+ if HAS_GCONF:
+ # We have to wait to set the orientation for the palettes
+ # to be loaded.
+ self.client = gconf.client_get_default()
+ if self.client.get_int(self._ORIENTATION) == 1:
+ self.tw.set_orientation(1)
+
if 'palette' in self.metadata:
n = int(self.metadata['palette'])
if n == -1:
self.tw.hideshow_palette(False)
else:
- # Set radio button to active
+ # Try to set radio button to active
if n < len(self.palette_buttons):
self.palette_buttons[n].set_active(True)
+ else:
+ self.tw.show_palette(n=0)
if 'orientation' in self.metadata:
self.tw.set_orientation(int(self.metadata['orientation']))
else:
@@ -1320,6 +1325,8 @@ class TurtleArtActivity(activity.Activity):
else:
self.metadata['palette'] = '-1'
self.metadata['orientation'] = str(self.tw.orientation)
+ if HAS_GCONF:
+ self.client.set_int(self._ORIENTATION, self.tw.orientation)
if len(self.error_list) > 0:
errors = []
if 'error_list' in self.metadata:
@@ -1627,17 +1634,17 @@ in order to use the plugin.'))
self._old_cursor = self.get_window().get_cursor()
self.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1))
- def empty_trash_alert(self):
+ def empty_trash_alert(self, title, msg):
''' We get confirmation from the user before emptying the trash '''
alert = ConfirmationAlert()
- alert.props.title = _('empty trash')
- alert.props.msg = _('Do you really want to empty the trash?')
+ alert.props.title = title
+ alert.props.msg = msg
def _empty_trash_alert_response_cb(alert, response_id, self):
if response_id is gtk.RESPONSE_OK:
_logger.debug('emptying the trash')
self.remove_alert(alert)
- self.tw.empty_trash()
+ self.tw._empty_trash()
elif response_id is gtk.RESPONSE_CANCEL:
_logger.debug('cancel emptying the trash')
self.remove_alert(alert)
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index 1e9b2e4..df0d1ff 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -75,7 +75,7 @@ class Turtle_blocks_extras(Plugin):
style='clamp-style-boolean',
label=_('while'),
prim_name='while',
- default=[None, None, None],
+ default=[None, None],
special_name=_('while'),
help_string=_('do-while-True operator that uses \
boolean operators from Numbers palette'))
@@ -96,7 +96,7 @@ boolean operators from Numbers palette'))
style='clamp-style-boolean',
label=_('until'),
prim_name='until',
- default=[None, None, None],
+ default=[None, None],
special_name=_('until'),
help_string=_('do-until-True operator that uses \
boolean operators from Numbers palette'))
diff --git a/setup.py b/setup.py
index e5026ee..6877cb5 100755
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-import os
+
import sys
if len(sys.argv) > 1 and '--no-sugar' == sys.argv[1]:
@@ -7,7 +7,7 @@ if len(sys.argv) > 1 and '--no-sugar' == sys.argv[1]:
# for distutils
sys.argv.pop(1)
- import glob, os.path, string
+ import glob
from distutils.core import setup
DATA_FILES = [
diff --git a/turtleblocks.py b/turtleblocks.py
index d8bd71b..7e3aba4 100755
--- a/turtleblocks.py
+++ b/turtleblocks.py
@@ -71,6 +71,7 @@ class TurtleMain():
_ICON_SUBPATH = 'images/turtle.png'
_GNOME_PLUGIN_SUBPATH = 'gnome_plugins'
_HOVER_HELP = '/desktop/sugar/activities/turtleart/hoverhelp'
+ _ORIENTATION = '/desktop/sugar/activities/turtleart/orientation'
_COORDINATE_SCALE = '/desktop/sugar/activities/turtleart/coordinatescale'
def __init__(self):
@@ -240,6 +241,8 @@ return %s(self)" % (p, P, P)
self.tw.coord_scale = 1
else:
self.tw.coord_scale = 0
+ if self.client.get_int(self._ORIENTATION) == 1:
+ self.tw.orientation = 1
def _set_gconf_overrides(self):
if self.tw.coord_scale == 0:
@@ -492,6 +495,8 @@ return %s(self)" % (p, P, P)
elif resp == gtk.RESPONSE_CANCEL:
return
+ self.client.set_int(self._ORIENTATION, self.tw.orientation)
+
for plugin in self.tw.turtleart_plugins:
if hasattr(plugin, 'quit'):
plugin.quit()