Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tablock.py21
-rw-r--r--taconstants.py31
-rw-r--r--tajail.py2
-rw-r--r--talogo.py9
-rw-r--r--tawindow.py57
5 files changed, 85 insertions, 35 deletions
diff --git a/tablock.py b/tablock.py
index 3f4478b..ec6d99c 100644
--- a/tablock.py
+++ b/tablock.py
@@ -298,8 +298,10 @@ class Block:
self._make_basic_style_1arg(svg)
elif self.name in BASIC_STYLE_2ARG:
self._make_basic_style_2arg(svg)
- elif self.name in BULLET_STYLE:
+ elif self.name in BASIC_STYLE_VAR_ARG:
self._make_basic_style_var_arg(svg)
+ elif self.name in BULLET_STYLE:
+ self._make_bullet_style(svg)
elif self.name in BOX_STYLE:
self._make_box_style(svg)
elif self.name in BOX_STYLE_MEDIA:
@@ -422,6 +424,23 @@ class Block:
def _make_basic_style_var_arg(self, svg):
self.svg.expand(10+self.dx+self.ex, self.ey)
+ innie = [True]
+ for i in range(self._ei):
+ innie.append(True)
+ self.svg.set_innie(innie)
+ self._make_basic_block(svg)
+ self.docks = [['flow', True, self.svg.docks[0][0],
+ self.svg.docks[0][1]],
+ ['number', False, self.svg.docks[1][0],
+ self.svg.docks[1][1]]]
+ for i in range(self._ei):
+ self.docks.append(['number', False, self.svg.docks[i+2][0],
+ self.svg.docks[i+2][1]])
+ self.docks.append(['flow', False, self.svg.docks[self._ei+2][0],
+ self.svg.docks[self._ei+2][1]])
+
+ def _make_bullet_style(self, svg):
+ self.svg.expand(10+self.dx+self.ex, self.ey)
innie = [True, True]
for i in range(self._ei):
innie.append(True)
diff --git a/taconstants.py b/taconstants.py
index e102c47..0e0729d 100644
--- a/taconstants.py
+++ b/taconstants.py
@@ -124,8 +124,9 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right',
'storeinbox1', 'storeinbox2', 'string', 'box1', 'box2', 'box',
'storein', 'start'],
['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap',
- 'myfunc1arg', 'nop', 'addturtle', 'comment', 'print', 'cartesian',
- 'width','height', 'polar', 'sandwichtop', 'sandwichbottom'],
+ 'myfunc1arg', 'userdefined', 'addturtle', 'comment', 'print',
+ 'cartesian', 'width', 'height', 'polar', 'sandwichtop',
+ 'sandwichbottom'],
['journal', 'audio', 'description', 'savepix', 'hideblocks',
'showblocks', 'fullscreen', 'picturelist', 'picture1x1a',
'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2'],
@@ -174,6 +175,8 @@ BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', 'image',
'settextsize', 'settextcolor', 'print', 'wait', 'storeinbox1', 'savepix',
'storeinbox2', 'wait', 'stack', 'push', 'nop', 'addturtle', 'comment',
'savesvg']
+BASIC_STYLE_VAR_ARG = ['userdefined', 'userdefined2args', 'userdefined3args']
+BULLET_STYLE = ['templatelist', 'list']
BASIC_STYLE_2ARG = ['arc', 'setxy', 'fillscreen', 'storein', 'write']
BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade',
'textcolor', 'textsize', 'box1', 'box2', 'string', 'leftpos', 'scale',
@@ -203,7 +206,6 @@ COLLAPSIBLE_BOTTOM = ['sandwichbottom']
# Depreciated block styles
PORTFOLIO_STYLE_2x2 = ['template2x2']
-BULLET_STYLE = ['templatelist', 'list']
PORTFOLIO_STYLE_1x1 = ['template1x1', 'template1x1a']
PORTFOLIO_STYLE_2x1 = ['template2x1']
PORTFOLIO_STYLE_1x2 = ['template1x2']
@@ -212,7 +214,8 @@ PORTFOLIO_STYLE_1x2 = ['template1x2']
# Blocks that are expandable
#
EXPANDABLE = ['vspace', 'hspace', 'templatelist', 'list', 'identity2',
- 'myfunc1arg', 'myfunc2arg', 'myfunc3arg']
+ 'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'userdefined',
+ 'userdefined2args', 'userdefined3args']
#
# Blocks that are 'collapsible'
@@ -232,7 +235,10 @@ CONTENT_BLOCKS = ['number', 'string', 'description', 'audio', 'journal']
#
# These blocks get a special skin
#
-BLOCKS_WITH_SKIN = ['journal', 'audio', 'description', 'nop']
+BLOCKS_WITH_SKIN = ['journal', 'audio', 'description', 'nop', 'userdefined',
+ 'userdefined2args', 'userdefined3args']
+
+PYTHON_SKIN = ['nop', 'userdefined', 'userdefined2args', 'userdefined3args']
#
# Block-name dictionary used for labels
@@ -364,6 +370,9 @@ BLOCK_NAMES = {
'topy':[_('picture top')],
'turtle':[_('turtle')],
'until':[_('until')],
+ 'userdefined':[_(' ')],
+ 'userdefined2args':[_(' ')],
+ 'userdefined3args':[_(' ')],
'voltage':[_('voltage')],
'volume':[_('volume')],
'vspace':[' '],
@@ -491,6 +500,9 @@ PRIMITIVES = {
'titley':'titley',
'toppos':'tpos',
'topy':'topy',
+ 'userdefined':'userdefined',
+ 'userdefined2args':'userdefined2',
+ 'userdefined3args':'userdefined3',
'voltage':'voltage',
'volume':'volume',
'vspace':'nop',
@@ -558,6 +570,9 @@ DEFAULTS = {
'template2x1':[_('Title'), 'None', 'None'],
'template2x2':[_('Title'), 'None', 'None', 'None', 'None'],
'templatelist':[_('Title'), '∙ '],
+ 'userdefined':[100],
+ 'userdefined2args':[100,100],
+ 'userdefined3args':[100,100,100],
'wait':[1],
'write':[_('text'), 32]}
@@ -569,7 +584,8 @@ STRING_OR_NUMBER_ARGS = ['plus2', 'equal2', 'less2', 'greater2', 'box',
'template2x2', 'template1x1a', 'templatelist', 'nop',
'print', 'stack', 'hat', 'addturtle', 'myfunc',
'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'comment',
- 'sandwichtop', 'sandwichtop2']
+ 'sandwichtop', 'sandwichtop2', 'userdefined',
+ 'userdefined2args','userdefined3args']
CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1',
'storeinbox2']
@@ -787,6 +803,9 @@ HELP_STRINGS = {
'trash':_("Trashcan"),
'turtle':_("Palette of turtle commands"),
'until':_("do-until-True operator that uses boolean operators from Numbers palette"),
+ 'userdefined':_("runs code found in the tamyblock.py module found in the Journal"),
+ 'userdefined2args':_("runs code found in the tamyblock.py module found in the Journal"),
+ 'userdefined3args':_("runs code found in the tamyblock.py module found in the Journal"),
'voltage':_("sensor voltage"),
'volume':_("microphone input volume"),
'vspace':_("jogs stack down"),
diff --git a/tajail.py b/tajail.py
index 9954eb3..366bd62 100644
--- a/tajail.py
+++ b/tajail.py
@@ -56,5 +56,5 @@ def myfunc(f, args):
def myfunc_import(lc, f, x):
userdefined = {}
exec f in globals(), userdefined
- return userdefined['myblock'](lc,x)
+ return userdefined['myblock'](lc, x)
diff --git a/talogo.py b/talogo.py
index 65f1741..1863d17 100644
--- a/talogo.py
+++ b/talogo.py
@@ -374,7 +374,9 @@ class LogoCode:
'topy':[0, lambda self: self.tw.topy],
'tpos':[0, lambda self: self.tw.canvas.height/(self.tw.coord_scale*2)],
'turtle':[1, lambda self, x: self.tw.canvas.set_turtle(x)],
- 'userdefined':[1, lambda self,x: self.prim_myblock(x)],
+ 'userdefined':[1, lambda self,x: self.prim_myblock([x])],
+ 'userdefined2':[2, lambda self,x,y: self.prim_myblock([x,y])],
+ 'userdefined3':[3, lambda self,x,y,z: self.prim_myblock([x,y,z])],
'video':[1, lambda self,x: self.play_movie(x)],
'vres':[0, lambda self: self.tw.canvas.height/self.tw.coord_scale],
'wait':[1, self.prim_wait, True],
@@ -930,7 +932,10 @@ class LogoCode:
def prim_myblock(self, x):
if self.tw.myblock is not None:
try:
- y = myfunc_import(self, self.tw.myblock, x)
+ if len(x) == 1:
+ y = myfunc_import(self, self.tw.myblock, x[0])
+ else:
+ y = myfunc_import(self, self.tw.myblock, x)
except:
raise logoerror("#nocode")
else:
diff --git a/tawindow.py b/tawindow.py
index a88d119..68753c7 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -307,7 +307,7 @@ class TurtleArtWindow():
"""
def set_userdefined(self):
for blk in self.just_blocks():
- if blk.name == 'nop':
+ if blk.name in PYTHON_SKIN:
x, y = self._calc_image_offset('pythonon', blk.spr)
blk.set_image(self.media_shapes['pythonon'], x, y)
self._resize_skin(blk)
@@ -555,7 +555,7 @@ class TurtleArtWindow():
self._proto_skin(name[8:], n, i)
elif name[:7] == 'picture':
self._proto_skin(name[7:], n, i)
- elif name == 'nop':
+ elif name in PYTHON_SKIN:
self._proto_skin('pythonsmall', n, i)
self._layout_palette(n)
@@ -983,7 +983,7 @@ class TurtleArtWindow():
'block', [], self.block_scale)
# Add a 'skin' to some blocks
- if name == 'nop':
+ if name in PYTHON_SKIN:
if self.nop == 'pythonloaded':
self._block_skin('pythonon', newblk)
else:
@@ -1405,7 +1405,7 @@ class TurtleArtWindow():
if b != blk:
b.spr.move_relative((0, dy*blk.scale))
self._grow_stack_arm(self._find_sandwich_top(blk))
- elif blk.name in EXPANDABLE:
+ elif blk.name in EXPANDABLE or blk.name == 'nop':
if self._show_button_hit(blk.spr, x, y):
n = len(blk.connections)
group = self._find_group(blk.connections[n-1])
@@ -1420,6 +1420,14 @@ class TurtleArtWindow():
dy = blk.add_arg(False)
blk.primitive = 'myfunction3'
blk.name = 'myfunc3arg'
+ elif blk.name == 'userdefined':
+ dy = blk.add_arg()
+ blk.primitive = 'userdefined2'
+ blk.name = 'userdefined2args'
+ elif blk.name == 'userdefined2args':
+ dy = blk.add_arg(False)
+ blk.primitive = 'userdefined3'
+ blk.name = 'userdefined3args'
else:
dy = blk.add_arg()
for b in group:
@@ -1438,6 +1446,8 @@ class TurtleArtWindow():
argblk.connections = [blk, None]
blk.connections[n-1] = argblk
self._grow_stack_arm(self._find_sandwich_top(blk))
+ elif blk.name in PYTHON_SKIN and self.myblock==None:
+ self._import_py()
else:
self._run_stack(blk)
elif blk.name in COLLAPSIBLE:
@@ -1446,8 +1456,6 @@ class TurtleArtWindow():
self._restore_stack(top)
elif top is not None:
self._collapse_stack(top)
- elif blk.name=='nop' and self.myblock==None:
- self._import_py()
else:
self._run_stack(blk)
@@ -2393,12 +2401,7 @@ class TurtleArtWindow():
# Some blocks get transformed.
if btype == 'string':
blk.spr.set_label(blk.values[0].replace('\n', RETURN))
- elif btype == 'nop':
- if self.nop == 'pythonloaded':
- self._block_skin('pythonon', blk)
- else:
- self._block_skin('pythonoff', blk)
- elif btype in EXPANDABLE:
+ elif btype in EXPANDABLE or btype == 'nop':
if btype == 'vspace':
if value is not None:
blk.expand_in_y(value)
@@ -2408,10 +2411,16 @@ class TurtleArtWindow():
elif btype == 'templatelist' or btype == 'list':
for i in range(len(b[4])-4):
dy = blk.add_arg()
- elif btype == 'myfunc2arg' or btype == 'myfunc3arg':
+ elif btype == 'myfunc2arg' or btype == 'myfunc3arg' or\
+ btype == 'userdefined2args' or btype == 'userdefined3args':
dy = blk.add_arg()
- if btype == 'myfunc3arg':
+ if btype == 'myfunc3arg' or btype == 'userdefined3args':
dy = blk.add_arg(False)
+ if btype in PYTHON_SKIN:
+ if self.nop == 'pythonloaded':
+ self._block_skin('pythonon', blk)
+ else:
+ self._block_skin('pythonoff', blk)
elif btype in BOX_STYLE_MEDIA:
if len(blk.values) == 0 or blk.values[0] == 'None' or\
blk.values[0] == None:
@@ -2730,16 +2739,14 @@ class TurtleArtWindow():
return target_w, target_h
image_w = self.media_shapes[name].get_width()
image_h = self.media_shapes[name].get_height()
- if image_w > target_w or image_h > target_h:
- scale_factor = float(target_w)/image_w
- new_w = target_w
- new_h = image_h*scale_factor
- if new_h > target_h:
- scale_factor = float(target_h)/new_h
- new_h = target_h
- new_w = target_w*scale_factor
- return int(new_w), int(new_h)
- return int(target_w), int(target_h)
+ scale_factor = float(target_w)/image_w
+ new_w = target_w
+ new_h = image_h*scale_factor
+ if new_h > target_h:
+ scale_factor = float(target_h)/new_h
+ new_h = target_h
+ new_w = target_w*scale_factor
+ return int(new_w), int(new_h)
"""
Utility for calculating proto skin images
@@ -2760,7 +2767,7 @@ class TurtleArtWindow():
Resize the 'skin' when block scale changes.
"""
def _resize_skin(self, b):
- if b.name == 'nop':
+ if b.name in PYTHON_SKIN:
w, h = self._calc_w_h('pythonoff', b.spr)
x, y = self._calc_image_offset('pythonoff', b.spr, w, h)
elif b.name == 'journal':