From e97b50e05bfe1523091f004bee804b16308fff6f Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 22 Jan 2010 21:43:19 +0000 Subject: adding more block types --- diff --git a/block.py b/block.py index 4da2b0b..8ea851f 100644 --- a/block.py +++ b/block.py @@ -20,7 +20,7 @@ #THE SOFTWARE. from constants import * -import sprite_factory +from sprite_factory import * import sprites from gettext import gettext as _ @@ -90,7 +90,7 @@ class Block: else: print "new block: %s %s (%d %d)" % (name, labels[0], x, y) - svg = sprite_factory.SVG() + svg = SVG() if name in TURTLE_PALETTE: svg.set_colors(TURTLE_COLORS) elif name in PEN_PALETTE: @@ -147,9 +147,76 @@ class Block: ('num',False,self.width-xoff,54), ('flow',False,0,self.height-yoff)) elif name in BOX_STYLE: - svg.expand(40,0) + svg.expand(60,0) self._make_basic_box(sprite_list, svg, x, y) self.docks = (('num',True,0,12),('unavailable',False,0,12)) + elif name in NUMBER_STYLE: + svg.expand(25,0) + svg.set_innie([True,True]) + svg.set_outie(True) + svg.set_tab(False) + svg.set_slot(False) + self._make_basic_block(sprite_list, svg, x, y) + self.docks = (('num',True,0,12), ('num',False,self.width-xoff,12), + ('num',False,self.width-xoff,54)) + elif name in NUMBER_STYLE_1ARG: + svg.expand(25,0) + svg.set_innie([True]) + svg.set_outie(True) + svg.set_tab(False) + svg.set_slot(False) + self._make_basic_block(sprite_list, svg, x, y) + self.docks = (('num',True,0,12),('num',False,self.width-xoff,12)) + elif name in NUMBER_STYLE_PORCH: + svg.expand(25,0) + svg.set_innie([True,True]) + svg.set_outie(True) + svg.set_tab(False) + svg.set_slot(False) + svg.set_porch(True) + self._make_basic_block(sprite_list, svg, x, y) + xoff += svg._porch + self.docks = (('num',True,0,12), ('num',False,self.width-xoff,12), + ('num',False,self.width-xoff,54)) + elif name in COMPARE_STYLE: + self._make_boolean_compare(sprite_list, svg, x, y) + self.docks = (('bool',True,0,self.height-12), + ('num',False,self.width-xoff,12), + ('num',False,self.width-xoff,54)) + elif name in BOOLEAN_STYLE: + self._make_boolean_and_or(sprite_list, svg, x, y) + self.docks = (('bool',False,0,self.height-12), + ('bool',False,self.width-xoff,12)) + elif name in NOT_STYLE: + self._make_boolean_not(sprite_list, svg, x, y) + self.docks = (('bool',True,0,self.height-12), + ('bool',False,self.width-xoff,12)) + elif name in FLOW_STYLE: + svg.expand(25,0) + svg.set_slot(True) + self._make_basic_flow(sprite_list, svg, x, y) + self.docks = (('flow',True,0,2), + ('flow',False,self.width/2, self.height-yoff)) + elif name in FLOW_STYLE_1ARG: + svg.expand(25,0) + svg.set_slot(True) + svg.set_tab(True) + svg.set_innie([True]) + self._make_basic_flow(sprite_list, svg, x, y) + self.docks = (('flow',True,0,2), + ('num',False,self.width-xoff,12), + ('flow',False, 0, self.height-yoff) + ('flow',False,self.width/2, self.height-yoff)) + elif name in FLOW_STYLE_BOOLEAN: + svg.expand(25,0) + svg.set_slot(True) + svg.set_tab(True) + svg.set_boolean(True) + self._make_basic_flow(sprite_list, svg, x, y) + self.docks = (('flow',True,0,2), + ('bool',False,self.width-xoff,12), + ('flow',False, 0, self.height-yoff) + ('flow',False,self.width/2, self.height-yoff)) else: svg.expand(40,0) self._make_basic_block(sprite_list, svg, x, y) @@ -157,9 +224,11 @@ class Block: print "don't know how to create a block for %s" % (name) if len(labels) > 0: - self.spr.set_label(_(labels[0])) - for label in labels: - self.spr.set_label(label, labels.index(label)) + if BLOCK_NAMES.has_key(name): + self.spr.set_label(BLOCK_NAMES[name]) + for i, label in enumerate(labels): + if i > 0: + self.spr.set_label(label, labels[i]) self.type = 'block' if DEFAULTS.has_key(name): @@ -168,21 +237,55 @@ class Block: self.defaults = [] def _make_basic_block(self, sprite_list, svg, x, y): - self.shape = sprite_factory.svg_str_to_pixbuf(svg.basic_block()) + self.shape = svg_str_to_pixbuf(svg.basic_block()) self.width = svg.get_width() self.height = svg.get_height() svg.set_stroke_width(SELECTED_STROKE_WIDTH) svg.set_stroke_color(SELECTED_COLOR) - self.selected_shape =\ - sprite_factory.svg_str_to_pixbuf(svg.basic_block()) + self.selected_shape = svg_str_to_pixbuf(svg.basic_block()) self.spr = sprites.Sprite(sprite_list, x, y, self.shape) def _make_basic_box(self, sprite_list, svg, x, y): - self.shape = sprite_factory.svg_str_to_pixbuf(svg.basic_box()) + self.shape = svg_str_to_pixbuf(svg.basic_box()) self.width = svg.get_width() self.height = svg.get_height() svg.set_stroke_width(SELECTED_STROKE_WIDTH) svg.set_stroke_color(SELECTED_COLOR) - self.selected_shape = sprite_factory.svg_str_to_pixbuf(svg.basic_box()) + self.selected_shape = svg_str_to_pixbuf(svg.basic_box()) self.spr = sprites.Sprite(sprite_list, x, y, self.shape) + def _make_basic_flow(self, sprite_list, svg, x, y): + self.shape = svg_str_to_pixbuf(svg.basic_flow()) + self.width = svg.get_width() + self.height = svg.get_height() + svg.set_stroke_width(SELECTED_STROKE_WIDTH) + svg.set_stroke_color(SELECTED_COLOR) + self.selected_shape = svg_str_to_pixbuf(svg.basic_flow()) + self.spr = sprites.Sprite(sprite_list, x, y, self.shape) + + def _make_boolean_compare(self, sprite_list, svg, x, y): + self.shape = svg_str_to_pixbuf(svg.boolean_compare()) + self.width = svg.get_width() + self.height = svg.get_height() + svg.set_stroke_width(SELECTED_STROKE_WIDTH) + svg.set_stroke_color(SELECTED_COLOR) + self.selected_shape = svg_str_to_pixbuf(svg.boolean_compare()) + self.spr = sprites.Sprite(sprite_list, x, y, self.shape) + + def _make_boolean_and_or(self, sprite_list, svg, x, y): + self.shape = svg_str_to_pixbuf(svg.boolean_and_or()) + self.width = svg.get_width() + self.height = svg.get_height() + svg.set_stroke_width(SELECTED_STROKE_WIDTH) + svg.set_stroke_color(SELECTED_COLOR) + self.selected_shape = svg_str_to_pixbuf(svg.boolean_and_or()) + self.spr = sprites.Sprite(sprite_list, x, y, self.shape) + + def _make_boolean_not(self, sprite_list, svg, x, y): + self.shape = svg_str_to_pixbuf(svg.boolean_not()) + self.width = svg.get_width() + self.height = svg.get_height() + svg.set_stroke_width(SELECTED_STROKE_WIDTH) + svg.set_stroke_color(SELECTED_COLOR) + self.selected_shape = svg_str_to_pixbuf(svg.boolean_not()) + self.spr = sprites.Sprite(sprite_list, x, y, self.shape) diff --git a/constants.py b/constants.py index 0837ab6..e8b3897 100644 --- a/constants.py +++ b/constants.py @@ -38,26 +38,44 @@ TOP_LAYER = 1000 # block definitions # -BASIC_STYLE_HEAD = ['start', 'action 1', 'action 2'] -BASIC_STYLE_HEAD_1ARG = [] +BASIC_STYLE_HEAD = ['start', 'def action 1', 'def action 2'] +BASIC_STYLE_HEAD_1ARG = ['def action'] BASIC_STYLE_TAIL = ['stop action'] -BASIC_STYLE = ['clean', 'pen up', 'pen down', 'action 1', 'action 2', 'nop' ] -BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show',\ - 'set scale', 'set pen size', 'set color', 'set shade'\ - 'set text size', 'set text color', 'print', 'wait', 'store in box 1',\ - 'store in box 2'] -BASIC_STYLE_2ARG = ['arc', 'set xy', 'fill screen'] -BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pen size', 'color', 'shade'\ - 'text color', 'text size', 'box 1', 'box 2', 'string'] - -TURTLE_PALETTE = ['clean', 'forward', 'back', 'left', 'right', 'seth', 'show',\ +BASIC_STYLE = ['clean', 'pen up', 'pen down', 'action 1', 'action 2', 'vspace', + 'hide blocks'] +BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', + 'set scale', 'set pen size', 'set color', 'set shade', 'print', + 'set text size', 'set text color', 'print', 'wait', 'store in box 1', + 'store in box 2', 'wait', 'action'] +BASIC_STYLE_2ARG = ['arc', 'set xy', 'fill screen', 'store in'] +BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pen size', 'color', 'shade', + 'text color', 'text size', 'box 1', 'box 2', 'string', 'left pos', + 'top pos', 'right pos', 'bottom pos', 'width', 'height'] +NUMBER_STYLE = ['plus', 'multiply', 'random'] +NUMBER_STYLE_PORCH = ['minus', 'divide', 'mod'] +NUMBER_STYLE_1ARG = ['square root'] +COMPARE_STYLE = ['greater than', 'less than', 'equal to'] +BOOLEAN_STYLE = ['and', 'or'] +NOT_STYLE = ['not'] +FLOW_STYLE = ['forever', 'hspace'] +FLOW_STYLE_1ARG = ['repeat'] +FLOW_STYLE_BOOLEAN = ['if else'] +TURTLE_PALETTE = ['clean', 'forward', 'back', 'left', 'right', 'seth', 'show', 'set_scale', 'xcor', 'ycor', 'heading'] -PEN_PALETTE = ['pen up','pen down'] -NUMBER_PALETTE = ['number'] -BLOCKS_PALETTE = ['start', 'string', 'store in box 1'] -FLOW_PALETTE = [] -MISC_PALETTE = [] -PORTFOLIO_PALETTE = [] +PEN_PALETTE = ['pen up','pen down', 'set pen size', 'set text size', + 'set color', 'set shade', 'fill screen', 'pen size', 'text size', 'color', + 'shade'] # shade? +NUMBER_PALETTE = ['number', 'plus', 'minus', 'multiply', + 'divide', 'mod', 'square root', 'random', 'greater than', 'less than', + 'equal to', 'and', 'or', 'not', 'print'] +FLOW_PALETTE = ['wait', 'forever', 'repeat', 'if then', 'stop action', 'hspace' + 'vspace'] # stop stack +BLOCKS_PALETTE = ['start', 'def action 1', 'action 1', 'def action 2', + 'action 2', 'def action', 'action', 'store in box 1', 'box 1', + 'store in box 2', 'box 2', 'store in', 'box', 'string'] # hat, stack... +MISC_PALETTE = ['left pos', 'top pos', 'right pos', 'bottom pos', 'width', + 'height'] # hres, vres +PORTFOLIO_PALETTE = ['hide blocks'] TURTLE_COLORS = ["#00FF00","#00A000"] PEN_COLORS = ["#00FFFF","#00A0A0"] @@ -71,35 +89,64 @@ SELECTED_COLOR = "#0000FF" SELECTED_STROKE_WIDTH = 2.0 # -# default values +# block name dictionary +# + +BLOCK_NAMES = {'clean':_('clean'), 'forward':_('forward'), 'back':_('back'), + 'left':_('left'), 'right':_('right'), 'set heading':_('set heading'), + 'show':_('show'), 'set_scale':_('set_scale'), 'xcor':_('xcor'), + 'ycor':_('ycor'), 'heading':_('heading'), 'pen up':_('pen up'), + 'pen down':_('pen down'), 'set pen size':_('set pen size'), + 'set text size':_('set text size'), 'set color':_('set color'), + 'set shade':_('set shade'), 'fill screen':_('fill screen'), + 'pen size':_('pen size'), 'text size':_('text size'), 'color':_('color'), + 'plus':'+', 'minus':'–', 'multiply':'×', 'divide':'/', 'mod':_('mod'), + 'random':_('random'), 'square root':'√', 'less than':'<', + 'greater than':'>', 'equal to':'=', 'and':_('and'), 'or':_('or'), + 'not':_('not'), 'print':_('print'), 'wait':_('wait'), + 'forever':_('forever'), 'repeat':_('repeat'), 'if then':_('if then'), + 'stop action':_('stop action'), 'hspace':_(''), 'vspace':_(''), + 'start':_('start'), 'def action 1':_('action 1'), 'action 1':_('action 1'), + 'def action 2':_('action 2'), 'action 2':_('action 2'), + 'def action':_('action'), 'action':_('action'), + 'store in box 1':_('store in box 1'), 'box 1':_('box 1'), + 'store in box 2':_('store in box 2'), 'box 2':_('box 2'), + 'store in':_('store in'), 'box':_('box'), 'string':_('string'), + 'left pos':_('left'), 'top pos':_('top'), 'right pos':_('right'), + 'bottom pos':_('bottom'), 'width':_('width'), 'height':_('height'), + 'hide blocks':_('hide blocks')} + +# +# block default values # DEFAULTS = {'forward':[100], 'back':[100], 'left':[90], 'right':[90], - 'arc':[90,100], 'seth':[0], 'set scale':[33], 'show':[_('text')], - 'set pen size':[5], 'set text size':[32], 'set color':[0], - 'set shade':[50], 'fill screen':[60,80], 'number':[100], - 'random':[0,100], 'wait':[1], 'repeat':[4], 'set xy':[0,0], - 'store in':[_('box'),100]} + 'arc':[90,100], 'seth':[0], 'set scale':[33], 'show':[_('text')], + 'set pen size':[5], 'set text size':[32], 'set color':[0], + 'set shade':[50], 'fill screen':[60,80], 'number':[100], + 'random':[0,100], 'wait':[1], 'repeat':[4], 'set xy':[0,0], + 'store in':[_('box'),100]} + # # 'dead key' Unicode dictionaries # DEAD_KEYS = ['grave','acute','circumflex','tilde','diaeresis','abovering'] -DEAD_DICTS = [{'A':192,'E':200,'I':204,'O':210,'U':217,'a':224,'e':232,'i':236,\ +DEAD_DICTS = [{'A':192,'E':200,'I':204,'O':210,'U':217,'a':224,'e':232,'i':236, 'o':242,'u':249}, - {'A':193,'E':201,'I':205,'O':211,'U':218,'a':225,'e':233,'i':237,\ + {'A':193,'E':201,'I':205,'O':211,'U':218,'a':225,'e':233,'i':237, 'o':243,'u':250}, - {'A':194,'E':202,'I':206,'O':212,'U':219,'a':226,'e':234,\ + {'A':194,'E':202,'I':206,'O':212,'U':219,'a':226,'e':234, 'i':238,'o':244,'u':251}, {'A':195,'O':211,'N':209,'U':360,'a':227,'o':245,'n':241,'u':361}, - {'A':196,'E':203,'I':207,'O':211,'U':218,'a':228,'e':235,\ + {'A':196,'E':203,'I':207,'O':211,'U':218,'a':228,'e':235, 'i':239,'o':245,'u':252}, {'A':197,'a':229}] -NOISE_KEYS = ['Shift_L', 'Shift_R', 'Control_L', 'Caps_Lock', 'Pause',\ - 'Alt_L', 'Alt_R', 'KP_Enter', 'ISO_Level3_Shift', 'KP_Divide',\ - 'Escape', 'Return', 'KP_Page_Up', 'Up', 'Down', 'Menu',\ - 'Left', 'Right', 'KP_Home', 'KP_End', 'KP_Up', 'Super_L',\ - 'KP_Down', 'KP_Left', 'KP_Right', 'KP_Page_Down', 'Scroll_Lock',\ +NOISE_KEYS = ['Shift_L', 'Shift_R', 'Control_L', 'Caps_Lock', 'Pause', + 'Alt_L', 'Alt_R', 'KP_Enter', 'ISO_Level3_Shift', 'KP_Divide', + 'Escape', 'Return', 'KP_Page_Up', 'Up', 'Down', 'Menu', + 'Left', 'Right', 'KP_Home', 'KP_End', 'KP_Up', 'Super_L', + 'KP_Down', 'KP_Left', 'KP_Right', 'KP_Page_Down', 'Scroll_Lock', 'Page_Down', 'Page_Up'] WHITE_SPACE = ['space','Tab'] diff --git a/tasetup.py b/tasetup.py index 77fc458..2b15c94 100644 --- a/tasetup.py +++ b/tasetup.py @@ -60,11 +60,7 @@ selectors = ( ('xcor','xcor','num'), ('ycor','ycor','num'), ('heading','heading','num'), - ('scale','scale','num'), - # not selectable, but here for backward compatability - ('container','container','container','None'), - ('image','insertimage','image','None'), - ('write','write','1sarg',_('text'),32))), + ('scale','scale','num'))), ('pen', 55, (('pen up','penup','noarg'), ('pen down','pendown','noarg'), @@ -83,62 +79,47 @@ selectors = ( ('green','green','num'), ('cyan','cyan','num'), ('blue','blue','num'), - ('purple','purple','num'), - # not selectable, but here for backward compatability - ('set_text_color','settextcolor','1arg',0), - ('text_color','textcolor','num'))), + ('purple','purple','num'))), ('numbers', 55, (('number','','num',100,float,numcheck), - ('plus2','plus','newari'), - ('minus2','minus','newari2'), - ('product2','product','newari'), - ('division2','division','newari2'), - ('remainder2','mod','newari2'), - ('sqrt','sqrt','sqrt',100), - ('identity','id','id'), - ('identity2','id','id2'), + ('plus','plus','newari'), + ('minus','minus','newari2'), + ('multiply','product','newari'), + ('divide','division','newari2'), + ('mod','mod','newari2'), + ('square root','sqrt','sqrt',100), ('random','random','random',0,100), - ('greater','greater?','comp'), - ('less','less?','comp'), - ('equal','equal?','comp'), + ('greater than','greater?','comp'), + ('less than','less?','comp'), + ('equal to','equal?','comp'), ('and','and','and'), ('or','or','and'), ('not','not','not'), - ('print','print','onearg'), - # not selectable, but here for backward compatability - ('minus','-','ari'), - ('product','*','ari'), - ('division','/','ari'), - ('remainder','%','ari2'), - ('plus','+','ari'))), + ('print','print','onearg'))), ('flow', 55, (('wait','wait','onearg',1), ('forever','forever','forever'), ('repeat','repeat','repeat',4), ('if','if','if'), - ('stop stack','stopstack','stop'), + ('stop action','stopstack','stop'), ('if else','ifelse','ifelse'), ('hspace','nop','hspace'), - ('vspace','nop','vspace'), - # not selectable, but here for backward compatability - ('lock','nop','lock'))), + ('vspace','nop','vspace'))), ('myblocks', 55, (('start','start','start'), - ('hat1','nop1','start'), - ('stack1','stack1','noarg'), - ('hat2','nop2','start'), - ('stack2','stack2','noarg'), - ('hat','nop3','starts',_('action')), - ('stack','stack','sarg',_('action')), + ('def action 1','nop1','start'), + ('action 1','stack1','noarg'), + ('def action 2','nop2','start'), + ('action 2','stack2','noarg'), + ('def action','nop3','starts',_('action')), + ('action','stack','sarg',_('action')), ('store in box 1','storeinbox1','1arg'), ('box 1','box1','num'), ('store in box 2','storeinbox2','1arg'), ('box 2','box2','num'), ('store in','storeinbox','1varg',_('box'),100), ('box','box','nfuncs',_('box')), - ('string','','string',_('name'),str,strcheck), - # not selectable, but here for backward compatability - ('store in box','storeinbox','1sarg',_('box'),100))), + ('string','','string',_('name'),str,strcheck))), ('sensors', 55, (('kbinput','kbinput','noarg2'), ('keyboard','keyboard','num'), @@ -152,8 +133,8 @@ selectors = ( ('top pos','toppos','num'), ('right pos','rightpos','num'), ('bottom pos','bottompos','num'), - ('hres','hres','num'), - ('vres','vres','num'))), + ('width','hres','num'), + ('height','vres','num'))), ('templates',55, (('journal','','media','','',''), ('audio off','','audio','','',''), diff --git a/tawindow.py b/tawindow.py index 08a4351..b3dc5d5 100644 --- a/tawindow.py +++ b/tawindow.py @@ -873,10 +873,10 @@ class TurtleArtWindow(): gobject.idle_add(doevalstep, self.lc) """ - # phased out filter out blocks """ def _blocks(self): + print ">>>>>>>>>>>>>>>>>>> DEPRCIATED: _blocks()" return [spr for spr in self.sprite_list.list if spr.type == 'block'] """ -- cgit v0.9.1