From 7954dd9b2820d2bb76ec38cbe08a2bc28611311b Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 22 Jan 2010 00:28:06 +0000 Subject: fixed disconnect, but not connect --- diff --git a/block.py b/block.py index c12a8e4..79eb178 100644 --- a/block.py +++ b/block.py @@ -106,49 +106,49 @@ class Block: svg.set_outie(False) svg.set_tab(True) svg.set_slot(True) + xoff = INNIE*scale-2 + yoff = SLOTY*scale-1 if name in BASIC_STYLE: svg.expand(40,0) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('flow',True,37,5),('flow',False,37,39)) + self.docks = (('flow',True,0,2),('flow',False,0,self.height-yoff)) elif name in BASIC_STYLE_HEAD: svg.expand(40,0) svg.set_slot(False) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('start',True,37,0), ('flow',False,37,39)) + self.docks = (('start',True,0,2),('flow',False,0,self.height-yoff)) elif name in BASIC_STYLE_HEAD_1ARG: svg.expand(40,0) svg.set_slot(False) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('start',True,37,0), ('string',False,42,12), - ('flow',False,37,44)) + self.docks = (('start',True,0,0), ('string',False,self.width,12), + ('flow',False,0,self.height-yoff)) elif name in BASIC_STYLE_TAIL: svg.expand(40,0) svg.set_tab(False) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('flow',True,37,5),('unavailable',False,0,0)) + self.docks = (('flow',True,0,2),('unavailable',False,0,0)) elif name in BASIC_STYLE_1ARG: - ex = 25 - ey = 0 - svg.expand(ex,ey) + svg.expand(25,0) svg.set_innie([True]) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('flow',True,37,5), ('num',False,42+ex*scale,12), - ('flow',False,37,44+ey)) + self.docks = (('flow',True,0,2), ('num',False,self.width-xoff,12), + ('flow',False,0,self.height-yoff)) elif name in BASIC_STYLE_2ARG: - ex = 25 - ey = 0 - svg.expand(ex,ey) + svg.expand(25,0) svg.set_innie([True,True]) self._make_basic_block(sprite_list, svg, x, y) - self.docks = (('flow',True,37,5), ('num',False,42+ex*scale,12), - ('num',False,42+ex*scale,54), ('flow',False,37,81)) + self.docks = (('flow',True,0,2), ('num',False,self.width-xoff,12), + ('num',False,self.width-xoff,54), + ('flow',False,0,self.height-yoff)) elif name in BOX_STYLE: - svg.expand(50,0) + svg.expand(40,0) self._make_basic_box(sprite_list, svg, x, y) - self.docks = (('num',True,0,12),('unavailable',False,105,12)) + self.docks = (('num',True,0,12),('unavailable',False,0,12)) else: svg.expand(40,0) self._make_basic_block(sprite_list, svg, x, y) + self.docks = (('flow',True,0,2),('flow',False,0,self.height-yoff)) print "don't know how to create a block for %s" % (name) if len(labels) > 0: @@ -164,6 +164,8 @@ class Block: def _make_basic_block(self, sprite_list, svg, x, y): self.shape = sprite_factory.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 =\ @@ -172,6 +174,8 @@ class Block: def _make_basic_box(self, sprite_list, svg, x, y): self.shape = sprite_factory.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()) diff --git a/constants.py b/constants.py index e4cb0a0..8c7efe5 100644 --- a/constants.py +++ b/constants.py @@ -14,6 +14,13 @@ from gettext import gettext as _ # +# SVG constants +# +SLOTY = 2 +INNIE = 9 +SPACER = 9 + +# # sprite layers # diff --git a/sprite_factory.py b/sprite_factory.py index 22b9c56..46132a3 100755 --- a/sprite_factory.py +++ b/sprite_factory.py @@ -24,6 +24,7 @@ import pygtk pygtk.require('2.0') import gtk import os +from constants import SLOTY, INNIE, SPACER from gettext import gettext as _ class SVG: @@ -42,15 +43,15 @@ class SVG: self._stroke_width = 1 self._innie = [False] self._outie = False - self._innie_x1 = 4 + self._innie_x1 = (INNIE-self._stroke_width)/2 self._innie_y1 = 3 - self._innie_x2 = 4 - self._innie_y2 = 4 - self._innie_spacer = 9 + self._innie_x2 = (INNIE-self._stroke_width)/2 + self._innie_y2 = (INNIE-self._stroke_width)/2 + self._innie_spacer = SPACER self._slot = True self._tab = True self._bool = False - self._slot_x = 12 + self._slot_x = 10 self._slot_y = 2 self._porch = False self._porch_x = self._innie_x1+self._innie_x2+4*self._stroke_width @@ -241,6 +242,11 @@ class SVG: # # Utility methods # + def get_width(self): + return self._width + + def get_height(self): + return self._height def set_scale(self, scale=1): self._scale = scale diff --git a/talogo.py b/talogo.py index bbb91d9..072da45 100644 --- a/talogo.py +++ b/talogo.py @@ -609,12 +609,17 @@ def lcNew(tw): return lc -def display_coordinates(tw): +def display_coordinates(tw, a=-1, b=-1, d=-1): if hasattr(tw, "activity"): if hasattr(tw.activity, "coordinates_label"): - x = round_int(tw.turtle.xcor/tw.coord_scale) - y = round_int(tw.turtle.ycor/tw.coord_scale) - h = round_int(tw.turtle.heading) + if a==-1 and b==-1 and d == -1: + x = round_int(tw.turtle.xcor/tw.coord_scale) + y = round_int(tw.turtle.ycor/tw.coord_scale) + h = round_int(tw.turtle.heading) + else: + x = a + y = b + h = d tw.activity.coordinates_label.set_text(_("xcor") + " = " + \ str(x) + " " + \ _("ycor") + " = " + \ diff --git a/tawindow.py b/tawindow.py index f40da15..7175190 100644 --- a/tawindow.py +++ b/tawindow.py @@ -341,7 +341,7 @@ class TurtleArtWindow(): """ def _find_block_to_run(self, spr): top = self._find_top_block(spr) - if spr == top and spr.proto.name[0:3] != 'hat': + if spr == top and self.block_list.spr_to_block(spr).name[0:3] != 'hat': return True else: return False @@ -350,9 +350,10 @@ class TurtleArtWindow(): find top block """ def _find_top_block(self, spr): - b = spr - while b.connections[0]!=None: - b=b.connections[0] + blk = self.block_list.spr_to_block(spr) + b = blk.spr + while blk.connections[0]!=None: + b=blk.connections[0] return b """ @@ -790,9 +791,11 @@ class TurtleArtWindow(): def _snap_to_dock(self): spr = self.draggroup[0] my_block = self.block_list.spr_to_block(spr) + print my_block.name d = 200 for my_dockn in range(len(my_block.docks)): for your_block in self.block_list.list: + print your_block.name # don't link to a block to which you're already connected if your_block.spr in self.draggroup: continue @@ -803,6 +806,7 @@ class TurtleArtWindow(): if self._magnitude(this_xy) > d: continue print "found a match? %d" % (your_dockn) + your_block.spr.set_shape(your_block.selected_shape) d = self._magnitude(this_xy) best_xy = this_xy best_you = your_block @@ -947,11 +951,13 @@ class TurtleArtWindow(): disconnect block """ def _disconnect(self, b): - if b.connections[0]==None: + blk = self.block_list.spr_to_block(b) + if blk.connections[0]==None: return - b2=b.connections[0] - b2.connections[b2.connections.index(b)] = None - b.connections[0] = None + b2=blk.connections[0] + blk2 = self.block_list.spr_to_block(b2) + blk2.connections[blk2.connections.index(b)] = None + blk.connections[0] = None """ turtle pressed @@ -985,6 +991,7 @@ class TurtleArtWindow(): dock2 = block2.docks[dock2n] d1type, d1dir, d1x, d1y = dock1[0:4] d2type, d2dir, d2x, d2y = dock2[0:4] + ''' if (d2type!='num') or (dock2n!=0): if block1.connections is not None and dock1n < block1.connections\ and block1.connections[dock1n] is not None: @@ -992,8 +999,11 @@ class TurtleArtWindow(): if block2.connections is not None and dock2n < block2.connections\ and block2.connections[dock2n] is not None: return (100,100) + ''' if block1 == block2: + print "block1 == block2" return (100,100) + ''' if d1type != d2type: # some blocks can take strings or nums if block1.name in ('write', 'plus2', 'equal', 'less', 'greater', @@ -1017,8 +1027,12 @@ class TurtleArtWindow(): pass else: return (100,100) + ''' if d1dir == d2dir: + print "d1dir == d2dir" return (100,100) + display_coordinates(self, (block1.spr.x+d1x)-(block2.spr.x+d2x), + (block1.spr.y+d1y)-(block2.spr.y+d2y), 0) return ((block1.spr.x+d1x)-(block2.spr.x+d2x), (block1.spr.y+d1y)-(block2.spr.y+d2y)) -- cgit v0.9.1