From d6606be70ed63aecde87e111421c61a696ba6d66 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 23 Oct 2010 20:51:12 +0000 Subject: add value to labels of constant blocks --- diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 0ad00fa..9c7547f 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -36,7 +36,7 @@ from taconstants import EXPANDABLE, EXPANDABLE_BLOCKS, EXPANDABLE_ARGS, \ COLLAPSIBLE_TOP_NO_ARM_NO_LABEL, COLLAPSIBLE_BOTTOM, PORTFOLIO_STYLE_2x2, \ PORTFOLIO_STYLE_1x1, PORTFOLIO_STYLE_2x1, PORTFOLIO_STYLE_1x2, \ STANDARD_STROKE_WIDTH, SELECTED_STROKE_WIDTH, SELECTED_COLOR, BOX_COLORS, \ - BASIC_STYLE_EXTENDED_VERTICAL + BASIC_STYLE_EXTENDED_VERTICAL, CONSTANTS from tasprite_factory import SVG, svg_str_to_pixbuf import sprites @@ -160,7 +160,8 @@ class Block: if self.name not in EXPANDABLE and \ self.name not in EXPANDABLE_BLOCKS and \ self.name not in EXPANDABLE_ARGS and \ - self.name not in ['string', 'sandwichtop', 'sandwichtop_no_label']: + self.name not in BOX_STYLE and \ + self.name not in ['sandwichtop', 'sandwichtop_no_label']: for b in self.block_list.list: if b.scale == self.scale and b.name == self.name: copy_block = b @@ -352,6 +353,10 @@ class Block: str(v).replace('.', self.block_list.decimal_point)) else: self._set_labels(i, str(v)) + elif self.type == 'block' and self.name in CONSTANTS: + self._set_labels(0, BLOCK_NAMES[self.name][0] + ' = ' + \ + str(CONSTANTS[self.name])) + elif self.name in BLOCK_NAMES: for i, n in enumerate(BLOCK_NAMES[self.name]): self._set_labels(i, n) diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 2e031a9..ca5aa59 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -278,6 +278,15 @@ BLOCKS_WITH_SKIN = ['journal', 'audio', 'description', 'nop', 'userdefined', PYTHON_SKIN = ['nop', 'userdefined', 'userdefined2args', 'userdefined3args'] # +# These blocks hold constants +# +CONSTANTS = {'leftpos':None, 'toppos':None, 'rightpos':None, 'bottompos':None, + 'width':None, 'height':None, 'red':0, 'orange':10, 'yellow':20, + 'green':40, 'cyan':50, 'blue':70, 'purple':90, 'titlex':None, + 'titley':None, 'leftx':None, 'topy':None, 'rightx':None, + 'bottomy':None} + +# # Block-name dictionary used for labels # BLOCK_NAMES = { @@ -288,7 +297,7 @@ BLOCK_NAMES = { 'back': [_('back')], 'black': [_('black')], 'blocks': [_('blocks')], - 'blue': [_('blue') + ' = 70'], + 'blue': [_('blue')], 'bottompos': [_('bottom')], 'bottomy': [_('picture bottom')], 'box': [_('box')], @@ -300,7 +309,7 @@ BLOCK_NAMES = { 'color': [_('color')], 'colors': [_('colors')], 'comment': [_('comment')], - 'cyan': [_('cyan') + ' = 50'], + 'cyan': [_('cyan')], 'decription': [' '], 'division2': ['/'], 'empty': [_('empty trash')], @@ -313,7 +322,7 @@ BLOCK_NAMES = { 'fullscreen': [_('full screen')], 'gray': [_('gray')], 'greater2': [">"], - 'green': [_('green') + ' = 30'], + 'green': [_('green')], 'hat': [_('action')], 'hat1': [_('action 1')], 'hat2': [_('action 2')], @@ -342,7 +351,7 @@ BLOCK_NAMES = { 'not': [_('not')], 'number': ['100'], 'numbers': [_('numbers')], - 'orange': [_('orange') + ' = 10'], + 'orange': [_('orange')], 'or2': [_('or')], 'pen': [_('pen')], 'pendown': [_('pen down')], @@ -362,11 +371,11 @@ BLOCK_NAMES = { 'printheap': [_('show heap')], 'print': [_('print')], 'product2': ['×'], - 'purple': [_('purple') + ' = 90'], + 'purple': [_('purple')], 'push': [_('push')], 'random': [_('random'), _('min'), _('max')], 'readpixel': [_('read pixel')], - 'red': [_('red') + ' = 0'], + 'red': [_('red')], 'remainder2': [_('mod')], 'repeat': [' ', _('repeat')], 'reskin': [_('turtle shell')], @@ -441,7 +450,7 @@ BLOCK_NAMES = { 'write': [_('write')], 'xcor': [_('xcor')], 'ycor': [_('ycor')], - 'yellow': [_('yellow') + ' = 20']} + 'yellow': [_('yellow')]} # # Logo primitives diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 2d39667..ca0af4a 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -54,7 +54,7 @@ from taconstants import HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, \ TURTLE_LAYER, EXPANDABLE_BLOCKS, COMPARE_STYLE, \ BOOLEAN_STYLE, EXPANDABLE_ARGS, NUMBER_STYLE, \ NUMBER_STYLE_PORCH, NUMBER_STYLE_BLOCK, \ - NUMBER_STYLE_VAR_ARG + NUMBER_STYLE_VAR_ARG, CONSTANTS from talogo import LogoCode, stop_logo from tacanvas import TurtleGraphics from tablock import Blocks, Block @@ -207,16 +207,29 @@ class TurtleArtWindow(): self.selected_turtle = None self.canvas = TurtleGraphics(self, self.width, self.height) - self.titlex = -(self.canvas.width * TITLEXY[0]) / \ - (self.coord_scale * 2) - self.leftx = -(self.canvas.width * TITLEXY[0]) / \ - (self.coord_scale * 2) + self.titlex = int(-(self.canvas.width * TITLEXY[0]) / \ + (self.coord_scale * 2)) + CONSTANTS['titlex'] = self.titlex + self.leftx = int(-(self.canvas.width * TITLEXY[0]) / \ + (self.coord_scale * 2)) + CONSTANTS['leftx'] = self.leftx self.rightx = 0 - self.titley = (self.canvas.height * TITLEXY[1]) / \ - (self.coord_scale * 2) - self.topy = (self.canvas.height * (TITLEXY[1] - 0.125)) / \ - (self.coord_scale * 2) + CONSTANTS['rightx'] = self.rightx + self.titley = int((self.canvas.height * TITLEXY[1]) / \ + (self.coord_scale * 2)) + CONSTANTS['titley'] = self.titley + self.topy = int((self.canvas.height * (TITLEXY[1] - 0.125)) / \ + (self.coord_scale * 2)) + CONSTANTS['topy'] = self.topy self.bottomy = 0 + CONSTANTS['bottomy'] = self.bottomy + CONSTANTS['leftpos'] = int(-self.canvas.width / (self.coord_scale * 2)) + CONSTANTS['toppos'] = int(self.canvas.height / (self.coord_scale * 2)) + CONSTANTS['rightpos'] = int(self.canvas.width / (self.coord_scale * 2)) + CONSTANTS['bottompos'] = int(-self.canvas.height / \ + (self.coord_scale * 2)) + CONSTANTS['width'] = int(self.canvas.width / self.coord_scale) + CONSTANTS['height'] = int(self.canvas.height / self.coord_scale) self.lc = LogoCode(self) self.saved_pictures = [] -- cgit v0.9.1