From 7e6d1757a3d6a23e446bf0f7875a98633a041295 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 06 Apr 2011 20:02:16 +0000 Subject: added logo_command primitive to block structure --- diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index 825dd95..0cc27d3 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -116,8 +116,9 @@ class Palettes(): palette.add_block('forward', style='basic-style-1arg', label=_('forward'), - default=100, prim_name='forward', + default=100, + logo_command='forward', help_string=_('moves turtle forward')) self.tw.lc.def_prim('forward', 1, lambda self, x: primitive_dictionary['move']( @@ -128,6 +129,7 @@ class Palettes(): label=_('back'), prim_name='back', default=100, + logo_command='back', help_string=_('moves turtle backward')) self.tw.lc.def_prim('back', 1, lambda self, x: primitive_dictionary['move']( @@ -138,6 +140,7 @@ class Palettes(): style='basic-style-extended-vertical', label=_('clean'), prim_name='clean', + logo_command='clean', help_string=_('clears the screen and reset the \ turtle')) self.tw.lc.def_prim('clean', 0, @@ -149,6 +152,7 @@ turtle')) label=_('left'), prim_name='left', default=90, + logo_command='left', help_string=_('turns turtle counterclockwise (angle \ in degrees)')) self.tw.lc.def_prim('left', 1, @@ -159,6 +163,7 @@ in degrees)')) label=_('right'), prim_name='right', default=90, + logo_command='right', help_string=_('turns turtle clockwise (angle in \ degrees)')) self.tw.lc.def_prim('right', 1, @@ -170,6 +175,7 @@ degrees)')) label=[_('arc'), _('angle'), _('radius')], prim_name='arc', default=[90, 100], + logo_command='taarc', help_string=_('moves turtle along an arc')) self.tw.lc.def_prim('arc', 2, lambda self, x, y: primitive_dictionary['arc']( @@ -179,6 +185,7 @@ degrees)')) style='basic-style-2arg', label=[_('set xy'), _('x'), _('y')], prim_name='setxy2', + logo_command='tasetxy', default=[0, 0], help_string=_('moves turtle to position xcor, ycor; \ (0, 0) is in the center of the screen.')) @@ -192,6 +199,7 @@ degrees)')) label=_('set heading'), prim_name='seth', default=0, + logo_command='seth', help_string=_('sets the heading of the turtle (0 is \ towards the top of the screen.)')) self.tw.lc.def_prim('seth', 1, @@ -204,7 +212,8 @@ towards the top of the screen.)')) help_string=_('holds current x-coordinate value of \ the turtle (can be used in place of a number block)'), value_block=True, - prim_name='xcor') + prim_name='xcor', + logo_command='xcor') self.tw.lc.def_prim( 'xcor', 0, lambda self: self.tw.canvas.xcor / self.tw.coord_scale) @@ -214,7 +223,8 @@ the turtle (can be used in place of a number block)'), help_string=_('holds current y-coordinate value of \ the turtle (can be used in place of a number block)'), value_block=True, - prim_name='ycor') + prim_name='ycor', + logo_command='ycor') self.tw.lc.def_prim( 'ycor', 0, lambda self: self.tw.canvas.ycor / self.tw.coord_scale) @@ -224,7 +234,8 @@ the turtle (can be used in place of a number block)'), help_string=_('holds current heading value of the \ turtle (can be used in place of a number block)'), value_block=True, - prim_name='heading') + prim_name='heading', + logo_command='heading') self.tw.lc.def_prim( 'heading', 0, lambda self: self.tw.canvas.heading) @@ -240,6 +251,7 @@ turtle (can be used in place of a number block)'), label=[_('set xy'), _('x'), _('y')], prim_name='setxy', default=[0, 0], + logo_command='tasetxypenup', help_string=_('moves turtle to position xcor, ycor; \ (0, 0) is in the center of the screen.')) self.tw.lc.def_prim('setxy', 2, @@ -257,6 +269,7 @@ turtle (can be used in place of a number block)'), style='basic-style-extended-vertical', label=_('pen up'), prim_name='penup', + logo_command='penup', help_string=_('Turtle will not draw when moved.')) self.tw.lc.def_prim('penup', 0, lambda self: self.tw.canvas.setpen(False)) @@ -265,6 +278,7 @@ turtle (can be used in place of a number block)'), style='basic-style-extended-vertical', label=_('pen down'), prim_name='pendown', + logo_command='pendown', help_string=_('Turtle will draw when moved.')) self.tw.lc.def_prim('pendown', 0, lambda self: self.tw.canvas.setpen(True)) @@ -274,6 +288,7 @@ turtle (can be used in place of a number block)'), label=_('set pen size'), prim_name='setpensize', default=5, + logo_command='setpensize', help_string=_('sets size of the line drawn by the \ turtle')) self.tw.lc.def_prim('setpensize', 1, @@ -285,6 +300,7 @@ turtle')) label=[_('fill screen'), _('color'), _('shade')], prim_name='fillscreen', default=[60, 80], + logo_command='tasetbackground', help_string=_('fills the background with (color, \ shade)')) self.tw.lc.def_prim('fillscreen', 2, @@ -296,7 +312,8 @@ shade)')) help_string=_('holds current pen size (can be used \ in place of a number block)'), value_block=True, - prim_name='pensize') + prim_name='pensize', + logo_command='pensize') self.tw.lc.def_prim('pensize', 0, lambda self: self.tw.canvas.pensize) palette.add_block('startfill', @@ -329,6 +346,7 @@ start fill block)')) label=_('set color'), prim_name='setcolor', default=0, + logo_command='tasetpencolor', help_string=_('sets color of the line drawn by the \ turtle')) self.tw.lc.def_prim('setcolor', 1, @@ -340,6 +358,7 @@ turtle')) label=_('set shade'), prim_name='setshade', default=50, + logo_command='tasetshade', help_string=_('sets shade of the line drawn by the \ turtle')) self.tw.lc.def_prim('setshade', 1, @@ -363,7 +382,8 @@ the turtle')) help_string=_('holds current pen color (can be used \ in place of a number block)'), value_block=True, - prim_name='color') + prim_name='color', + logo_command='pencolor') self.tw.lc.def_prim('color', 0, lambda self: self.tw.canvas.color) palette.add_block('shade', @@ -371,7 +391,8 @@ in place of a number block)'), label=_('shade'), help_string=_('holds current pen shade'), value_block=True, - prim_name='shade') + prim_name='shade', + logo_command=':shade') self.tw.lc.def_prim('shade', 0, lambda self: self.tw.canvas.shade) palette.add_block('gray', @@ -429,6 +450,7 @@ turtle')) label='+', special_name=_('plus'), prim_name='plus', + logo_command='sum', help_string=_('adds two alphanumeric inputs')) self.tw.lc.def_prim( 'plus', 2, lambda self, x, y: primitive_dictionary['plus'](x, y)) @@ -439,6 +461,7 @@ turtle')) label='–', special_name=_('minus'), prim_name='minus', + logo_command='taminus', help_string=_('subtracts bottom numeric input from \ top numeric input')) self.tw.lc.def_prim( @@ -450,6 +473,7 @@ top numeric input')) label='×', special_name=_('multiply'), prim_name='product', + logo_command='product', help_string=_('multiplies two numeric inputs')) self.tw.lc.def_prim( 'product', 2, @@ -461,6 +485,7 @@ top numeric input')) label='/', special_name=_('divide'), prim_name='division', + logo_command='quotient', help_string=_('divides top numeric input (numerator) \ by bottom numeric input (denominator)')) self.tw.lc.def_prim( @@ -484,6 +509,7 @@ blocks')) label=_('mod'), special_name=_('mod'), prim_name='remainder', + logo_command='remainder', help_string=_('modular (remainder) operator')) self.tw.lc.def_prim('remainder', 2, lambda self, x, y: primitive_dictionary['remainder'](x, y)) @@ -494,6 +520,7 @@ blocks')) label=_('√'), special_name=_('square root'), prim_name='sqrt', + logo_command='tasqrt', help_string=_('calculates square root')) self.tw.lc.def_prim('sqrt', 1, lambda self, x: primitive_dictionary['sqrt'](x)) @@ -504,6 +531,7 @@ blocks')) label=[_('random'), _('min'), _('max')], default=[0, 100], prim_name='random', + logo_command='tarandom', help_string=_('returns random number between minimum \ (top) and maximum (bottom) values')) self.tw.lc.def_prim( @@ -523,6 +551,7 @@ operators')) label='>', special_name=_('greater than'), prim_name='greater?', + logo_command='greater?', help_string=_('logical greater-than operator')) self.tw.lc.def_prim( 'greater?', 2, lambda self, x, y: primitive_dictionary['more'](x, y)) @@ -533,6 +562,7 @@ operators')) label='<', special_name=_('less than'), prim_name='less?', + logo_command='less?', help_string=_('logical less-than operator')) self.tw.lc.def_prim( 'less?', 2, lambda self, x, y: primitive_dictionary['less'](x, y)) @@ -543,6 +573,7 @@ operators')) label='=', special_name=_('equal'), 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)) @@ -551,6 +582,7 @@ operators')) style='not-style', label=_('not'), prim_name='not', + logo_command='not', help_string=_('logical NOT operator')) self.tw.lc.def_prim('not', 1, lambda self, x: not x) @@ -559,6 +591,7 @@ operators')) style='boolean-style', label=_('and'), prim_name='and', + logo_command='and', special_name=_('and'), help_string=_('logical AND operator')) self.tw.lc.def_prim( @@ -569,6 +602,7 @@ operators')) style='boolean-style', label=_('or'), prim_name='or', + logo_command='or', special_name=_('or'), help_string=_('logical OR operator')) self.tw.lc.def_prim( @@ -587,6 +621,7 @@ operators')) label=_('wait'), prim_name='wait', default=1, + logo_command='wait', help_string=_('pauses program execution a specified \ number of seconds')) self.tw.lc.def_prim('wait', 1, primitive_dictionary['wait'], True) @@ -597,6 +632,7 @@ number of seconds')) label=_('forever'), prim_name='forever', default=[None, 'vspace'], + logo_command='forever', help_string=_('loops forever')) self.tw.lc.def_prim('forever', 1, primitive_dictionary['forever'], True) @@ -606,6 +642,7 @@ number of seconds')) label=[' ', _('repeat')], prim_name='repeat', default=[4, None, 'vspace'], + logo_command='repeat', special_name=_('repeat'), help_string=_('loops specified number of times')) self.tw.lc.def_prim('repeat', 2, primitive_dictionary['repeat'], True) @@ -617,6 +654,7 @@ number of seconds')) prim_name='if', default=[None, None, 'vspace'], special_name=_('if then'), + logo_command='if', help_string=_('if-then operator that uses boolean \ operators from Numbers palette')) self.tw.lc.def_prim('if', 2, primitive_dictionary['if'], True) @@ -627,6 +665,7 @@ operators from Numbers palette')) label=[' ', _('if'), _('then else')], prim_name='ifelse', default=[None, 'vspace', None, 'vspace'], + logo_command='ifelse', special_name=_('if then else'), help_string=_('if-then-else operator that uses \ boolean operators from Numbers palette')) @@ -653,6 +692,7 @@ boolean operators from Numbers palette')) style='basic-style-tail', label=_('stop action'), prim_name='stopstack', + logo_command='stop', help_string=_('stops current action')) self.tw.lc.def_prim('stopstack', 0, lambda self: primitive_dictionary['stopstack']()) @@ -669,6 +709,7 @@ boolean operators from Numbers palette')) style='basic-style-head', label=_('start'), prim_name='start', + logo_command='to start\r', help_string=_('connects action to toolbar run \ buttons')) self.tw.lc.def_prim('start', 0, @@ -680,6 +721,7 @@ buttons')) label=_('store in box 1'), prim_name='storeinbox1', default=100, + logo_command='make "box1', help_string=_('stores numeric value in Variable 1')) self.tw.lc.def_prim('storeinbox1', 1, lambda self, x: primitive_dictionary['setbox']( @@ -690,6 +732,7 @@ buttons')) label=_('store in box 2'), prim_name='storeinbox2', default=100, + logo_command='make "box2', help_string=_('stores numeric value in Variable 2')) self.tw.lc.def_prim('storeinbox2', 1, lambda self, x: primitive_dictionary['setbox']( @@ -706,6 +749,7 @@ buttons')) style='box-style', label=_('box 1'), prim_name='box1', + logo_command=':box1', help_string=_('Variable 1 (numeric value)'), value_block=True) self.tw.lc.def_prim('box1', 0, lambda self: self.tw.lc.boxes['box1']) @@ -714,6 +758,7 @@ buttons')) style='box-style', label=_('box 2'), prim_name='box2', + logo_command=':box2', help_string=_('Variable 2 (numeric value)'), value_block=True) self.tw.lc.def_prim('box2', 0, lambda self: self.tw.lc.boxes['box2']) @@ -724,6 +769,7 @@ buttons')) label=_('box'), prim_name='box', default=_('my box'), + logo_command='box', help_string=_('named variable (numeric value)')) self.tw.lc.def_prim('box', 1, lambda self, x: primitive_dictionary['box'](x)) @@ -732,6 +778,7 @@ buttons')) style='basic-style-2arg', label=[_('store in'), _('box'), _('value')], prim_name='storeinbox', + logo_command='storeinbox', default=[_('my box'), 100], help_string=_('stores numeric value in named \ variable')) @@ -743,7 +790,8 @@ variable')) style='basic-style-head-1arg', label=_('action'), prim_name='nop3', - default=_('action'), + default=_('stack'), + logo_command='action', help_string=_('top of nameable action stack')) self.tw.lc.def_prim('nop3', 1, lambda self, x: None) @@ -751,6 +799,7 @@ variable')) style='basic-style-head', label=_('action 1'), prim_name='nop1', + logo_command='to stack1\r', help_string=_('top of Action 1 stack')) self.tw.lc.def_prim('nop1', 0, lambda self: None) @@ -758,6 +807,7 @@ variable')) style='basic-style-head', label=_('action 2'), prim_name='nop2', + logo_command='to stack2\r', help_string=_('top of Action 2 stack')) self.tw.lc.def_prim('nop2', 0, lambda self: None) @@ -766,6 +816,7 @@ variable')) style='basic-style-1arg', label=_('action'), prim_name='stack', + logo_command='runstack', default=_('action'), help_string=_('invokes named action stack')) self.tw.lc.def_prim('stack', 1, primitive_dictionary['stack'], True) @@ -775,6 +826,7 @@ variable')) style='basic-style-extended-vertical', label=_('action 1'), prim_name='stack1', + logo_command='stack1', help_string=_('invokes Action 1 stack')) self.tw.lc.def_prim('stack1', 0, primitive_dictionary['stack1'], True) @@ -783,6 +835,7 @@ variable')) style='basic-style-extended-vertical', label=_('action 2'), prim_name='stack2', + logo_command='stack2', help_string=_('invokes Action 2 stack')) self.tw.lc.def_prim('stack2', 0, primitive_dictionary['stack2'], True) diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index e34df21..48212ae 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -129,7 +129,7 @@ class Palette(): def add_block(self, block_name, style='basic-block', label=None, special_name=None, default=None, prim_name=None, help_string=None, value_block=False, content_block=False, - hidden=False): + logo_command=None, hidden=False): """ Add a new block to the palette """ block = Block(block_name) block.set_style(style) @@ -144,6 +144,8 @@ class Palette(): block.set_default(default) if prim_name is not None: block.set_prim_name(prim_name) + if logo_command is not None: + block.set_logo_command(logo_command) if help_string is not None: block.set_help(help_string) block.set_value_block(value_block) @@ -185,6 +187,7 @@ class Block(): self._default = None self._help = None self._prim_name = None + self._logo_command = None self._value_block = False self._content_block = False @@ -273,3 +276,6 @@ class Block(): def set_prim_name(self, prim_name): self._prim_name = prim_name + + def set_logo_command(self, logo_command): + self._logo_command = logo_command diff --git a/plugins/turtle_blocks_plugin.py b/plugins/turtle_blocks_plugin.py index ba2e45f..72dc3c6 100644 --- a/plugins/turtle_blocks_plugin.py +++ b/plugins/turtle_blocks_plugin.py @@ -153,6 +153,7 @@ boolean operators from Numbers palette')) label=_('show'), default=_('text'), prim_name='show', + logo_command='label', help_string=_('draws text or show media from the \ Journal')) self.tw.lc.def_prim('show', 1, @@ -164,6 +165,7 @@ Journal')) label=_('show aligned'), default=_('text'), prim_name='showaligned', + logo_command='label', help_string=_('draws text or show media from the \ Journal')) self.tw.lc.def_prim('showaligned', 1, @@ -177,6 +179,7 @@ Journal')) label=_('show'), default=[_('text'), 32], prim_name='write', + logo_command='label', help_string=_('draws text or show media from the \ Journal')) self.tw.lc.def_prim('write', 2, @@ -188,6 +191,7 @@ Journal')) label=_('set scale'), prim_name='setscale', default=33, + logo_command='setlabelheight', help_string=_('sets the scale of media')) self.tw.lc.def_prim('setscale', 1, lambda self, x: primitive_dictionary['setscale'](x)) @@ -219,6 +223,7 @@ in the Sugar Journal')) label=_('scale'), prim_name='scale', value_block=True, + logo_command='labelsize', help_string=_('holds current scale value')) self.tw.lc.def_prim('scale', 0, lambda self: self.tw.lc.scale) @@ -251,6 +256,7 @@ stored in keyboard block)')) label=_('keyboard'), prim_name='keyboard', value_block=True, + logo_command='make "keyboard readchar', help_string=_('holds results of query-keyboard \ block')) self.tw.lc.def_prim('keyboard', 0, lambda self: self.tw.lc.keyboard) @@ -260,6 +266,7 @@ block')) style='basic-style-extended-vertical', label=_('read pixel'), prim_name='readpixel', + logo_command=':keyboard', help_string=_('RGB color under the turtle is pushed \ to the stack')) self.tw.lc.def_prim('readpixel', 0, @@ -297,6 +304,7 @@ program started')) style='basic-style-1arg', label=_('push'), prim_name='push', + logo_command='tapush', help_string=_('pushes value onto FILO (first-in \ last-out heap)')) self.tw.lc.def_prim('push', 1, @@ -307,6 +315,7 @@ last-out heap)')) style='basic-style-extended-vertical', label=_('show heap'), prim_name='printheap', + logo_command='taprintheap', help_string=_('shows values in FILO (first-in \ last-out heap)')) self.tw.lc.def_prim('printheap', 0, @@ -317,6 +326,7 @@ last-out heap)')) style='basic-style-extended-vertical', label=_('empty heap'), prim_name='clearheap', + logo_command='taclearheap', help_string=_('emptys FILO (first-in-last-out \ heap)')) self.tw.lc.def_prim('clearheap', 0, @@ -328,6 +338,7 @@ heap)')) label=_('pop'), prim_name='pop', value_block=True, + logo_command='tapop', help_string=_('pops value off FILO (first-in \ last-out heap)')) self.tw.lc.def_prim('pop', 0, @@ -347,6 +358,7 @@ last-out heap)')) style='basic-style-1arg', label=_('print'), prim_name='print', + logo_command='label', help_string=_('prints value in status block at \ bottom of the screen')) self.tw.lc.def_prim('print', 1, @@ -592,6 +604,7 @@ Journal objects')) style='box-style', label=_('left'), prim_name='lpos', + logo_command='lpos', help_string=_('xcor of left of screen')) self.tw.lc.def_prim('lpos', 0, lambda self: CONSTANTS['leftpos']) @@ -599,6 +612,7 @@ Journal objects')) style='box-style', label=_('bottom'), prim_name='bpos', + logo_command='bpos', help_string=_('ycor of bottom of screen')) self.tw.lc.def_prim('bpos', 0, lambda self: CONSTANTS['bottompos']) @@ -606,6 +620,7 @@ Journal objects')) style='box-style', label=_('width'), prim_name='hres', + logo_command='width', help_string=_('the canvas width')) self.tw.lc.def_prim('hres', 0, lambda self: CONSTANTS['width']) @@ -613,6 +628,7 @@ Journal objects')) style='box-style', label=_('right'), prim_name='rpos', + logo_command='rpos', help_string=_('xcor of right of screen')) self.tw.lc.def_prim('rpos', 0, lambda self: CONSTANTS['rightpos']) @@ -620,6 +636,7 @@ Journal objects')) style='box-style', label=_('top'), prim_name='tpos', + logo_command='tpos', help_string=_('ycor of top of screen')) self.tw.lc.def_prim('tpos', 0, lambda self: CONSTANTS['toppos']) @@ -627,6 +644,7 @@ Journal objects')) style='box-style', label=_('height'), prim_name='vres', + logo_command='height', help_string=_('the canvas height')) self.tw.lc.def_prim('vres', 0, lambda self: CONSTANTS['height']) @@ -634,6 +652,7 @@ Journal objects')) hidden=True, style='box-style', label=_('title x'), + logo_command='titlex', prim_name='titlex') self.tw.lc.def_prim('titlex', 0, lambda self: CONSTANTS['titlex']) @@ -641,6 +660,7 @@ Journal objects')) hidden=True, style='box-style', label=_('title y'), + logo_command='titley', prim_name='titley') self.tw.lc.def_prim('titley', 0, lambda self: CONSTANTS['titley']) @@ -648,28 +668,32 @@ Journal objects')) hidden=True, style='box-style', label=_('left x'), - prim_name='leftx') + prim_name='leftx', + logo_command='leftx') self.tw.lc.def_prim('leftx', 0, lambda self: CONSTANTS['leftx']) palette.add_block('topy', hidden=True, style='box-style', label=_('top y'), - prim_name='topy') + prim_name='topy', + logo_command='topy') self.tw.lc.def_prim('topy', 0, lambda self: CONSTANTS['topy']) palette.add_block('rightx', hidden=True, style='box-style', label=_('right x'), - prim_name='rightx') + prim_name='rightx', + logo_command='rightx') self.tw.lc.def_prim('rightx', 0, lambda self: CONSTANTS['rightx']) palette.add_block('bottomy', hidden=True, style='box-style', label=_('bottom y'), - prim_name='bottomy') + prim_name='bottomy', + logo_command='bottomy') self.tw.lc.def_prim('bottomy', 0, lambda self: CONSTANTS['bottomy']) # deprecated blocks -- cgit v0.9.1