From b34f16ddb5012df4929d07443c7423cfb26f3b88 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 26 Jan 2010 21:45:22 +0000 Subject: added restore from trash --- diff --git a/constants.py b/constants.py index 951cafe..c1a0b9c 100644 --- a/constants.py +++ b/constants.py @@ -61,7 +61,7 @@ PALETTES = [['forward', 'back', 'clean', 'left', 'right', 'show', 'myfunc', 'nop', 'leftpos', 'toppos', 'width', 'rightpos', 'bottompos', 'height', 'print'], ['hideblocks'], - []] + ['restore']] # # block style attributes @@ -69,7 +69,7 @@ PALETTES = [['forward', 'back', 'clean', 'left', 'right', 'show', COLORS = [["#00FF00","#00A000"], ["#00FFFF","#00A0A0"], ["#FF00FF","#A000A0"], ["#FFC000","#A08000"], ["#FFFF00","#A0A000"], ["#FF0000","#A0000"], - ["#0000FF","#0000FF"], ["#000000","#000000"]] + ["#0000FF","#0000FF"], ["#FFFF00","#A0A000"]] PALETTE_HEIGHT = 175 @@ -85,7 +85,7 @@ BASIC_STYLE_HEAD = ['start', 'hat1', 'hat2'] BASIC_STYLE_HEAD_1ARG = ['hat'] BASIC_STYLE_TAIL = ['stopstack'] BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace', - 'hideblocks', 'clearheap', 'printheap', 'kbinput'] + 'hideblocks', 'clearheap', 'printheap', 'kbinput', 'restore'] BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'setheading', 'show', 'setscale', 'setpensize', 'setcolor', 'setshade', 'print', 'settextsize', 'settextcolor', 'print', 'wait', 'storeinbox1', @@ -148,7 +148,7 @@ BLOCK_NAMES = {'clean':[_('clean')], 'forward':[_('forward')], 'push':[_('push')], 'pop':[_('pop')], 'kbinput':[_('query keyboard')], 'myfunc':[_('python'), _('code'), _('value')], 'nop':[' '], 'printheap':[_('show heap')], - 'clearheap':[_('empty heap')]} + 'clearheap':[_('empty heap')], 'restore':[_('restore')]} # # Legacy names @@ -202,11 +202,10 @@ DEFAULTS = {'forward':[100], 'back':[100], 'left':[90], 'right':[90], 'hat':[_('action')], 'stack':[_('action')], 'nop':[100], 'storeinbox1':[100], 'storeinbox2':[100], 'myfunc':[_('x'),100]} - - # # Status blocks # + MEDIA_SHAPES = ['audioon', 'texton', 'journalon', 'descon', 'pythonoff', 'pythonon'] diff --git a/sprites.py b/sprites.py index cdf26ad..b2156db 100644 --- a/sprites.py +++ b/sprites.py @@ -118,6 +118,12 @@ class Sprite: self._x,self._y = int(pos[0]),int(pos[1]) self.inval() + def move_relative(self, pos): + self.inval() + self._x += int(pos[0]) + self._y += int(pos[1]) + self.inval() + def get_xy(self): return (self._x, self._y) diff --git a/tawindow.py b/tawindow.py index 4b61c32..42f07b3 100644 --- a/tawindow.py +++ b/tawindow.py @@ -323,12 +323,13 @@ class TurtleArtWindow(): x, y = 5, 0 for i, name in enumerate(PALETTE_NAMES): a = self._load_sprite_from_file("%s/%soff.svg" % (self.path, - PALETTE_NAMES[i])) + name)) b = self._load_sprite_from_file("%s/%son.svg" % (self.path, - PALETTE_NAMES[i])) + name)) self.selector_shapes.append([a,b]) self.selectors.append(sprites.Sprite(self.sprite_list, x, y, a)) self.selectors[i].type = 'selector' + self.selectors[i].name = name self.selectors[i].set_layer(TAB_LAYER) w, h = self.selectors[i].get_dimensions() x += int(w+5) @@ -501,24 +502,6 @@ class TurtleArtWindow(): self.dy += dy """ - Get proto from category - TODO: move to toolbar - """ - def _get_proto_from_category(self, x, y): - return - - (sx,sy) = self.category_spr.get_xy() - pixel = self.current_category.get_pixel(self.current_category.mask, - x-sx, y-sy) - index = ((pixel%256)>>3)-1 - if index==0: - return 'hide' - index-=1 - if index>len(self.current_category.blockprotos): - return None - return self.current_category.blockprotos[index] - - """ Let's help our users by displaying a little help. """ def _show_popup(self, x, y): @@ -535,23 +518,7 @@ class TurtleArtWindow(): self.timeout_tag[0] = 0 except: self.timeout_tag[0] = 0 - elif spr and hasattr(spr,'type') and spr.type == 'category': - # TODO: reassign to new palettes - return - proto = self._get_proto_from_category(x, y) - if proto and proto!='hide': - if self.timeout_tag[0] == 0: - self.timeout_tag[0] = self._do_show_popup(proto.name) - self.selected_spr = spr - return - else: - if self.timeout_tag[0] > 0: - try: - gobject.source_remove(self.timeout_tag[0]) - self.timeout_tag[0] = 0 - except: - self.timeout_tag[0] = 0 - elif spr and hasattr(spr,'type') and spr.type == 'selbutton': + elif spr and hasattr(spr,'type') and spr.type == 'selector': if self.timeout_tag[0] == 0: self.timeout_tag[0] = self._do_show_popup(spr.name) self.selected_spr = spr @@ -572,7 +539,6 @@ class TurtleArtWindow(): """ Fetch the help text and display it. - TODO: if block selection moves to the toolbar, help will have to move """ def _do_show_popup(self, block_name): if blocks_dict.has_key(block_name): @@ -738,17 +704,9 @@ class TurtleArtWindow(): elif tur is not None: self._jog_turtle(mov_dict[keyname][0], mov_dict[keyname][1]) """ - elif self.selected_spr.type == 'selbutton': + elif self.selected_spr.type == 'selector': if keyname == 'Return' or keyname == 'KP_Page_Up': self._select_category(self.selected_spr) - elif self.selected_spr.type == 'category': - if keyname == 'Return' or keyname == 'KP_Page_Up': - (x,y) = self.window.get_pointer() - self._block_selector_pressed(x, y) - for b in self.drag_group: - (bx, by) = b.spr.get_xy() - b.spr.move((bx+200, by)) - self.drag_group = None """ return True @@ -783,9 +741,12 @@ class TurtleArtWindow(): self.selected_blk = blk self._block_pressed(mask, x, y, blk) elif blk.type == 'proto': - blk.spr.set_shape(blk.shapes[1]) - self._new_block_from_category(blk.name, x, y+PALETTE_HEIGHT) - blk.spr.set_shape(blk.shapes[0]) + if blk.name == 'restore': + self._restore_from_trash() + else: + blk.spr.set_shape(blk.shapes[1]) + self._new_block_from_category(blk.name, x, y+PALETTE_HEIGHT) + blk.spr.set_shape(blk.shapes[0]) return True # Next, look for a turtle @@ -881,6 +842,7 @@ class TurtleArtWindow(): # Remove blocks by dragging them onto the trash palette if self.block_operation=='move' and self._in_the_trash(x, y): for b in self.drag_group: + b.type = 'trash' b.spr.hide() self.drag_group = None return @@ -993,6 +955,17 @@ class TurtleArtWindow(): gobject.idle_add(doevalstep, self.lc) """ + Restore all the blocks in the trash can + """ + def _restore_from_trash(self): + for b in self.block_list.list: + if b.type == 'trash': + b.spr.set_layer(BLOCK_LAYER) + x,y = b.spr.get_xy() + b.spr.move((x,y+200)) + b.type = 'block' + + """ Is x,y over the trash can? """ def _in_the_trash(self, x, y): @@ -1011,19 +984,6 @@ class TurtleArtWindow(): return just_blocks_list """ - Block selector pressed - TODO: move to toolbar - """ - def _block_selector_pressed(self, x, y): - proto = self._get_proto_from_category(x, y) - if proto is None: - return - if proto is not 'hide': - self._new_block_from_category(proto.name, x, y) - else: - self.hideshow_palette(False) - - """ Make a new block. """ def _new_block_from_category(self, name, x, y): -- cgit v0.9.1