diff options
author | Walter Bender <walter@walter-laptop.(none)> | 2010-02-03 22:36:43 (GMT) |
---|---|---|
committer | Walter Bender <walter@walter-laptop.(none)> | 2010-02-03 22:36:43 (GMT) |
commit | 6913d97067e79a86045d0e306e15367dd5e48ea8 (patch) | |
tree | 587e23a9b076f603bad137e54beb43d32a538e12 | |
parent | ebb2f2da5760329d5c15785f4429a009806d25a2 (diff) |
dynamic scaling of blocks
-rw-r--r-- | TurtleArtActivity.py | 11 | ||||
-rw-r--r-- | tablock.py | 19 | ||||
-rw-r--r-- | tawindow.py | 43 | ||||
-rwxr-xr-x | turtleart.py | 16 |
4 files changed, 68 insertions, 21 deletions
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index f2f0722..4e1ea72 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -56,7 +56,6 @@ import os.path import subprocess import tarfile import sys -import re from taconstants import * from taexporthtml import save_html @@ -538,22 +537,22 @@ class TurtleArtActivity(activity.Activity): # maybe we can use a stack to share events to new-comers? # self._share += "text + "\n" if text[0] == 'p': # button press - e,x,y,mask = re.split(":",text) + e,x,y,mask = text.split(":") # _logger.debug("receiving button press: "+x+" "+y+" "+mask) if mask == 'T': self.tw.button_press(True,int(x),int(y),False) else: self.tw.button_press(False,int(x),int(y),False) elif text[0] == 'r': # block release - e,x,y = re.split(":",text) + e,x,y = text.split(":") # _logger.debug("receiving button release: " + x + " " + y) self.tw.button_release(int(x),int(y),False) elif text[0] == 'm': # mouse move - e,x,y = re.split(":",text) + e,x,y = text.split(":") _logger.debug("receiving move: " + x + " " + y) self.tw.mouse_move(0,0,False,int(x),int(y)) elif text[0] == 'k': # typing - e,mask,keyname = re.split(":",text,3) + e,mask,keyname = text.split(":",3) # _logger.debug("recieving key press: " + mask + " " + keyname) if mask == 'T': self.tw.key_press(True,keyname,False) @@ -569,7 +568,7 @@ class TurtleArtActivity(activity.Activity): elif text[0] == 'I': # receiving current state if self.waiting_for_blocks: _logger.debug("receiving project from sharer") - e,text = re.split(":",text,2) + e,text = text.split(":",2) if len(text) > 0: self.tw.new_project() self.tw.process_data(data_from_string(text)) @@ -53,6 +53,12 @@ class Blocks: if block_type is None or block_type == block.type: print "%d: %s" % (i, block.name) + def set_scale(self, scale): + for b in self.list: + for i in range(len(b._font_size)): + b._font_size[i] *= b.scale*scale/self.font_scale_factor + self.font_scale_factor = scale + # # sprite utilities # @@ -124,11 +130,24 @@ class Block: def rescale(self, scale): for i in range(len(self._font_size)): self._font_size[i] /= self.scale + self._dx /= self.scale + self._ex /= self.scale + self._ey /= self.scale self.scale = scale for i in range(len(self._font_size)): self._font_size[i] *= self.scale + self._dx *= self.scale + self._ex *= self.scale + self._ey *= self.scale + for i in range(len(self.spr.labels)): + if i == 0: + self.spr.set_label_attributes(int(self._font_size[0]+0.5)) + else: + self.spr.set_label_attributes(int(self._font_size[1]+0.5)) + self.svg.set_scale(self.scale) self._make_block(self.svg) self.spr.set_shape(self.shapes[0]) + self.spr.draw() # We may want to add "innies" def add_arg(self): diff --git a/tawindow.py b/tawindow.py index 3a463aa..86d24c0 100644 --- a/tawindow.py +++ b/tawindow.py @@ -103,6 +103,7 @@ class TurtleArtWindow(): else: self.lead = 1.0 self.scale = 1.0 + self.block_scale = BLOCK_SCALE self.cm = self.gc.get_colormap() self.rgb = [255,0,0] self.bgcolor = self.cm.alloc_color('#fff8de') @@ -169,6 +170,16 @@ class TurtleArtWindow(): self.window.connect("key_press_event", self._keypress_cb) """ + Resize all of the blocks + """ + def resize(self, scale): + self.block_scale = scale + for b in self.just_blocks(): + b.rescale(self.block_scale) + for b in self.just_blocks(): + self._adjust_dock_positions(b) + + """ Repaint """ def _expose_cb(self, win, event): @@ -429,16 +440,16 @@ class TurtleArtWindow(): # Some blocks get a skin. if name in BOX_STYLE_MEDIA: self.palettes[n][i].spr.set_image(self.media_shapes[ - name+'small'], 1, int(MEDIA_X*scale/BLOCK_SCALE), - int(MEDIA_Y*scale/BLOCK_SCALE)) + name+'small'], 1, int(MEDIA_X*scale/self.block_scale), + int(MEDIA_Y*scale/self.block_scale)) elif name[:8] == 'template': self.palettes[n][i].spr.set_image(self.media_shapes[ - name[8:]], 1, int(TEMPLATE_X*scale/BLOCK_SCALE), - int(TEMPLATE_Y*scale/BLOCK_SCALE)) + name[8:]], 1, int(TEMPLATE_X*scale/self.block_scale), + int(TEMPLATE_Y*scale/self.block_scale)) elif name == 'nop': self.palettes[n][i].spr.set_image(self.media_shapes[ - 'pythonsmall'], 1, int(PYTHON_X*scale/BLOCK_SCALE), - int(PYTHON_Y*scale/BLOCK_SCALE)) + 'pythonsmall'], 1, int(PYTHON_X*scale/self.block_scale), + int(PYTHON_Y*scale/self.block_scale)) self._layout_palette(n) for blk in self.palettes[n]: blk.spr.set_layer(CATEGORY_LAYER) @@ -892,10 +903,10 @@ class TurtleArtWindow(): if blk.name == 'restore': self._restore_from_trash() elif MACROS.has_key(blk.name): - self._new_macro(blk.name, x, y+PALETTE_HEIGHT) + self._new_macro(blk.name, x+PALETTE_WIDTH, y+PALETTE_HEIGHT) else: blk.spr.set_shape(blk.shapes[1]) - self._new_block(blk.name, x, y+PALETTE_HEIGHT) + self._new_block(blk.name, x+PALETTE_WIDTH, y+PALETTE_HEIGHT) blk.spr.set_shape(blk.shapes[0]) return True @@ -1215,7 +1226,7 @@ class TurtleArtWindow(): if b.type == 'trash': b.spr.set_layer(BLOCK_LAYER) x,y = b.spr.get_xy() - b.spr.move((x,y+200)) + b.spr.move((x+PALETTE_WIDTH,y+PALETTE_HEIGHT)) b.type = 'block' """ @@ -1244,11 +1255,11 @@ class TurtleArtWindow(): """ def _new_block(self, name, x, y): if name in CONTENT_BLOCKS: - newblk = Block(self.block_list, self.sprite_list, name, - x-20, y-20, 'block', DEFAULTS[name]) + newblk = Block(self.block_list, self.sprite_list, name, x-20, y-20, + 'block', DEFAULTS[name], self.block_scale) else: - newblk = Block(self.block_list, self.sprite_list, name, - x-20, y-20, 'block') + newblk = Block(self.block_list, self.sprite_list, name, x-20, y-20, + 'block', [], self.block_scale) # Add special skin to some blocks if name == 'nop': if self.nop == 'pythonloaded': @@ -1285,10 +1296,12 @@ class TurtleArtWindow(): if argname is not None: if argname in CONTENT_BLOCKS: argblk = Block(self.block_list, self.sprite_list, - argname, 0, 0, 'block', [argvalue]) + argname, 0, 0, 'block', [argvalue], + self.block_scale) else: argblk = Block(self.block_list, self.sprite_list, - argname, 0, 0, 'block') + argname, 0, 0, 'block', [], + self.block_scale) argdock = argblk.docks[0] nx, ny = sx+dock[2]-argdock[2], sy+dock[3]-argdock[3] if argname == 'journal': diff --git a/turtleart.py b/turtleart.py index e992028..9d45818 100755 --- a/turtleart.py +++ b/turtleart.py @@ -54,6 +54,7 @@ Caveats: class TurtleMain(): def __init__(self): self.i = 0 + self.scale=2.0 tw = None # make sure Sugar paths are present tapath = os.path.join(os.environ['HOME'],'.sugar','default', \ @@ -84,6 +85,14 @@ class TurtleMain(): menu.append(menu_items) menu_items.connect("activate", self._do_save_cb) menu_items.show() + menu_items = gtk.MenuItem(_("Lerger")) + menu.append(menu_items) + menu_items.connect("activate", self._do_resize_cb, 1.5) + menu_items.show() + menu_items = gtk.MenuItem(_("Reset")) + menu.append(menu_items) + menu_items.connect("activate", self._do_resize_cb, -1) + menu_items.show() activity_menu = gtk.MenuItem("File") activity_menu.show() @@ -149,6 +158,13 @@ class TurtleMain(): def _do_save_cb(self, widget): self.tw.save_file() + def _do_resize_cb(self, widget, factor): + if factor == -1: + self.scale = 2.0 + else: + self.scale *= factor + self.tw.resize(self.scale) + def _do_palette_cb(self, widget): self.tw.show_toolbar_palette(self.i) self.i += 1 |