diff options
Diffstat (limited to 'TurtleArt/tabasics.py')
-rw-r--r-- | TurtleArt/tabasics.py | 162 |
1 files changed, 75 insertions, 87 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index e26950d..6bff0dc 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -69,6 +69,7 @@ from talogo import primitive_dictionary, logoerror from tautils import convert, chr_to_ord, round_int, strtype from taconstants import BLACK, WHITE, CONSTANTS, XO30 + def _num_type(x): """ Is x a number type? """ if type(x) == int: @@ -137,7 +138,7 @@ class Palettes(): lambda self, x: primitive_dictionary['move']( self.tw.canvas.forward, -x)) - primitive_dictionary['clean'] = self._prim_clean + primitive_dictionary['clean'] = self.tw.lc.prim_clear palette.add_block('clean', style='basic-style-extended-vertical', label=_('clean'), @@ -292,7 +293,6 @@ setxy :x :y\rpendown\rend\r') lambda self: self.tw.canvas.setpen(True)) palette.add_block('setpensize', - hidden=True, style='basic-style-1arg', label=_('set pen size'), prim_name='setpensize', @@ -307,7 +307,6 @@ turtle')) round :a\rend\r') palette.add_block('fillscreen', - hidden=True, style='basic-style-2arg', label=[_('fill screen'), _('color'), _('shade')], prim_name='fillscreen', @@ -321,7 +320,6 @@ shade)')) :shade\rtasetshade :shade\rsetbackground :color\rend\r') palette.add_block('pensize', - hidden=True, style='box-style', label=_('pen size'), help_string=_('holds current pen size (can be used \ @@ -333,36 +331,6 @@ in place of a number block)'), define_logo_function('tapensize', 'to tapensize\routput first round \ pensize\rend\r') - palette.add_block('startfill', - style='basic-style-extended-vertical', - label=_('start fill'), - prim_name='startfill', - help_string=_('starts filled polygon (used with end \ -fill block)')) - self.tw.lc.def_prim('startfill', 0, - lambda self: self.tw.canvas.start_fill()) - - palette.add_block('stopfill', - style='basic-style-extended-vertical', - label=_('end fill'), - prim_name='stopfill', - help_string=_('completes filled polygon (used with \ -start fill block)')) - self.tw.lc.def_prim('stopfill', 0, - lambda self: self.tw.canvas.stop_fill()) - - def _color_palette(self): - """ The basic Turtle Art color palette """ - - if self.tw.hw == XO30: - palette = make_palette('pen', - colors=["#00FFFF", "#00A0A0"], - help_string=_('Palette of pen colors')) - else: - palette = make_palette('colors', - colors=["#00FFFF", "#00A0A0"], - help_string=_('Palette of pen colors')) - palette.add_block('setcolor', style='basic-style-1arg', label=_('set color'), @@ -376,7 +344,6 @@ turtle')) 'color', self.tw.canvas.setcolor, x)) palette.add_block('setshade', - hidden=True, style='basic-style-1arg', label=_('set shade'), prim_name='setshade', @@ -389,7 +356,6 @@ turtle')) 'shade', self.tw.canvas.setshade, x)) palette.add_block('setgray', - hidden=True, style='basic-style-1arg', label=_('set gray'), prim_name='setgray', @@ -411,7 +377,6 @@ in place of a number block)'), self.tw.lc.def_prim('color', 0, lambda self: self.tw.canvas.color) palette.add_block('shade', - hidden=True, style='box-style', label=_('shade'), help_string=_('holds current pen shade'), @@ -421,15 +386,44 @@ in place of a number block)'), self.tw.lc.def_prim('shade', 0, lambda self: self.tw.canvas.shade) palette.add_block('gray', - hidden=True, style='box-style', label=_('gray'), - help_string=_('holds current gray level (can be used \ -in place of a number block)'), + help_string=_('holds current gray level (can be \ +used in place of a number block)'), value_block=True, prim_name='gray') self.tw.lc.def_prim('gray', 0, lambda self: self.tw.canvas.gray) + palette.add_block('startfill', + style='basic-style-extended-vertical', + label=_('start fill'), + prim_name='startfill', + help_string=_('starts filled polygon (used with end \ +fill block)')) + self.tw.lc.def_prim('startfill', 0, + lambda self: self.tw.canvas.start_fill()) + + palette.add_block('stopfill', + style='basic-style-extended-vertical', + label=_('end fill'), + prim_name='stopfill', + help_string=_('completes filled polygon (used with \ +start fill block)')) + self.tw.lc.def_prim('stopfill', 0, + lambda self: self.tw.canvas.stop_fill()) + + def _color_palette(self): + """ The basic Turtle Art color palette """ + + if self.tw.hw == XO30: + palette = make_palette('pen', + colors=["#00FFFF", "#00A0A0"], + help_string=_('Palette of pen colors')) + else: + palette = make_palette('colors', + colors=["#00FFFF", "#00A0A0"], + help_string=_('Palette of pen colors')) + self._make_constant(palette, 'red', _('red'), CONSTANTS['red']) self._make_constant(palette, 'orange', _('orange'), CONSTANTS['orange']) @@ -569,8 +563,8 @@ tasetshade :shade \r') top numeric input')) self.tw.lc.def_prim( 'minus', 2, lambda self, x, y: primitive_dictionary['minus'](x, y)) - define_logo_function('taminus', 'to taminus :y :x\routput sum :x minus \ -:y\rend\r') + define_logo_function('taminus', 'to taminus :y :x\routput sum :x \ +minus :y\rend\r') primitive_dictionary['product'] = self._prim_product palette.add_block('product2', @@ -591,8 +585,8 @@ top numeric input')) special_name=_('divide'), prim_name='division', logo_command='quotient', - help_string=_('divides top numeric input (numerator) \ -by bottom numeric input (denominator)')) + help_string=_('divides top numeric input \ +(numerator) by bottom numeric input (denominator)')) self.tw.lc.def_prim( 'division', 2, lambda self, x, y: primitive_dictionary['division'](x, y)) @@ -621,7 +615,6 @@ blocks')) primitive_dictionary['sqrt'] = self._prim_sqrt palette.add_block('sqrt', - hidden=True, style='number-style-1arg', label=_('√'), special_name=_('square root'), @@ -639,8 +632,8 @@ blocks')) default=[0, 100], prim_name='random', logo_command='tarandom', - help_string=_('returns random number between minimum \ -(top) and maximum (bottom) values')) + help_string=_('returns random number between \ +minimum (top) and maximum (bottom) values')) self.tw.lc.def_prim( 'random', 2, lambda self, x, y: primitive_dictionary['random']( x, y)) @@ -660,8 +653,8 @@ operators')) hidden=True, style='compare-porch-style', label='>', - special_name=_('greater than'), string_or_number=True, + special_name=_('greater than'), prim_name='greater?', logo_command='greater?', help_string=_('logical greater-than operator')) @@ -669,9 +662,6 @@ operators')) 'greater?', 2, lambda self, x, y: primitive_dictionary['more'](x, y)) - if self.tw.canvas.width > 1024: - self._make_constant(palette, 'true', _('True'), 1) - primitive_dictionary['less'] = self._prim_less palette.add_block('less2', hidden=True, @@ -685,21 +675,18 @@ operators')) self.tw.lc.def_prim( 'less?', 2, lambda self, x, y: primitive_dictionary['less'](x, y)) - if self.tw.canvas.width > 1024: - self._make_constant(palette, 'false', _('False'), 0) - primitive_dictionary['equal'] = self._prim_equal palette.add_block('equal2', hidden=True, style='compare-style', label='=', - string_or_number=True, special_name=_('equal'), + string_or_number=True, prim_name='equal?', logo_command='equal?', help_string=_('logical equal-to operator')) - self.tw.lc.def_prim( - 'equal?', 2, lambda self, x, y: primitive_dictionary['equal'](x, y)) + self.tw.lc.def_prim('equal?', 2, + lambda self, x, y: primitive_dictionary['equal'](x, y)) palette.add_block('not', hidden=True, @@ -743,7 +730,6 @@ operators')) primitive_dictionary['wait'] = self._prim_wait palette.add_block('wait', - hidden=True, style='basic-style-1arg', label=_('wait'), prim_name='wait', @@ -756,20 +742,21 @@ number of seconds')) primitive_dictionary['forever'] = self._prim_forever palette.add_block('forever', hidden=True, - style='flow-style', + style='clamp-style', label=_('forever'), prim_name='forever', - default=[None, 'vspace'], + default=[None, None], logo_command='forever', help_string=_('loops forever')) - self.tw.lc.def_prim('forever', 1, primitive_dictionary['forever'], True) + self.tw.lc.def_prim('forever', 1, primitive_dictionary['forever'], + True) primitive_dictionary['repeat'] = self._prim_repeat palette.add_block('repeat', - style='flow-style-1arg', - label=[' ', _('repeat')], + style='clamp-style-1arg', + label=_('repeat'), prim_name='repeat', - default=[4, None, 'vspace'], + default=[4, None, None], logo_command='repeat', special_name=_('repeat'), help_string=_('loops specified number of times')) @@ -778,10 +765,10 @@ number of seconds')) primitive_dictionary['if'] = self._prim_if palette.add_block('if', hidden=True, - style='flow-style-boolean', - label=[_('if'), ' ', _('then')], + style='clamp-style-boolean', + label=[_('if'), _('then'), ''], prim_name='if', - default=[None, None, 'vspace'], + default=[None, None, None], special_name=_('if then'), logo_command='if', help_string=_('if-then operator that uses boolean \ @@ -790,20 +777,30 @@ operators from Numbers palette')) primitive_dictionary['ifelse'] = self._prim_ifelse palette.add_block('ifelse', - hidden=True, - style='flow-style-else', - label=[_('if'), ' ', _('then else')], + hidden=True, # Too big to fit palette + style='clamp-style-else', + label=[_('if'), _('then'), _('else')], prim_name='ifelse', - default=[None, 'vspace', None, 'vspace'], + default=[None, None, None, None], logo_command='ifelse', special_name=_('if then else'), help_string=_('if-then-else operator that uses \ boolean operators from Numbers palette')) self.tw.lc.def_prim('ifelse', 3, primitive_dictionary['ifelse'], True) + # macro + palette.add_block('ifthenelse', + hidden=True, + style='basic-style-extended-vertical', + label=_('if then else'), + help_string=_('if-then-else operator that uses \ +boolean operators from Numbers palette')) + + # Deprecated palette.add_block('hspace', style='flow-style-tail', - label=' ', + hidden=True, + label='', prim_name='nop', special_name=_('horizontal space'), help_string=_('jogs stack right')) @@ -811,7 +808,7 @@ boolean operators from Numbers palette')) palette.add_block('vspace', style='basic-style-extended-vertical', - label=' ', + label='', prim_name='nop', special_name=_('vertical space'), help_string=_('jogs stack down')) @@ -850,9 +847,9 @@ buttons')) palette.add_block('storeinbox1', style='basic-style-1arg', label=_('store in box 1'), - string_or_number=True, prim_name='storeinbox1', default=100, + string_or_number=True, logo_command='make "box1', help_string=_('stores numeric value in Variable 1')) self.tw.lc.def_prim('storeinbox1', 1, @@ -862,9 +859,9 @@ buttons')) palette.add_block('storeinbox2', style='basic-style-1arg', label=_('store in box 2'), - string_or_number=True, prim_name='storeinbox2', default=100, + string_or_number=True, logo_command='make "box2', help_string=_('stores numeric value in Variable 2')) self.tw.lc.def_prim('storeinbox2', 1, @@ -872,7 +869,6 @@ buttons')) 'box2', None, x)) palette.add_block('string', - hidden=True, style='box-style', label=_('text'), default=_('text'), @@ -899,11 +895,10 @@ buttons')) primitive_dictionary['box'] = self._prim_box palette.add_block('box', - hidden=True, style='number-style-1strarg', label=_('box'), - prim_name='box', string_or_number=True, + prim_name='box', default=_('my box'), logo_command='box', help_string=_('named variable (numeric value)')) @@ -911,7 +906,6 @@ buttons')) lambda self, x: primitive_dictionary['box'](x)) palette.add_block('storein', - hidden=True, style='basic-style-2arg', label=[_('store in'), _('box'), _('value')], string_or_number=True, @@ -925,7 +919,6 @@ variable')) 'box3', x, y)) palette.add_block('hat', - hidden=True, style='basic-style-head-1arg', label=_('action'), prim_name='nop3', @@ -953,7 +946,6 @@ variable')) primitive_dictionary['stack'] = self._prim_stack palette.add_block('stack', - hidden=True, style='basic-style-1arg', label=_('action'), string_or_number=True, @@ -1005,12 +997,6 @@ variable')) # Block primitives - def _prim_clean(self): - ''' Clean block ''' - self.tw.lc.prim_clear - self.tw.display_coordinates() - self.tw.parent.restore_challenge() - def _prim_and(self, x, y): """ Logical and """ return x & y @@ -1215,6 +1201,8 @@ variable')) def _prim_less(self, x, y): """ Compare numbers and strings """ + if type(x) == list or type(y) == list: + raise logoerror("#syntaxerror") try: return float(x) < float(y) except ValueError: |