From 08ac16fe7bbaa46673b495687325240745b21033 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 05 Mar 2011 03:02:21 +0000 Subject: made add_block a method of Palette --- diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index 12301e9..2ce6c0c 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -66,7 +66,7 @@ from random import uniform from gettext import gettext as _ -from taprimitive import make_palette, make_prim +from taprimitive import make_palette from talogo import PLUGIN_DICTIONARY, logoerror from taconstants import CONSTANTS, BLACK, WHITE from tautils import convert, chr_to_ord, round_int, strtype @@ -113,143 +113,135 @@ class Palettes(): def _turtle_palette(self): """ The basic Turtle Art turtle palette """ - make_palette('turtle', - colors=["#00FF00", "#00A000"], - help_string=_('Palette of turtle commands')) + palette = make_palette('turtle', + colors=["#00FF00", "#00A000"], + help_string=_('Palette of turtle commands')) PLUGIN_DICTIONARY['move'] = self._prim_move - make_prim('forward', - palette='turtle', - style='basic-style-1arg', - label=_('forward'), - default=100, - prim_name='forward', - help_string=_('moves turtle forward')) + palette.add_block('forward', + style='basic-style-1arg', + label=_('forward'), + default=100, + prim_name='forward', + help_string=_('moves turtle forward')) self.tw.lc.def_prim('forward', 1, lambda self, x: PLUGIN_DICTIONARY['move']( self.tw.canvas.forward, x)) - make_prim('back', - palette='turtle', - style='basic-style-1arg', - label=_('back'), - prim_name='back', - default=100, - help_string=_('moves turtle backward')) + palette.add_block('back', + style='basic-style-1arg', + label=_('back'), + prim_name='back', + default=100, + help_string=_('moves turtle backward')) self.tw.lc.def_prim('back', 1, lambda self, x: PLUGIN_DICTIONARY['move']( self.tw.canvas.forward, -x)) PLUGIN_DICTIONARY['clean'] = self.tw.lc.prim_clear - make_prim('clean', - palette='turtle', - style='basic-style-extended-vertical', - label=_('clean'), - prim_name='clean', - help_string=_('clears the screen and reset the turtle')) + palette.add_block('clean', + style='basic-style-extended-vertical', + label=_('clean'), + prim_name='clean', + help_string=_('clears the screen and reset the \ +turtle')) self.tw.lc.def_prim('clean', 0, lambda self: PLUGIN_DICTIONARY['clean']()) PLUGIN_DICTIONARY['right'] = self._prim_right - make_prim('left', - palette='turtle', - style='basic-style-1arg', - label=_('left'), - prim_name='left', - default=90, - help_string=_('turns turtle counterclockwise (angle in \ -degrees)')) + palette.add_block('left', + style='basic-style-1arg', + label=_('left'), + prim_name='left', + default=90, + help_string=_('turns turtle counterclockwise (angle \ +in degrees)')) self.tw.lc.def_prim('right', 1, lambda self, x: PLUGIN_DICTIONARY['right'](-x)) - make_prim('right', - palette='turtle', - style='basic-style-1arg', - label=_('right'), - prim_name='right', - default=90, - help_string=_('turns turtle clockwise (angle in degrees)')) + palette.add_block('right', + style='basic-style-1arg', + label=_('right'), + prim_name='right', + default=90, + help_string=_('turns turtle clockwise (angle in \ +degrees)')) self.tw.lc.def_prim('right', 1, lambda self, x: PLUGIN_DICTIONARY['right'](x)) PLUGIN_DICTIONARY['arc'] = self._prim_arc - make_prim('arc', - palette='turtle', - style='basic-style-2arg', - label=[_('arc'), _('angle'), _('radius')], - prim_name='arc', - default=[90, 100], - help_string=_('moves turtle along an arc')) + palette.add_block('arc', + style='basic-style-2arg', + label=[_('arc'), _('angle'), _('radius')], + prim_name='arc', + default=[90, 100], + help_string=_('moves turtle along an arc')) self.tw.lc.def_prim('arc', 2, lambda self, x, y: PLUGIN_DICTIONARY['arc']( self.tw.canvas.arc, x, y)) - make_prim('setxy2', - palette='turtle', - style='basic-style-2arg', - label=[_('set xy'), _('x'), _('y')], - prim_name='setxy2', - default=[0, 0], - help_string=_('moves turtle to position xcor, ycor; (0, 0) \ -is in the center of the screen.')) + palette.add_block('setxy2', + style='basic-style-2arg', + label=[_('set xy'), _('x'), _('y')], + prim_name='setxy2', + default=[0, 0], + help_string=_('moves turtle to position xcor, ycor; \ +(0, 0) is in the center of the screen.')) self.tw.lc.def_prim('setxy2', 2, lambda self, x, y: PLUGIN_DICTIONARY['move']( self.tw.canvas.setxy, x, y)) PLUGIN_DICTIONARY['set'] = self._prim_set - make_prim('seth', - palette='turtle', - style='basic-style-1arg', - label=_('set heading'), - prim_name='seth', - default=0, - help_string=_('sets the heading of the turtle (0 is towards \ -the top of the screen.)')) + palette.add_block('seth', + style='basic-style-1arg', + label=_('set heading'), + prim_name='seth', + default=0, + help_string=_('sets the heading of the turtle (0 is \ +towards the top of the screen.)')) self.tw.lc.def_prim('seth', 1, lambda self, x: PLUGIN_DICTIONARY['set']( 'heading', self.tw.canvas.seth, x)) - make_prim('xcor', - palette='turtle', - style='box-style', - label=_('xcor'), - 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') + palette.add_block('xcor', + style='box-style', + label=_('xcor'), + 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') self.tw.lc.def_prim( 'xcor', 0, lambda self: self.tw.canvas.xcor / self.tw.coord_scale) - make_prim('ycor', - palette='turtle', - style='box-style', - label=_('ycor'), - 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') + palette.add_block('ycor', + style='box-style', + label=_('ycor'), + 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') self.tw.lc.def_prim( 'ycor', 0, lambda self: self.tw.canvas.ycor / self.tw.coord_scale) - make_prim('heading', - palette='turtle', - style='box-style', - label=_('heading'), - help_string=_('holds current heading value of the turtle \ -(can be used in place of a number block)'), - value_block=True, - prim_name='heading') + palette.add_block('heading', + style='box-style', + label=_('heading'), + help_string=_('holds current heading value of the \ +turtle (can be used in place of a number block)'), + value_block=True, + prim_name='heading') self.tw.lc.def_prim( 'heading', 0, lambda self: self.tw.canvas.heading) # Deprecated - make_prim('setxy', - style='basic-style-2arg', - label=[_('set xy'), _('x'), _('y')], - prim_name='setxy', - default=[0, 0], - help_string=_('moves turtle to position xcor, ycor; (0, 0) \ -is in the center of the screen.')) + palette.add_block('setxy', + hidden=True, + style='basic-style-2arg', + label=[_('set xy'), _('x'), _('y')], + prim_name='setxy', + default=[0, 0], + help_string=_('moves turtle to position xcor, ycor; \ +(0, 0) is in the center of the screen.')) self.tw.lc.def_prim('setxy', 2, lambda self, x, y: PLUGIN_DICTIONARY['move']( self.tw.canvas.setxy, x, y, pendown=False)) @@ -257,597 +249,556 @@ is in the center of the screen.')) def _pen_palette(self): """ The basic Turtle Art pen palette """ - make_palette('pen', - colors=["#00FFFF", "#00A0A0"], - help_string=_('Palette of pen commands')) + palette = make_palette('pen', + colors=["#00FFFF", "#00A0A0"], + help_string=_('Palette of pen commands')) - make_prim('penup', - palette='pen', - style='basic-style-extended-vertical', - label=_('pen up'), - prim_name='penup', - help_string=_('Turtle will not draw when moved.')) + palette.add_block('penup', + style='basic-style-extended-vertical', + label=_('pen up'), + prim_name='penup', + help_string=_('Turtle will not draw when moved.')) self.tw.lc.def_prim('penup', 0, lambda self: self.tw.canvas.setpen(False)) - make_prim('pendown', - palette='pen', - style='basic-style-extended-vertical', - label=_('pen down'), - prim_name='pendown', - help_string=_('Turtle will draw when moved.')) + palette.add_block('pendown', + style='basic-style-extended-vertical', + label=_('pen down'), + prim_name='pendown', + help_string=_('Turtle will draw when moved.')) self.tw.lc.def_prim('pendown', 0, lambda self: self.tw.canvas.setpen(True)) - make_prim('setpensize', - palette='pen', - style='basic-style-1arg', - label=_('set pen size'), - prim_name='setpensize', - default=5, - help_string=_('sets size of the line drawn by the turtle')) + palette.add_block('setpensize', + style='basic-style-1arg', + label=_('set pen size'), + prim_name='setpensize', + default=5, + help_string=_('sets size of the line drawn by the \ +turtle')) self.tw.lc.def_prim('setpensize', 1, lambda self, x: PLUGIN_DICTIONARY['set']( 'pensize', self.tw.canvas.setpensize, x)) - make_prim('fillscreen', - palette='pen', - style='basic-style-2arg', - label=[_('fill screen'), _('color'), _('shade')], - prim_name='fillscreen', - default=[60, 80], - help_string=_('fills the background with (color, shade)')) + palette.add_block('fillscreen', + style='basic-style-2arg', + label=[_('fill screen'), _('color'), _('shade')], + prim_name='fillscreen', + default=[60, 80], + help_string=_('fills the background with (color, \ +shade)')) self.tw.lc.def_prim('fillscreen', 2, lambda self, x, y: self.tw.canvas.fillscreen(x, y)) - make_prim('pensize', - palette='pen', - style='box-style', - label=_('pen size'), - help_string=_('holds current pen size (can be used in place \ -of a number block)'), - value_block=True, - prim_name='pensize') + palette.add_block('pensize', + style='box-style', + label=_('pen size'), + help_string=_('holds current pen size (can be used \ +in place of a number block)'), + value_block=True, + prim_name='pensize') self.tw.lc.def_prim('pensize', 0, lambda self: self.tw.canvas.pensize) - make_prim('startfill', - palette='pen', - style='basic-style-extended-vertical', - label=_('start fill'), - prim_name='startfill', - help_string=_('starts filled polygon (used with end fill \ -block)')) + 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()) - make_prim('stopfill', - palette='pen', - style='basic-style-extended-vertical', - label=_('end fill'), - prim_name='stopfill', - help_string=_('completes filled polygon (used with start \ -fill block)')) + 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 """ - make_palette('colors', - colors=["#00FFFF", "#00A0A0"], - help_string=_('Palette of pen colors')) - - make_prim('setcolor', - palette='colors', - style='basic-style-1arg', - label=_('set color'), - prim_name='setcolor', - default=0, - help_string=_('sets color of the line drawn by the turtle')) + palette = make_palette('colors', + colors=["#00FFFF", "#00A0A0"], + help_string=_('Palette of pen colors')) + + palette.add_block('setcolor', + style='basic-style-1arg', + label=_('set color'), + prim_name='setcolor', + default=0, + help_string=_('sets color of the line drawn by the \ +turtle')) self.tw.lc.def_prim('setcolor', 1, lambda self, x: PLUGIN_DICTIONARY['set']( 'color', self.tw.canvas.setcolor, x)) - make_prim('setshade', - palette='colors', - style='basic-style-1arg', - label=_('set shade'), - prim_name='setshade', - default=50, - help_string=_('sets shade of the line drawn by the turtle')) + palette.add_block('setshade', + style='basic-style-1arg', + label=_('set shade'), + prim_name='setshade', + default=50, + help_string=_('sets shade of the line drawn by the \ +turtle')) self.tw.lc.def_prim('setshade', 1, lambda self, x: PLUGIN_DICTIONARY['set']( 'shade', self.tw.canvas.setshade, x)) - make_prim('setgray', - palette='colors', - style='basic-style-1arg', - label=_('set gray'), - prim_name='setgray', - default=100, - help_string=_('sets gray level of the line drawn by the \ -turtle')) + palette.add_block('setgray', + style='basic-style-1arg', + label=_('set gray'), + prim_name='setgray', + default=100, + help_string=_('sets gray level of the line drawn by \ +the turtle')) self.tw.lc.def_prim('setgray', 1, lambda self, x: PLUGIN_DICTIONARY['set']( 'gray', self.tw.canvas.setgray, x)) - make_prim('color', - palette='colors', - style='box-style', - label=_('color'), - help_string=_('holds current pen color (can be used in \ -place of a number block)'), - value_block=True, - prim_name='color') + palette.add_block('color', + style='box-style', + label=_('color'), + help_string=_('holds current pen color (can be used \ +in place of a number block)'), + value_block=True, + prim_name='color') self.tw.lc.def_prim('color', 0, lambda self: self.tw.canvas.color) - make_prim('shade', - palette='colors', - style='box-style', - label=_('shade'), - help_string=_('holds current pen shade'), - value_block=True, - prim_name='shade') + palette.add_block('shade', + style='box-style', + label=_('shade'), + help_string=_('holds current pen shade'), + value_block=True, + prim_name='shade') self.tw.lc.def_prim('shade', 0, lambda self: self.tw.canvas.shade) - make_prim('gray', - palette='colors', - style='box-style', - label=_('gray'), - help_string=_('holds current gray level (can be used in \ -place of a number block)'), - value_block=True, - prim_name='gray') + palette.add_block('gray', + style='box-style', + label=_('gray'), + 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) - self._make_constant('red', 'colors', CONSTANTS['red']) - self._make_constant('orange', 'colors', CONSTANTS['orange']) - self._make_constant('yellow', 'colors', CONSTANTS['yellow']) - self._make_constant('green', 'colors', CONSTANTS['green']) - self._make_constant('cyan', 'colors', CONSTANTS['cyan']) - self._make_constant('blue', 'colors', CONSTANTS['blue']) - self._make_constant('purple', 'colors', CONSTANTS['purple']) - self._make_constant('white', 'colors', WHITE) - self._make_constant('black', 'colors', BLACK) + self._make_constant(palette, 'red', CONSTANTS['red']) + self._make_constant(palette, 'orange', CONSTANTS['orange']) + self._make_constant(palette, 'yellow', CONSTANTS['yellow']) + self._make_constant(palette, 'green', CONSTANTS['green']) + self._make_constant(palette, 'cyan', CONSTANTS['cyan']) + self._make_constant(palette, 'blue', CONSTANTS['blue']) + self._make_constant(palette, 'purple', CONSTANTS['purple']) + self._make_constant(palette, 'white', WHITE) + self._make_constant(palette, 'black', BLACK) # deprecated blocks - make_prim('settextcolor', - style='basic-style-1arg', - label=_('set text color'), - prim_name='settextcolor', - default=0, - help_string=_('sets color of text drawn by the turtle')) + palette.add_block('settextcolor', + hidden=True, + style='basic-style-1arg', + label=_('set text color'), + prim_name='settextcolor', + default=0, + help_string=_('sets color of text drawn by the \ +turtle')) self.tw.lc.def_prim('settextcolor', 1, lambda self, x: self.tw.canvas.settextcolor(x)) - make_prim('settextsize', - style='basic-style-1arg', - label=_('set text size'), - prim_name='settextsize', - default=0, - help_string=_('sets size of text drawn by the turtle')) + palette.add_block('settextsize', + hidden=True, + style='basic-style-1arg', + label=_('set text size'), + prim_name='settextsize', + default=0, + help_string=_('sets size of text drawn by the \ +turtle')) self.tw.lc.def_prim('settextsize', 1, lambda self, x: self.tw.canvas.settextsize(x)) def _numbers_palette(self): """ The basic Turtle Art numbers palette """ - make_palette('numbers', - colors=["#FF00FF", "#A000A0"], - help_string=_('Palette of numeric operators')) + palette = make_palette('numbers', + colors=["#FF00FF", "#A000A0"], + help_string=_('Palette of numeric operators')) PLUGIN_DICTIONARY['plus'] = self._prim_plus - make_prim('plus2', - palette='numbers', - style='number-style', - label='+', - special_name=_('plus'), - prim_name='plus', - help_string=_('adds two alphanumeric inputs')) + palette.add_block('plus2', + style='number-style', + label='+', + special_name=_('plus'), + prim_name='plus', + help_string=_('adds two alphanumeric inputs')) self.tw.lc.def_prim( 'plus', 2, lambda self, x, y: PLUGIN_DICTIONARY['plus'](x, y)) PLUGIN_DICTIONARY['minus'] = self._prim_minus - make_prim('minus2', - palette='numbers', - style='number-style-porch', - label='–', - special_name=_('minus'), - prim_name='minus', - help_string=_('subtracts bottom numeric input from top \ -numeric input')) + palette.add_block('minus2', + style='number-style-porch', + label='–', + special_name=_('minus'), + prim_name='minus', + help_string=_('subtracts bottom numeric input from \ +top numeric input')) self.tw.lc.def_prim( 'minus', 2, lambda self, x, y: PLUGIN_DICTIONARY['minus'](x, y)) PLUGIN_DICTIONARY['product'] = self._prim_product - make_prim('product2', - palette='numbers', - style='number-style', - label='×', - special_name=_('multiply'), - prim_name='product', - help_string=_('multiplies two numeric inputs')) + palette.add_block('product2', + style='number-style', + label='×', + special_name=_('multiply'), + prim_name='product', + help_string=_('multiplies two numeric inputs')) self.tw.lc.def_prim( 'product', 2, lambda self, x, y: PLUGIN_DICTIONARY['product'](x, y)) PLUGIN_DICTIONARY['division'] = self._prim_careful_divide - make_prim('division2', - palette='numbers', - style='number-style-porch', - label='/', - special_name=_('divide'), - prim_name='division', - help_string=_('divides top numeric input (numerator) by \ -bottom numeric input (denominator)')) + palette.add_block('division2', + style='number-style-porch', + label='/', + special_name=_('divide'), + prim_name='division', + help_string=_('divides top numeric input (numerator) \ +by bottom numeric input (denominator)')) self.tw.lc.def_prim( 'division', 2, lambda self, x, y: PLUGIN_DICTIONARY['division'](x, y)) PLUGIN_DICTIONARY['id'] = self._prim_identity - make_prim('identity2', - palette='numbers', - style='number-style-1strarg', - label='←', - special_name=_('identity'), - prim_name='id', - help_string=_('identity operator used for extending blocks')) + palette.add_block('identity2', + style='number-style-1strarg', + label='←', + special_name=_('identity'), + prim_name='id', + help_string=_('identity operator used for extending \ +blocks')) self.tw.lc.def_prim('id', 1, lambda self, x: PLUGIN_DICTIONARY['id'](x)) PLUGIN_DICTIONARY['remainder'] = self._prim_mod - make_prim('remainder2', - palette='numbers', - style='number-style-porch', - label=_('mod'), - special_name=_('mod'), - prim_name='remainder', - help_string=_('modular (remainder) operator')) + palette.add_block('remainder2', + style='number-style-porch', + label=_('mod'), + special_name=_('mod'), + prim_name='remainder', + help_string=_('modular (remainder) operator')) self.tw.lc.def_prim('remainder', 2, lambda self, x, y: PLUGIN_DICTIONARY['remainder'](x, y)) PLUGIN_DICTIONARY['sqrt'] = self._prim_sqrt - make_prim('sqrt', - palette='numbers', - style='number-style-1arg', - label=_('√'), - special_name=_('square root'), - prim_name='sqrt', - help_string=_('calculates square root')) + palette.add_block('sqrt', + style='number-style-1arg', + label=_('√'), + special_name=_('square root'), + prim_name='sqrt', + help_string=_('calculates square root')) self.tw.lc.def_prim('sqrt', 1, lambda self, x: PLUGIN_DICTIONARY['sqrt'](x)) PLUGIN_DICTIONARY['random'] = self._prim_random - make_prim('random', - palette='numbers', - style='number-style-block', - label=[_('random'), _('min'), _('max')], - default=[0, 100], - prim_name='random', - help_string=_('returns random number between minimum (top) \ -and maximum (bottom) values')) + palette.add_block('random', + style='number-style-block', + label=[_('random'), _('min'), _('max')], + default=[0, 100], + prim_name='random', + help_string=_('returns random number between minimum \ +(top) and maximum (bottom) values')) self.tw.lc.def_prim( 'random', 2, lambda self, x, y: PLUGIN_DICTIONARY['random'](x, y)) - make_prim('number', - palette='numbers', - style='box-style', - label='100', - default=100, - special_name=_('number'), - help_string=_('used as numeric input in mathematic \ + palette.add_block('number', + style='box-style', + label='100', + default=100, + special_name=_('number'), + help_string=_('used as numeric input in mathematic \ operators')) PLUGIN_DICTIONARY['more'] = self._prim_more - make_prim('greater2', - palette='numbers', - style='compare-porch-style', - label='>', - special_name=_('greater than'), - prim_name='greater?', - help_string=_('logical greater-than operator')) + palette.add_block('greater2', + style='compare-porch-style', + label='>', + special_name=_('greater than'), + prim_name='greater?', + help_string=_('logical greater-than operator')) self.tw.lc.def_prim( 'greater?', 2, lambda self, x, y: PLUGIN_DICTIONARY['more'](x, y)) PLUGIN_DICTIONARY['less'] = self._prim_less - make_prim('less2', - palette='numbers', - style='compare-porch-style', - label='<', - special_name=_('less than'), - prim_name='less?', - help_string=_('logical less-than operator')) + palette.add_block('less2', + style='compare-porch-style', + label='<', + special_name=_('less than'), + prim_name='less?', + help_string=_('logical less-than operator')) self.tw.lc.def_prim( 'less?', 2, lambda self, x, y: PLUGIN_DICTIONARY['less'](x, y)) PLUGIN_DICTIONARY['equal'] = self._prim_equal - make_prim('equal2', - palette='numbers', - style='compare-style', - label='=', - special_name=_('equal'), - prim_name='equal?', - help_string=_('logical equal-to operator')) + palette.add_block('equal2', + style='compare-style', + label='=', + special_name=_('equal'), + prim_name='equal?', + help_string=_('logical equal-to operator')) self.tw.lc.def_prim( 'equal?', 2, lambda self, x, y: PLUGIN_DICTIONARY['equal'](x, y)) - make_prim('not', - palette='numbers', - style='not-style', - label=_('not'), - prim_name='not', - help_string=_('logical NOT operator')) + palette.add_block('not', + style='not-style', + label=_('not'), + prim_name='not', + help_string=_('logical NOT operator')) self.tw.lc.def_prim('not', 1, lambda self, x: not x) - make_prim('and2', - palette='numbers', - style='boolean-style', - label=_('and'), - prim_name='and', - special_name=_('and'), - help_string=_('logical AND operator')) + palette.add_block('and2', + style='boolean-style', + label=_('and'), + prim_name='and', + special_name=_('and'), + help_string=_('logical AND operator')) self.tw.lc.def_prim('not', 2, lambda self, x, y: x & y) - make_prim('or2', - palette='numbers', - style='boolean-style', - label=_('or'), - prim_name='or', - special_name=_('or'), - help_string=_('logical OR operator')) + palette.add_block('or2', + style='boolean-style', + label=_('or'), + prim_name='or', + special_name=_('or'), + help_string=_('logical OR operator')) self.tw.lc.def_prim('not', 2, lambda self, x, y: x | y) def _flow_palette(self): """ The basic Turtle Art flow palette """ - make_palette('flow', - colors=["#FFC000", "#A08000"], - help_string=_('Palette of flow operators')) + palette = make_palette('flow', + colors=["#FFC000", "#A08000"], + help_string=_('Palette of flow operators')) PLUGIN_DICTIONARY['wait'] = self._prim_wait - make_prim('wait', - palette='flow', - style='basic-style-1arg', - label=_('wait'), - prim_name='wait', - default=1, - help_string=_( - 'pauses program execution a specified number of seconds')) + palette.add_block('wait', + style='basic-style-1arg', + label=_('wait'), + prim_name='wait', + default=1, + help_string=_('pauses program execution a specified \ +number of seconds')) self.tw.lc.def_prim('wait', 1, PLUGIN_DICTIONARY['wait'], True) PLUGIN_DICTIONARY['forever'] = self._prim_forever - make_prim('forever', - palette='flow', - style='flow-style', - label=_('forever'), - prim_name='forever', - default=[None, 'vspace'], - help_string=_('loops forever')) + palette.add_block('forever', + style='flow-style', + label=_('forever'), + prim_name='forever', + default=[None, 'vspace'], + help_string=_('loops forever')) self.tw.lc.def_prim('forever', 1, PLUGIN_DICTIONARY['forever'], True) PLUGIN_DICTIONARY['repeat'] = self._prim_repeat - make_prim('repeat', - palette='flow', - style='flow-style-1arg', - label=[' ', _('repeat')], - prim_name='repeat', - default=[4, None, 'vspace'], - special_name=_('repeat'), - help_string=_('loops specified number of times')) + palette.add_block('repeat', + style='flow-style-1arg', + label=[' ', _('repeat')], + prim_name='repeat', + default=[4, None, 'vspace'], + special_name=_('repeat'), + help_string=_('loops specified number of times')) self.tw.lc.def_prim('repeat', 2, PLUGIN_DICTIONARY['repeat'], True) PLUGIN_DICTIONARY['if'] = self._prim_if - make_prim('if', - palette='flow', - style='flow-style-boolean', - label=[' ', _('if'), _('then')], - prim_name='if', - default=[None, None, 'vspace'], - special_name=_('if then'), - help_string=_('if-then operator that uses boolean \ + palette.add_block('if', + style='flow-style-boolean', + label=[' ', _('if'), _('then')], + prim_name='if', + default=[None, None, 'vspace'], + special_name=_('if then'), + help_string=_('if-then operator that uses boolean \ operators from Numbers palette')) self.tw.lc.def_prim('if', 2, PLUGIN_DICTIONARY['if'], True) PLUGIN_DICTIONARY['ifelse'] = self._prim_ifelse - make_prim('ifelse', - palette='flow', - style='flow-style-else', - label=[' ', _('if'), _('then else')], - prim_name='ifelse', - default=[None, 'vspace', None, 'vspace'], - special_name=_('if then else'), - help_string=_('if-then-else operator that uses boolean \ -operators from Numbers palette')) + palette.add_block('ifelse', + style='flow-style-else', + label=[' ', _('if'), _('then else')], + prim_name='ifelse', + default=[None, 'vspace', None, 'vspace'], + 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, PLUGIN_DICTIONARY['ifelse'], True) - make_prim('hspace', - palette='flow', - style='flow-style-tail', - label=' ', - prim_name='nop', - special_name=_('horizontal space'), - help_string=_('jogs stack right')) + palette.add_block('hspace', + style='flow-style-tail', + label=' ', + prim_name='nop', + special_name=_('horizontal space'), + help_string=_('jogs stack right')) self.tw.lc.def_prim('nop', 0, lambda self: None) - make_prim('vspace', - palette='flow', - style='basic-style-extended-vertical', - label=' ', - prim_name='nop', - special_name=_('vertical space'), - help_string=_('jogs stack down')) + palette.add_block('vspace', + style='basic-style-extended-vertical', + label=' ', + prim_name='nop', + special_name=_('vertical space'), + help_string=_('jogs stack down')) self.tw.lc.def_prim('nop', 0, lambda self: None) PLUGIN_DICTIONARY['stopstack'] = self._prim_stopstack - make_prim('stopstack', - palette='flow', - style='basic-style-tail', - label=_('stop action'), - prim_name='stopstack', - help_string=_('stops current action')) + palette.add_block('stopstack', + style='basic-style-tail', + label=_('stop action'), + prim_name='stopstack', + help_string=_('stops current action')) self.tw.lc.def_prim('stopstack', 0, lambda self: PLUGIN_DICTIONARY['stopstack']()) def _blocks_palette(self): """ The basic Turtle Art blocks palette """ - make_palette('blocks', - colors=["#FFFF00", "#A0A000"], - help_string=_('Palette of variable blocks')) + palette = make_palette('blocks', + colors=["#FFFF00", "#A0A000"], + help_string=_('Palette of variable blocks')) PLUGIN_DICTIONARY['start'] = self._prim_start - make_prim('start', - palette='blocks', - style='basic-style-head', - label=_('start'), - prim_name='start', - help_string=_('connects action to toolbar run buttons')) + palette.add_block('start', + style='basic-style-head', + label=_('start'), + prim_name='start', + help_string=_('connects action to toolbar run \ +buttons')) self.tw.lc.def_prim('start', 0, lambda self: PLUGIN_DICTIONARY['start']()) PLUGIN_DICTIONARY['setbox'] = self._prim_setbox - make_prim('storeinbox1', - palette='blocks', - style='basic-style-1arg', - label=_('store in box 1'), - prim_name='storeinbox1', - default=100, - help_string=_('stores numeric value in Variable 1')) + palette.add_block('storeinbox1', + style='basic-style-1arg', + label=_('store in box 1'), + prim_name='storeinbox1', + default=100, + help_string=_('stores numeric value in Variable 1')) self.tw.lc.def_prim('storeinbox1', 1, lambda self, x: PLUGIN_DICTIONARY['setbox']( 'box1', None, x)) - make_prim('storeinbox2', - palette='blocks', - style='basic-style-1arg', - label=_('store in box 2'), - prim_name='storeinbox2', - default=100, - help_string=_('stores numeric value in Variable 2')) + palette.add_block('storeinbox2', + style='basic-style-1arg', + label=_('store in box 2'), + prim_name='storeinbox2', + default=100, + help_string=_('stores numeric value in Variable 2')) self.tw.lc.def_prim('storeinbox2', 1, lambda self, x: PLUGIN_DICTIONARY['setbox']( 'box2', None, x)) - make_prim('string', - palette='blocks', - style='box-style', - label=_('text'), - default=_('text'), - special_name='', - help_string=_('string value')) - - make_prim('box1', - palette='blocks', - style='box-style', - label=_('box 1'), - prim_name='box1', - help_string=_('Variable 1 (numeric value)'), - value_block=True) + palette.add_block('string', + style='box-style', + label=_('text'), + default=_('text'), + special_name='', + help_string=_('string value')) + + palette.add_block('box1', + style='box-style', + label=_('box 1'), + prim_name='box1', + help_string=_('Variable 1 (numeric value)'), + value_block=True) self.tw.lc.def_prim('box1', 0, lambda self: self.tw.lc.boxes['box1']) - make_prim('box2', - palette='blocks', - style='box-style', - label=_('box 2'), - prim_name='box2', - help_string=_('Variable 2 (numeric value)'), - value_block=True) + palette.add_block('box2', + style='box-style', + label=_('box 2'), + prim_name='box2', + help_string=_('Variable 2 (numeric value)'), + value_block=True) self.tw.lc.def_prim('box2', 0, lambda self: self.tw.lc.boxes['box2']) PLUGIN_DICTIONARY['box'] = self._prim_box - make_prim('box', - palette='blocks', - style='number-style-1strarg', - label=_('box'), - prim_name='box', - default=_('my box'), - help_string=_('named variable (numeric value)')) + palette.add_block('box', + style='number-style-1strarg', + label=_('box'), + prim_name='box', + default=_('my box'), + help_string=_('named variable (numeric value)')) self.tw.lc.def_prim('box', 1, lambda self, x: PLUGIN_DICTIONARY['box'](x)) - make_prim('storein', - palette='blocks', - style='basic-style-2arg', - label=[_('store in'), _('box'), _('value')], - prim_name='storeinbox', - default=[_('my box'), 100], - help_string=_('stores numeric value in named variable')) + palette.add_block('storein', + style='basic-style-2arg', + label=[_('store in'), _('box'), _('value')], + prim_name='storeinbox', + default=[_('my box'), 100], + help_string=_('stores numeric value in named \ +variable')) self.tw.lc.def_prim('storeinbox', 2, lambda self, x, y: PLUGIN_DICTIONARY['setbox']( 'box3', x, y)) - make_prim('hat', - palette='blocks', - style='basic-style-head-1arg', - label=_('action'), - prim_name='nop3', - default=_('action'), - help_string=_('top of nameable action stack')) + palette.add_block('hat', + style='basic-style-head-1arg', + label=_('action'), + prim_name='nop3', + default=_('action'), + help_string=_('top of nameable action stack')) self.tw.lc.def_prim('nop3', 1, lambda self, x: None) - make_prim('hat1', - palette='blocks', - style='basic-style-head', - label=_('action 1'), - prim_name='nop1', - help_string=_('top of Action 1 stack')) + palette.add_block('hat1', + style='basic-style-head', + label=_('action 1'), + prim_name='nop1', + help_string=_('top of Action 1 stack')) self.tw.lc.def_prim('nop1', 0, lambda self: None) - make_prim('hat2', - palette='blocks', - style='basic-style-head', - label=_('action 2'), - prim_name='nop2', - help_string=_('top of Action 2 stack')) + palette.add_block('hat2', + style='basic-style-head', + label=_('action 2'), + prim_name='nop2', + help_string=_('top of Action 2 stack')) self.tw.lc.def_prim('nop2', 0, lambda self: None) PLUGIN_DICTIONARY['stack'] = self._prim_stack - make_prim('stack', - palette='blocks', - style='basic-style-1arg', - label=_('action'), - prim_name='stack', - default=_('action'), - help_string=_('invokes named action stack')) + palette.add_block('stack', + style='basic-style-1arg', + label=_('action'), + prim_name='stack', + default=_('action'), + help_string=_('invokes named action stack')) self.tw.lc.def_prim('stack', 1, PLUGIN_DICTIONARY['stack'], True) PLUGIN_DICTIONARY['stack1'] = self._prim_stack1 - make_prim('stack1', - palette='blocks', - style='basic-style-extended-vertical', - label=_('action 1'), - prim_name='stack1', - default=_('action 1'), - help_string=_('invokes Action 1 stack')) + palette.add_block('stack1', + style='basic-style-extended-vertical', + label=_('action 1'), + prim_name='stack1', + default=_('action 1'), + help_string=_('invokes Action 1 stack')) self.tw.lc.def_prim('stack1', 0, PLUGIN_DICTIONARY['stack1'], True) PLUGIN_DICTIONARY['stack2'] = self._prim_stack2 - make_prim('stack2', - palette='blocks', - style='basic-style-extended-vertical', - label=_('action 2'), - prim_name='stack2', - default=_('action 2'), - help_string=_('invokes Action 2 stack')) + palette.add_block('stack2', + style='basic-style-extended-vertical', + label=_('action 2'), + prim_name='stack2', + default=_('action 2'), + help_string=_('invokes Action 2 stack')) self.tw.lc.def_prim('stack2', 0, PLUGIN_DICTIONARY['stack2'], True) def _trash_palette(self): """ The basic Turtle Art turtle palette """ - make_palette('trash', - colors=["#FFFF00", "#A0A000"]) + palette = make_palette('trash', + colors=["#FFFF00", "#A0A000"]) - make_prim('empty', - palette='trash', - style='basic-style-tail', - label=_('empty trash'), - help_string=_("permanently deletes items in trash")) + palette.add_block('empty', + style='basic-style-tail', + label=_('empty trash'), + help_string=_("permanently deletes items in trash")) - make_prim('restoreall', - palette='trash', - style='basic-style-head', - label=_('restore all'), - help_string=_("restore all blocks from trash")) + palette.add_block('restoreall', + style='basic-style-head', + label=_('restore all'), + help_string=_("restore all blocks from trash")) # Block primitives @@ -1151,8 +1102,8 @@ operators from Numbers palette')) else: raise logoerror("#syntaxerror") - def _make_constant(self, block_name, palette_name, constant): + def _make_constant(self, palette, block_name, constant): """ Factory for constant blocks """ - make_prim(block_name, palette=palette_name, style='box-style', - label=_(block_name), prim_name=block_name) + palette.add_block(block_name, style='box-style', + label=_(block_name), prim_name=block_name) self.tw.lc.def_prim(block_name, 0, lambda self: constant) diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 7d73ff2..7eea957 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -70,19 +70,46 @@ class Palette(): def set_special_name(self, name): self._special_name = name + 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): + """ Add a new block to the palette """ + block = Block(block_name) + block.set_style(style) + if label is not None: + block.set_label(label) + if special_name is not None: + block.set_special_name(special_name) + if default is not None: + if default == 'None': + block.set_default(None) + else: + block.set_default(default) + if prim_name is not None: + block.set_prim_name(prim_name) + if help_string is not None: + block.set_help(help_string) + block.set_value_block(value_block) + block.set_content_block(content_block) + if not hidden: + block.set_palette(self._name) + block.add_block() + def make_palette(palette_name, colors=None, help_string=None): """ Palette helper function """ if colors is None: - p = Palette(palette_name) + palette = Palette(palette_name) else: - p = Palette(palette_name, colors) + palette = Palette(palette_name, colors) if help_string is not None: - p.set_help(help_string) - p.add_palette() + palette.set_help(help_string) + palette.add_palette() + return palette -class Primitive(): +class Block(): """ a class for defining new block primitives """ def __init__(self, name): @@ -97,7 +124,7 @@ class Primitive(): self._value_block = False self._content_block = False - def add_prim(self, position=None): + def add_block(self, position=None): if self._name is None: debug_output('You must specify a name for your block') return @@ -182,29 +209,3 @@ class Primitive(): def set_prim_name(self, prim_name): self._prim_name = prim_name - - -def make_prim(block_name, style='basic-block', palette=None, label=None, - special_name=None, default=None, prim_name=None, - help_string=None, value_block=False, content_block=False): - """ Primitive helper function """ - b = Primitive(block_name) - b.set_style(style) - if palette is not None: - b.set_palette(palette) - if label is not None: - b.set_label(label) - if special_name is not None: - b.set_special_name(special_name) - if default is not None: - if default == 'None': - b.set_default(None) - else: - b.set_default(default) - if prim_name is not None: - b.set_prim_name(prim_name) - if help_string is not None: - b.set_help(help_string) - b.set_value_block(value_block) - b.set_content_block(content_block) - b.add_prim() diff --git a/plugins/audio_sensors_plugin.py b/plugins/audio_sensors_plugin.py index 6723b9c..e5bd759 100644 --- a/plugins/audio_sensors_plugin.py +++ b/plugins/audio_sensors_plugin.py @@ -31,7 +31,7 @@ from audio.audiograb import AudioGrab_Unknown, AudioGrab_XO1, AudioGrab_XO15, \ from audio.ringbuffer import RingBuffer1d -from TurtleArt.taprimitive import make_palette, make_prim +from TurtleArt.taprimitive import make_palette from TurtleArt.taconstants import XO1, XO15 from TurtleArt.talogo import PLUGIN_DICTIONARY @@ -77,71 +77,67 @@ class Audio_sensors_plugin(Plugin): self.voltage_gain = -0.0001471 self.voltage_bias = 1.695 - make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks')) + palette = make_palette('sensor', + colors=["#FF6060", "#A06060"], + help_string=_('Palette of sensor blocks')) PLUGIN_DICTIONARY['sound'] = self.prim_sound - make_prim('sound', - palette='sensor', - style='box-style', - label=_('sound'), - help_string=_('raw microphone input signal'), - value_block=True, - prim_name='sound') + palette.add_block('sound', + style='box-style', + label=_('sound'), + help_string=_('raw microphone input signal'), + value_block=True, + prim_name='sound') self._parent.lc.def_prim('sound', 0, lambda self: PLUGIN_DICTIONARY['sound']()) PLUGIN_DICTIONARY['volume'] = self.prim_volume - make_prim('volume', - palette='sensor', - style='box-style', - label=_('loudness'), - help_string=_('microphone input volume'), - value_block=True, - prim_name='volume') + palette.add_block('volume', + style='box-style', + label=_('loudness'), + help_string=_('microphone input volume'), + value_block=True, + prim_name='volume') self._parent.lc.def_prim('volume', 0, lambda self: PLUGIN_DICTIONARY['volume']()) PLUGIN_DICTIONARY['pitch'] = self.prim_pitch if PITCH_AVAILABLE: - make_prim('pitch', - palette='sensor', - style='box-style', - label=_('pitch'), - help_string=_('microphone input pitch'), - value_block=True, - prim_name='pitch') + palette.add_block('pitch', + style='box-style', + label=_('pitch'), + help_string=_('microphone input pitch'), + value_block=True, + prim_name='pitch') else: - make_prim('pitch', - style='box-style', - label=_('pitch'), - help_string=_('microphone input pitch'), - value_block=True, - prim_name='pitch') + palette.add_block('pitch', + hidden=True, + style='box-style', + label=_('pitch'), + help_string=_('microphone input pitch'), + value_block=True, + prim_name='pitch') self._parent.lc.def_prim('pitch', 0, lambda self: PLUGIN_DICTIONARY['pitch']()) if self.hw in [XO1, XO15]: PLUGIN_DICTIONARY['resistance'] = self.prim_resistance - make_prim('resistance', - palette='sensor', - style='box-style', - label=_('resistance'), - help_string=_('microphone input resistance'), - value_block=True, - prim_name='resistance') + palette.add_block('resistance', + style='box-style', + label=_('resistance'), + help_string=_('microphone input resistance'), + value_block=True, + prim_name='resistance') self._parent.lc.def_prim('resistance', 0, lambda self: PLUGIN_DICTIONARY['resistance']()) PLUGIN_DICTIONARY['voltage'] = self.prim_voltage - make_prim('voltage', - palette='sensor', - style='box-style', - label=_('voltage'), - help_string=_('microphone input voltage'), - value_block=True, - prim_name='voltage') + palette.add_block('voltage', + style='box-style', + label=_('voltage'), + help_string=_('microphone input voltage'), + value_block=True, + prim_name='voltage') self._parent.lc.def_prim('voltage', 0, lambda self: PLUGIN_DICTIONARY['voltage']()) diff --git a/plugins/camera_plugin.py b/plugins/camera_plugin.py index 0a2ec02..48e807f 100644 --- a/plugins/camera_plugin.py +++ b/plugins/camera_plugin.py @@ -27,7 +27,7 @@ from camera.v4l2 import v4l2_control, V4L2_CID_AUTOGAIN, VIDIOC_G_CTRL, \ from plugin import Plugin -from TurtleArt.taprimitive import make_palette, make_prim +from TurtleArt.taprimitive import make_palette from TurtleArt.talogo import MEDIA_BLOCKS_DICTIONARY, PLUGIN_DICTIONARY from TurtleArt.tautils import get_path @@ -54,44 +54,42 @@ class Camera_plugin(Plugin): self._status = True def setup(self): - make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks')) + palette = make_palette('sensor', + colors=["#FF6060", "#A06060"], + help_string=_('Palette of sensor blocks')) # set up camera-specific blocks if self._status: PLUGIN_DICTIONARY['luminance'] = self.prim_read_camera - make_prim('luminance', - palette='sensor', - style='box-style', - label=_('brightness'), - help_string=_('light level detected by camera'), - value_block=True, - prim_name='luminance') + palette.add_block('luminance', + style='box-style', + label=_('brightness'), + help_string=_('light level detected by camera'), + value_block=True, + prim_name='luminance') self._parent.lc.def_prim('luminance', 0, lambda self: PLUGIN_DICTIONARY['luminance'](True)) # Depreciated block PLUGIN_DICTIONARY['read_camera'] = self.prim_read_camera - make_prim('read_camera', - palette='sensor', - style='box-style', - label=_('brightness'), - help_string=_('Average RGB color from camera is pushed \ -to the stack'), - value_block=True, - prim_name='luminance') + palette.add_block('read_camera', + hidden=True, + style='box-style', + label=_('brightness'), + help_string=_('Average RGB color from camera \ +is pushed to the stack'), + value_block=True, + prim_name='luminance') self._parent.lc.def_prim('read_camera', 0, lambda self: PLUGIN_DICTIONARY['read_camera'](True)) MEDIA_BLOCKS_DICTIONARY['camera'] = self.prim_take_picture - make_prim('camera', - palette='sensor', - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) + palette.add_block('camera', + style='box-style-media', + label=' ', + default='CAMERA', + help_string=_('camera output'), + content_block=True) def stop(self): # This gets called by the stop button diff --git a/plugins/rfid_plugin.py b/plugins/rfid_plugin.py index ee26152..ae91a4e 100644 --- a/plugins/rfid_plugin.py +++ b/plugins/rfid_plugin.py @@ -25,7 +25,7 @@ from rfid.rfidutils import strhex2bin, strbin2dec, find_device from plugin import Plugin -from TurtleArt.taprimitive import make_palette, make_prim +from TurtleArt.taprimitive import make_palette from TurtleArt.talogo import PLUGIN_DICTIONARY import logging @@ -82,18 +82,18 @@ class Rfid_plugin(Plugin): def setup(self): # set up RFID-specific blocks if self._status: - make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks')) + palette = make_palette('sensor', + colors=["#FF6060", "#A06060"], + help_string=_('Palette of sensor blocks')) PLUGIN_DICTIONARY['rfid'] = self.prim_read_camera - make_prim('rfid', - palette='sensor', - style='box-style', - label=_('RFID'), - help_string=_('read value from RFID device'), - value_block=True, - prim_name='rfid') + palette.add_block('rfid', + palette='sensor', + style='box-style', + label=_('RFID'), + help_string=_('read value from RFID device'), + value_block=True, + prim_name='rfid') self._parent.lc.def_prim('rfid', 0, lambda self: PLUGIN_DICTIONARY['rfid'](True)) diff --git a/plugins/turtle_blocks_plugin.py b/plugins/turtle_blocks_plugin.py index 2f02171..79ebcd6 100644 --- a/plugins/turtle_blocks_plugin.py +++ b/plugins/turtle_blocks_plugin.py @@ -26,7 +26,7 @@ except ImportError: pass from plugin import Plugin -from TurtleArt.taprimitive import make_palette, make_prim +from TurtleArt.taprimitive import make_palette from TurtleArt.talogo import PLUGIN_DICTIONARY, logoerror, \ MEDIA_BLOCKS_DICTIONARY from TurtleArt.taconstants import DEFAULT_SCALE, CONSTANTS, ICON_SIZE @@ -88,674 +88,663 @@ class Turtle_blocks_plugin(Plugin): # Palette definitions def _flow_palette(self): + palette = make_palette('flow', + colors=["#FFC000", "#A08000"], + help_string=_('Palette of flow operators')) + # macro - make_prim('while', - palette='flow', - style='flow-style-boolean', - label=_('while'), - help_string=_('do-while-True operator that uses boolean \ -operators from Numbers palette')) + palette.add_block('while', + style='flow-style-boolean', + label=_('while'), + help_string=_('do-while-True operator that uses \ +boolean operators from Numbers palette')) # macro - make_prim('until', - palette='flow', - style='flow-style-boolean', - label=_('until'), - help_string=_('do-until-True operator that uses boolean \ -operators from Numbers palette')) + palette.add_block('until', + style='flow-style-boolean', + label=_('until'), + help_string=_('do-until-True operator that uses \ +boolean operators from Numbers palette')) def _media_palette(self): - make_palette('media', + palette = make_palette('media', colors=["#A0FF00", "#80A000"], help_string=_('Palette of media objects')) - make_prim('journal', - palette='media', - style='box-style-media', - label=' ', - default='None', - special_name=_('journal'), - help_string=_('Sugar Journal media object')) - - make_prim('audio', - palette='media', - style='box-style-media', - label=' ', - special_name=_('audio'), - default='None', - help_string=_('Sugar Journal audio object')) - - make_prim('video', - palette='media', - style='box-style-media', - label=' ', - special_name=_('video'), - default='None', - help_string=_('Sugar Journal video object')) - - make_prim('description', - palette='media', - style='box-style-media', - label=' ', - special_name=_('description'), - default='None', - help_string=_('Sugar Journal description field')) - - make_prim('string', - palette='media', - style='box-style', - label=_('text'), - default=_('text'), - special_name='', - help_string=_('string value')) + palette.add_block('journal', + style='box-style-media', + label=' ', + default='None', + special_name=_('journal'), + help_string=_('Sugar Journal media object')) + + palette.add_block('audio', + style='box-style-media', + label=' ', + special_name=_('audio'), + default='None', + help_string=_('Sugar Journal audio object')) + + palette.add_block('video', + style='box-style-media', + label=' ', + special_name=_('video'), + default='None', + help_string=_('Sugar Journal video object')) + + palette.add_block('description', + style='box-style-media', + label=' ', + special_name=_('description'), + default='None', + help_string=_('Sugar Journal description field')) + + palette.add_block('string', + style='box-style', + label=_('text'), + default=_('text'), + special_name='', + help_string=_('string value')) PLUGIN_DICTIONARY['show'] = self._prim_show - make_prim('show', - palette='media', - style='basic-style-1arg', - label=_('show'), - default=_('text'), - prim_name='show', - help_string=_('draws text or show media from the Journal')) + palette.add_block('show', + style='basic-style-1arg', + label=_('show'), + default=_('text'), + prim_name='show', + help_string=_('draws text or show media from the \ +Journal')) self.tw.lc.def_prim('show', 1, lambda self, x: PLUGIN_DICTIONARY['show'](x, True)) - make_prim('showaligned', - style='basic-style-1arg', - label=_('show aligned'), - default=_('text'), - prim_name='showaligned', - help_string=_('draws text or show media from the Journal')) + palette.add_block('showaligned', + hidden=True, + style='basic-style-1arg', + label=_('show aligned'), + default=_('text'), + prim_name='showaligned', + help_string=_('draws text or show media from the \ +Journal')) self.tw.lc.def_prim('showaligned', 1, lambda self, x: PLUGIN_DICTIONARY['show'](x, False)) # deprecated PLUGIN_DICTIONARY['write'] = self._prim_write - make_prim('write', - style='basic-style-1arg', - label=_('show'), - default=[_('text'), 32], - prim_name='write', - help_string=_('draws text or show media from the Journal')) + palette.add_block('write', + hidden=True, + style='basic-style-1arg', + label=_('show'), + default=[_('text'), 32], + prim_name='write', + help_string=_('draws text or show media from the \ +Journal')) self.tw.lc.def_prim('write', 2, lambda self, x, y: PLUGIN_DICTIONARY['write'](x, y)) PLUGIN_DICTIONARY['setscale'] = self._prim_setscale - make_prim('setscale', - palette='media', - style='basic-style-1arg', - label=_('set scale'), - prim_name='setscale', - default=33, - help_string=_('sets the scale of media')) + palette.add_block('setscale', + style='basic-style-1arg', + label=_('set scale'), + prim_name='setscale', + default=33, + help_string=_('sets the scale of media')) self.tw.lc.def_prim('setscale', 1, lambda self, x: PLUGIN_DICTIONARY['setscale'](x)) PLUGIN_DICTIONARY['savepix'] = self._prim_save_picture - make_prim('savepix', - palette='media', - style='basic-style-1arg', - label=_('save picture'), - prim_name='savepix', - default=_('picture name'), - help_string=_('saves a picture to the Sugar Journal')) + palette.add_block('savepix', + style='basic-style-1arg', + label=_('save picture'), + prim_name='savepix', + default=_('picture name'), + help_string=_('saves a picture to the Sugar Journal')) self.tw.lc.def_prim('savepix', 1, lambda self, x: PLUGIN_DICTIONARY['savepix'](x)) PLUGIN_DICTIONARY['savesvg'] = self._prim_save_svg - make_prim('savesvg', - palette='media', - style='basic-style-1arg', - label=_('save SVG'), - prim_name='savesvg', - default=_('picture name'), - help_string=_('saves turtle graphics as an SVG file in the \ -Sugar Journal')) + palette.add_block('savesvg', + style='basic-style-1arg', + label=_('save SVG'), + prim_name='savesvg', + default=_('picture name'), + help_string=_('saves turtle graphics as an SVG file \ +in the Sugar Journal')) self.tw.lc.def_prim('savesvg', 1, lambda self, x: PLUGIN_DICTIONARY['savesvg'](x)) - make_prim('scale', - palette='media', - style='box-style', - label=_('scale'), - prim_name='scale', - value_block=True, - help_string=_('holds current scale value')) + palette.add_block('scale', + style='box-style', + label=_('scale'), + prim_name='scale', + value_block=True, + help_string=_('holds current scale value')) self.tw.lc.def_prim('scale', 0, lambda self: self.tw.lc.scale) - make_prim('mediawait', - palette='media', - style='basic-style-extended-vertical', - label=_('media wait'), - prim_name='mediawait', - help_string=_('wait for current video or audio to complete')) + palette.add_block('mediawait', + style='basic-style-extended-vertical', + label=_('media wait'), + prim_name='mediawait', + help_string=_('wait for current video or audio to \ +complete')) self.tw.lc.def_prim('mediawait', 0, self.tw.lc.media_wait, True) def _sensor_palette(self): - make_palette('sensor', + palette = make_palette('sensor', colors=["#FF6060", "#A06060"], help_string=_('Palette of sensor blocks')) PLUGIN_DICTIONARY['kbinput'] = self._prim_kbinput - make_prim('kbinput', - palette='sensor', - style='basic-style-extended-vertical', - label=_('query keyboard'), - prim_name='kbinput', - help_string=_('query for keyboard input (results stored in \ -keyboard block)')) + palette.add_block('kbinput', + style='basic-style-extended-vertical', + label=_('query keyboard'), + prim_name='kbinput', + help_string=_('query for keyboard input (results \ +stored in keyboard block)')) self.tw.lc.def_prim('kbinput', 0, lambda self: PLUGIN_DICTIONARY['kbinput']()) - - make_prim('keyboard', - palette='sensor', - style='box-style', - label=_('keyboard'), - prim_name='keyboard', - value_block=True, - help_string=_('holds results of query-keyboard block')) + palette.add_block('keyboard', + style='box-style', + label=_('keyboard'), + prim_name='keyboard', + value_block=True, + help_string=_('holds results of query-keyboard \ +block')) self.tw.lc.def_prim('keyboard', 0, lambda self: self.tw.lc.keyboard) PLUGIN_DICTIONARY['readpixel'] = self._prim_readpixel - make_prim('readpixel', - palette='sensor', - style='basic-style-extended-vertical', - label=_('read pixel'), - prim_name='readpixel', - help_string=_('RGB color under the turtle is pushed to the \ -stack')) + palette.add_block('readpixel', + style='basic-style-extended-vertical', + label=_('read pixel'), + prim_name='readpixel', + help_string=_('RGB color under the turtle is pushed \ +to the stack')) self.tw.lc.def_prim('readpixel', 0, lambda self: PLUGIN_DICTIONARY['readpixel']()) PLUGIN_DICTIONARY['see'] = self._prim_see - make_prim('see', - palette='sensor', - style='box-style', - label=_('turtle sees'), - prim_name='see', - help_string=_('returns the color that the turtle "sees"')) + palette.add_block('see', + style='box-style', + label=_('turtle sees'), + prim_name='see', + help_string=_('returns the color that the turtle \ +"sees"')) self.tw.lc.def_prim('see', 0, lambda self: PLUGIN_DICTIONARY['see']()) PLUGIN_DICTIONARY['time'] = self._prim_time - make_prim('time', - palette='sensor', - style='box-style', - label=_('time'), - prim_name='time', - value_block=True, - help_string=_('elapsed time (in seconds) since program \ -started')) + palette.add_block('time', + style='box-style', + label=_('time'), + prim_name='time', + value_block=True, + help_string=_('elapsed time (in seconds) since \ +program started')) self.tw.lc.def_prim('time', 0, lambda self: PLUGIN_DICTIONARY['time']()) def _extras_palette(self): - make_palette('extras', + palette = make_palette('extras', colors=["#FF0000", "#A00000"], help_string=_('Palette of extra options')) PLUGIN_DICTIONARY['push'] = self._prim_push - make_prim('push', - palette='extras', - style='basic-style-1arg', - label=_('push'), - prim_name='push', - help_string=_('pushes value onto FILO (first-in last-out \ -heap)')) + palette.add_block('push', + style='basic-style-1arg', + label=_('push'), + prim_name='push', + help_string=_('pushes value onto FILO (first-in \ +last-out heap)')) self.tw.lc.def_prim('push', 1, lambda self, x: PLUGIN_DICTIONARY['push'](x)) PLUGIN_DICTIONARY['printheap'] = self._prim_printheap - make_prim('printheap', - palette='extras', - style='basic-style-extended-vertical', - label=_('show heap'), - prim_name='printheap', - help_string=_('shows values in FILO (first-in last-out \ -heap)')) + palette.add_block('printheap', + style='basic-style-extended-vertical', + label=_('show heap'), + prim_name='printheap', + help_string=_('shows values in FILO (first-in \ +last-out heap)')) self.tw.lc.def_prim('printheap', 0, lambda self: PLUGIN_DICTIONARY['printheap']()) PLUGIN_DICTIONARY['clearheap'] = self._prim_emptyheap - make_prim('clearheap', - palette='extras', - style='basic-style-extended-vertical', - label=_('empty heap'), - prim_name='clearheap', - help_string=_('emptys FILO (first-in-last-out heap)')) + palette.add_block('clearheap', + style='basic-style-extended-vertical', + label=_('empty heap'), + prim_name='clearheap', + help_string=_('emptys FILO (first-in-last-out heap)')) self.tw.lc.def_prim('clearheap', 0, lambda self: PLUGIN_DICTIONARY['clearheap']()) PLUGIN_DICTIONARY['pop'] = self._prim_pop - make_prim('pop', - palette='extras', - style='box-style', - label=_('pop'), - prim_name='pop', - value_block=True, - help_string=_('pops value off FILO (first-in last-out heap)')) + palette.add_block('pop', + style='box-style', + label=_('pop'), + prim_name='pop', + value_block=True, + help_string=_('pops value off FILO (first-in \ +last-out heap)')) self.tw.lc.def_prim('pop', 0, lambda self: PLUGIN_DICTIONARY['pop']()) PLUGIN_DICTIONARY['print'] = self._prim_print - make_prim('comment', - palette='extras', - style='basic-style-1arg', - label=_('comment'), - prim_name='comment', - default=_('comment'), - help_string=_('places a comment in your code')) + palette.add_block('comment', + style='basic-style-1arg', + label=_('comment'), + prim_name='comment', + default=_('comment'), + help_string=_('places a comment in your code')) self.tw.lc.def_prim('comment', 1, lambda self, x: PLUGIN_DICTIONARY['print'](x, True)) - make_prim('print', - palette='extras', - style='basic-style-1arg', - label=_('print'), - prim_name='print', - help_string=_('prints value in status block at bottom of \ -the screen')) + palette.add_block('print', + style='basic-style-1arg', + label=_('print'), + prim_name='print', + help_string=_('prints value in status block at \ +bottom of the screen')) self.tw.lc.def_prim('print', 1, lambda self, x: PLUGIN_DICTIONARY['print'](x, False)) PLUGIN_DICTIONARY['myfunction'] = self._prim_myfunction - make_prim('myfunc1arg', - palette='extras', - style='number-style-var-arg', - label=[_('Python'), 'f(x)', 'x'], - prim_name='myfunction', - default=['x', 100], - help_string=_('a programmable block: used to add advanced \ -single-variable math equations, e.g., sin(x)')) + palette.add_block('myfunc1arg', + style='number-style-var-arg', + label=[_('Python'), 'f(x)', 'x'], + prim_name='myfunction', + default=['x', 100], + help_string=_('a programmable block: used to add \ +advanced single-variable math equations, e.g., sin(x)')) self.tw.lc.def_prim('myfunction', 2, lambda self, f, x: PLUGIN_DICTIONARY['myfunction'](f, [x])) - make_prim('myfunc2arg', - style='number-style-var-arg', - label=[_('Python'), 'f(x,y)', 'x'], - prim_name='myfunction2', - default=['x+y', 100, 100], - help_string=_('a programmable block: used to add advanced \ -multi-variable math equations, e.g., sqrt(x*x+y*y)')) + palette.add_block('myfunc2arg', + hidden=True, + style='number-style-var-arg', + label=[_('Python'), 'f(x,y)', 'x'], + prim_name='myfunction2', + default=['x+y', 100, 100], + help_string=_('a programmable block: used to add \ +advanced multi-variable math equations, e.g., sqrt(x*x+y*y)')) self.tw.lc.def_prim('myfunction2', 3, lambda self, f, x, y: PLUGIN_DICTIONARY['myfunction'](f, [x, y])) - make_prim('myfunc3arg', - style='number-style-var-arg', - label=[_('Python'), 'f(x,y,z)', 'x'], - prim_name='myfunction3', - default=['x+y+z', 100, 100, 100], - help_string=_('a programmable block: used to add advanced \ -multi-variable math equations, e.g., sin(x+y+z)')) + palette.add_block('myfunc3arg', + hidden=True, + style='number-style-var-arg', + label=[_('Python'), 'f(x,y,z)', 'x'], + prim_name='myfunction3', + default=['x+y+z', 100, 100, 100], + help_string=_('a programmable block: used to add \ +advanced multi-variable math equations, e.g., sin(x+y+z)')) self.tw.lc.def_prim('myfunction3', 4, lambda self, f, x, y, z: PLUGIN_DICTIONARY['myfunction']( f, [x, y, z])) PLUGIN_DICTIONARY['userdefined'] = self._prim_myblock - make_prim('userdefined', - palette='extras', - style='basic-style-var-arg', - label=' ', - prim_name='userdefined', - special_name=_('Python block'), - default=100, - help_string=_('runs code found in the tamyblock.py module \ -found in the Journal')) + palette.add_block('userdefined', + style='basic-style-var-arg', + label=' ', + prim_name='userdefined', + special_name=_('Python block'), + default=100, + help_string=_('runs code found in the tamyblock.py \ +module found in the Journal')) self.tw.lc.def_prim('userdefined', 1, lambda self, x: PLUGIN_DICTIONARY['userdefined']([x])) - make_prim('userdefined2args', - style='basic-style-var-arg', - label=' ', - prim_name='userdefined2', - special_name=_('Python block'), - default=[100, 100], - help_string=_('runs code found in the tamyblock.py module \ -found in the Journal')) + palette.add_block('userdefined2args', + hidden=True, + style='basic-style-var-arg', + label=' ', + prim_name='userdefined2', + special_name=_('Python block'), + default=[100, 100], + help_string=_('runs code found in the tamyblock.py \ +module found in the Journal')) self.tw.lc.def_prim('userdefined2', 2, lambda self, x, y: PLUGIN_DICTIONARY['userdefined']([x, y])) - make_prim('userdefined3args', - style='basic-style-var-arg', - label=' ', - prim_name='userdefined3', - special_name=_('Python block'), - default=[100, 100, 100], - help_string=_('runs code found in the tamyblock.py module \ -found in the Journal')) + palette.add_block('userdefined3args', + hidden=True, + style='basic-style-var-arg', + label=' ', + prim_name='userdefined3', + special_name=_('Python block'), + default=[100, 100, 100], + help_string=_('runs code found in the tamyblock.py \ +module found in the Journal')) self.tw.lc.def_prim('userdefined3', 3, lambda self, x, y, z: PLUGIN_DICTIONARY['userdefined']([x, y, z])) - make_prim('cartesian', - palette='extras', - style='basic-style-extended-vertical', - label=_('Cartesian'), - prim_name='cartesian', - help_string=_('displays Cartesian coordinates')) + palette.add_block('cartesian', + style='basic-style-extended-vertical', + label=_('Cartesian'), + prim_name='cartesian', + help_string=_('displays Cartesian coordinates')) self.tw.lc.def_prim('cartesian', 0, lambda self: self.tw.set_cartesian(True)) - make_prim('polar', - palette='extras', - style='basic-style-extended-vertical', - label=_('polar'), - prim_name='polar', - help_string=_('displays polar coordinates')) + palette.add_block('polar', + style='basic-style-extended-vertical', + label=_('polar'), + prim_name='polar', + help_string=_('displays polar coordinates')) self.tw.lc.def_prim('polar', 0, lambda self: self.tw.set_polar(True)) - make_prim('addturtle', - palette='extras', - style='basic-style-1arg', - label=_('turtle'), - prim_name='turtle', - default=1, - help_string=_('chooses which turtle to command')) + palette.add_block('addturtle', + style='basic-style-1arg', + label=_('turtle'), + prim_name='turtle', + default=1, + help_string=_('chooses which turtle to command')) self.tw.lc.def_prim('turtle', 1, lambda self, x: self.tw.canvas.set_turtle(x)) PLUGIN_DICTIONARY['skin'] = self._prim_reskin - make_prim('skin', - style='basic-style-1arg', - label=_('turtle shell'), - prim_name='skin', - help_string=_("put a custom 'shell' on the turtle")) + palette.add_block('skin', + hidden=True, + style='basic-style-1arg', + label=_('turtle shell'), + prim_name='skin', + help_string=_("put a custom 'shell' on the turtle")) self.tw.lc.def_prim('skin', 1, lambda self, x: PLUGIN_DICTIONARY['skin'](x)) # macro - make_prim('reskin', - palette='extras', - style='basic-style-1arg', - label=_('turtle shell'), - help_string=_("put a custom 'shell' on the turtle")) - - make_prim('sandwichtop_no_label', - palette='extras', - style='collapsible-top-no-label', - label=[' ', ' '], - special_name=_('top'), - prim_name='nop', - help_string=_('top of a collapsed stack')) - - make_prim('sandwichbottom', - palette='extras', - style='collapsible-bottom', - label=[' ', ' '], - prim_name='nop', - special_name=_('bottom'), - help_string=_('bottom of a collapsible stack')) - - make_prim('sandwichcollapsed', - style='invisible', - label=' ', - prim_name='nop', - help_string=_('bottom block in a collapsed stack: click to \ -open')) + palette.add_block('reskin', + style='basic-style-1arg', + label=_('turtle shell'), + help_string=_("put a custom 'shell' on the turtle")) + + palette.add_block('sandwichtop_no_label', + style='collapsible-top-no-label', + label=[' ', ' '], + special_name=_('top'), + prim_name='nop', + help_string=_('top of a collapsed stack')) + + palette.add_block('sandwichbottom', + style='collapsible-bottom', + label=[' ', ' '], + prim_name='nop', + special_name=_('bottom'), + help_string=_('bottom of a collapsible stack')) + + palette.add_block('sandwichcollapsed', + hidden=True, + style='invisible', + label=' ', + prim_name='nop', + help_string=_('bottom block in a collapsed stack: \ +click to open')) # deprecated blocks - make_prim('sandwichtop', - style='collapsible-top', - label=_('top of stack'), - default=_('label'), - prim_name='comment', - help_string=_('top of stack')) - - make_prim('sandwichtop_no_arm', - style='collapsible-top-no-arm', - label=_('top of a collapsible stack'), - default=_('label'), - prim_name='comment', - help_string=_('top of stack')) - - make_prim('sandwichtop_no_arm_no_label', - style='collapsible-top-no-arm-no-label', - label=[' ', _('click to open')], - prim_name='nop', - help_string=_('top of stack')) + palette.add_block('sandwichtop', + hidden=True, + style='collapsible-top', + label=_('top of stack'), + default=_('label'), + prim_name='comment', + help_string=_('top of stack')) + + palette.add_block('sandwichtop_no_arm', + hidden=True, + style='collapsible-top-no-arm', + label=_('top of a collapsible stack'), + default=_('label'), + prim_name='comment', + help_string=_('top of stack')) + + palette.add_block('sandwichtop_no_arm_no_label', + hidden=True, + style='collapsible-top-no-arm-no-label', + label=[' ', _('click to open')], + prim_name='nop', + help_string=_('top of stack')) def _portfolio_palette(self): - make_palette('portfolio', + palette = make_palette('portfolio', colors=["#0606FF", "#0606A0"], help_string=_('Palette of presentation templates')) - make_prim('hideblocks', - palette='portfolio', - style='basic-style-extended-vertical', - label=_('hide blocks'), - prim_name='hideblocks', - help_string=_('declutters canvas by hiding blocks')) + palette.add_block('hideblocks', + style='basic-style-extended-vertical', + label=_('hide blocks'), + prim_name='hideblocks', + help_string=_('declutters canvas by hiding blocks')) self.tw.lc.def_prim('hideblocks', 0, lambda self: self.tw.hideblocks()) - make_prim('showblocks', - palette='portfolio', - style='basic-style-extended-vertical', - label=_('show blocks'), - prim_name='showblocks', - help_string=_('restores hidden blocks')) + palette.add_block('showblocks', + style='basic-style-extended-vertical', + label=_('show blocks'), + prim_name='showblocks', + help_string=_('restores hidden blocks')) self.tw.lc.def_prim('showblocks', 0, lambda self: self.tw.showblocks()) - make_prim('fullscreen', - palette='portfolio', - style='basic-style-extended-vertical', - label=_('full screen'), - prim_name='fullscreen', - help_string=_('hides the Sugar toolbars')) + palette.add_block('fullscreen', + style='basic-style-extended-vertical', + label=_('full screen'), + prim_name='fullscreen', + help_string=_('hides the Sugar toolbars')) self.tw.lc.def_prim('fullscreen', 0, lambda self: self.tw.set_fullscreen()) PLUGIN_DICTIONARY['bulletlist'] = self._prim_list - make_prim('list', - style='bullet-style', - label=_('list'), - prim_name='bulletlist', - default=['∙ ', '∙ '], - help_string=_('presentation bulleted list')) + palette.add_block('list', + hidden=True, + style='bullet-style', + label=_('list'), + prim_name='bulletlist', + default=['∙ ', '∙ '], + help_string=_('presentation bulleted list')) self.tw.lc.def_prim('bulletlist', 1, PLUGIN_DICTIONARY['bulletlist'], True) # macros - make_prim('picturelist', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: list of bullets')) - - make_prim('picture1x1a', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: select Journal object \ -(no description)')) - - make_prim('picture1x1', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: select Journal object \ -(with description)')) - - make_prim('picture2x2', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: select four Journal \ -objects')) - - make_prim('picture2x1', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: select two Journal \ -objects')) - - make_prim('picture1x2', - palette='portfolio', - style='basic-style-extended', - label=' ', - help_string=_('presentation template: select two Journal \ -objects')) + palette.add_block('picturelist', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: list of \ +bullets')) + + palette.add_block('picture1x1a', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: select \ +Journal object (no description)')) + + palette.add_block('picture1x1', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: select \ +Journal object (with description)')) + + palette.add_block('picture2x2', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: select four \ +Journal objects')) + + palette.add_block('picture2x1', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: select two \ +Journal objects')) + + palette.add_block('picture1x2', + style='basic-style-extended', + label=' ', + help_string=_('presentation template: select two \ +Journal objects')) # Display-dependent constants - make_prim('leftpos', - palette='portfolio', - style='box-style', - label=_('left'), - prim_name='lpos', - help_string=_('xcor of left of screen')) + palette.add_block('leftpos', + style='box-style', + label=_('left'), + prim_name='lpos', + help_string=_('xcor of left of screen')) self.tw.lc.def_prim('lpos', 0, lambda self: CONSTANTS['leftpos']) - make_prim('bottompos', - palette='portfolio', - style='box-style', - label=_('bottom'), - prim_name='bpos', - help_string=_('ycor of bottom of screen')) + palette.add_block('bottompos', + style='box-style', + label=_('bottom'), + prim_name='bpos', + help_string=_('ycor of bottom of screen')) self.tw.lc.def_prim('bpos', 0, lambda self: CONSTANTS['bottompos']) - make_prim('width', - palette='portfolio', - style='box-style', - label=_('width'), - prim_name='hres', - help_string=_('the canvas width')) + palette.add_block('width', + style='box-style', + label=_('width'), + prim_name='hres', + help_string=_('the canvas width')) self.tw.lc.def_prim('hres', 0, lambda self: CONSTANTS['width']) - make_prim('rightpos', - palette='portfolio', - style='box-style', - label=_('right'), - prim_name='rpos', - help_string=_('xcor of right of screen')) + palette.add_block('rightpos', + style='box-style', + label=_('right'), + prim_name='rpos', + help_string=_('xcor of right of screen')) self.tw.lc.def_prim('rpos', 0, lambda self: CONSTANTS['rightpos']) - make_prim('toppos', - palette='portfolio', - style='box-style', - label=_('top'), - prim_name='tpos', - help_string=_('ycor of top of screen')) + palette.add_block('toppos', + style='box-style', + label=_('top'), + prim_name='tpos', + help_string=_('ycor of top of screen')) self.tw.lc.def_prim('tpos', 0, lambda self: CONSTANTS['toppos']) - make_prim('height', - palette='portfolio', - style='box-style', - label=_('height'), - prim_name='vres', - help_string=_('the canvas height')) + palette.add_block('height', + style='box-style', + label=_('height'), + prim_name='vres', + help_string=_('the canvas height')) self.tw.lc.def_prim('vres', 0, lambda self: CONSTANTS['height']) - make_prim('titlex', - style='box-style', - label=_('title x'), - prim_name='titlex') + palette.add_block('titlex', + hidden=True, + style='box-style', + label=_('title x'), + prim_name='titlex') self.tw.lc.def_prim('titlex', 0, lambda self: CONSTANTS['titlex']) - make_prim('titley', - style='box-style', - label=_('title y'), - prim_name='titley') + palette.add_block('titley', + hidden=True, + style='box-style', + label=_('title y'), + prim_name='titley') self.tw.lc.def_prim('titley', 0, lambda self: CONSTANTS['titley']) - make_prim('leftx', - style='box-style', - label=_('left x'), - prim_name='leftx') + palette.add_block('leftx', + hidden=True, + style='box-style', + label=_('left x'), + prim_name='leftx') self.tw.lc.def_prim('leftx', 0, lambda self: CONSTANTS['leftx']) - make_prim('topy', - style='box-style', - label=_('top y'), - prim_name='topy') + palette.add_block('topy', + hidden=True, + style='box-style', + label=_('top y'), + prim_name='topy') self.tw.lc.def_prim('topy', 0, lambda self: CONSTANTS['topy']) - make_prim('rightx', - style='box-style', - label=_('right x'), - prim_name='rightx') + palette.add_block('rightx', + hidden=True, + style='box-style', + label=_('right x'), + prim_name='rightx') self.tw.lc.def_prim('rightx', 0, lambda self: CONSTANTS['rightx']) - make_prim('bottomy', - style='box-style', - label=_('bottom y'), - prim_name='bottomy') + palette.add_block('bottomy', + hidden=True, + style='box-style', + label=_('bottom y'), + prim_name='bottomy') self.tw.lc.def_prim('bottomy', 0, lambda self: CONSTANTS['bottomy']) # deprecated blocks PLUGIN_DICTIONARY['t1x1'] = self._prim_t1x1 - make_prim('template1x1', - style='portfolio-style-1x1', - label=' ', - prim_name='t1x1', - default=[_('Title'), 'None'], - special_name=_('presentation 1x1'), - help_string=_('presentation template: select Journal object \ -(with description)')) + palette.add_block('template1x1', + hidden=True, + style='portfolio-style-1x1', + label=' ', + prim_name='t1x1', + default=[_('Title'), 'None'], + special_name=_('presentation 1x1'), + help_string=_('presentation template: select \ +Journal object (with description)')) self.tw.lc.def_prim('t1x1', 2, lambda self, a, b: PLUGIN_DICTIONARY['t1x1'](a, b)) PLUGIN_DICTIONARY['t1x1a'] = self._prim_t1x1a - make_prim('template1x1a', - style='portfolio-style-1x1', - label=' ', - prim_name='t1x1a', - default=[_('Title'), 'None'], - special_name=_('presentation 1x1'), - help_string=_('presentation template: select Journal object \ -(no description)')) + palette.add_block('template1x1a', + hidden=True, + style='portfolio-style-1x1', + label=' ', + prim_name='t1x1a', + default=[_('Title'), 'None'], + special_name=_('presentation 1x1'), + help_string=_('presentation template: select \ +Journal object (no description)')) self.tw.lc.def_prim('t1x1a', 2, lambda self, a, b: PLUGIN_DICTIONARY['t1x1a'](a, b)) PLUGIN_DICTIONARY['2x1'] = self._prim_t2x1 - make_prim('template2x1', - style='portfolio-style-2x1', - label=' ', - prim_name='t2x1', - default=[_('Title'), 'None', 'None'], - special_name=_('presentation 2x1'), - help_string=_("presentation template: select two Journal \ -objects")) + palette.add_block('template2x1', + hidden=True, + style='portfolio-style-2x1', + label=' ', + prim_name='t2x1', + default=[_('Title'), 'None', 'None'], + special_name=_('presentation 2x1'), + help_string=_("presentation template: select two \ +Journal objects")) self.tw.lc.def_prim('t2x1', 3, lambda self, a, b, c: PLUGIN_DICTIONARY['t2x1'](a, b, c)) PLUGIN_DICTIONARY['1x2'] = self._prim_t1x2 - make_prim('template1x2', - style='portfolio-style-1x2', - label=' ', - prim_name='t1x2', - default=[_('Title'), 'None', 'None'], - special_name=_('presentation 1x2'), - help_string=_("presentation template: select two Journal \ -objects")) + palette.add_block('template1x2', + hidden=True, + style='portfolio-style-1x2', + label=' ', + prim_name='t1x2', + default=[_('Title'), 'None', 'None'], + special_name=_('presentation 1x2'), + help_string=_("presentation template: select two \ +Journal objects")) self.tw.lc.def_prim('t1x2', 3, lambda self, a, b, c: PLUGIN_DICTIONARY['t1x2'](a, b, c)) PLUGIN_DICTIONARY['t2x2'] = self._prim_t2x2 - make_prim('template2x2', - style='portfolio-style-2x2', - label=' ', - prim_name='t2x2', - default=[_('Title'), 'None', 'None', 'None', 'None'], - special_name=_('presentation 2x2'), - help_string=_("presentation template: select four Journal \ -objects")) + palette.add_block('template2x2', + hidden=True, + style='portfolio-style-2x2', + label=' ', + prim_name='t2x2', + default=[_('Title'), 'None', 'None', 'None', 'None'], + special_name=_('presentation 2x2'), + help_string=_("presentation template: select four \ +Journal objects")) self.tw.lc.def_prim('t2x2', 5, lambda self, a, b, c, d, e: PLUGIN_DICTIONARY['t2x2']( a, b, c, d, e)) - make_prim('templatelist', - style='bullet-style', - label=' ', - prim_name='bullet', - default=[_('Title'), '∙ '], - special_name=_('presentation bulleted list'), - help_string=_('presentation template: list of bullets')) + palette.add_block('templatelist', + hidden=True, + style='bullet-style', + label=' ', + prim_name='bullet', + default=[_('Title'), '∙ '], + special_name=_('presentation bulleted list'), + help_string=_('presentation template: list of \ +bullets')) self.tw.lc.def_prim('bullet', 1, self._prim_list, True) # Block primitives -- cgit v0.9.1