From b8dd0d368449e259fd4b7bcb781d45fe15c158fb Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 22 Jan 2010 14:50:15 +0000 Subject: more transistioning from spr to blk, but lots broken at the moment --- diff --git a/constants.py b/constants.py index 8c7efe5..0837ab6 100644 --- a/constants.py +++ b/constants.py @@ -27,7 +27,7 @@ SPACER = 9 HIDE_LAYER = 100 CANVAS_LAYER = 500 OVERLAY_LAYER = 525 -TURTLE_LAYER = 2550 +TURTLE_LAYER = 550 BLOCK_LAYER = 600 CATEGORY_LAYER = 700 TAB_LAYER = 710 diff --git a/sprites.py b/sprites.py index 23626c5..690aaa6 100644 --- a/sprites.py +++ b/sprites.py @@ -82,53 +82,61 @@ class Sprites: # class Sprite: def __init__(self, sprites, x, y, image): - self.sprites = sprites - self.x = x - self.y = y + self._sprites = sprites + self._x = int(x) + self._y = int(y) + self._scale = [12] + self._rescale = [True] + self._horiz_align = ["center"] + self._vert_align = ["middle"] + self._fd = None + self._bold = False + self._italic = False + self._color = None + self._width = 0 + self._height = 0 self.layer = 100 self.labels = [] - self.scale = [12] - self.rescale = [True] - self.horiz_align = ["center"] - self.vert_align = ["middle"] - self.fd = None - self.bold = False - self.italic = False - self.color = None self.set_image(image) - self.sprites.append_to_list(self) + self._sprites.append_to_list(self) def set_image(self, image): if image is None: - self.width, self.height = 0,0 + self._width, self._height = 0,0 self.image = None return self.image = image if isinstance(self.image, gtk.gdk.Pixbuf): - self.width = self.image.get_width() - self.height = self.image.get_height() + self._width = self.image.get_width() + self._height = self.image.get_height() else: - self.width, self.height = self.image.get_size() + self._width, self._height = self.image.get_size() def move(self, pos): self.inval() - self.x,self.y = pos + self._x,self._y = int(pos[0]),int(pos[1]) self.inval() + def get_xy(self): + return (self._x, self._y) + + def get_layer(self): + return self.layer + def set_shape(self, image): self.inval() self.set_image(image) self.inval() def set_layer(self, layer): - self.sprites.remove_from_list(self) + self._sprites.remove_from_list(self) self.layer = layer - for i in range(self.sprites.length_of_list()): - if layer < self.sprites.get_sprite(i).layer: - self.sprites.insert_in_list(self, i) + for i in range(self._sprites.length_of_list()): + if layer < self._sprites.get_sprite(i).layer: + self._sprites.insert_in_list(self, i) self.inval() return - self.sprites.append_to_list(self) + self._sprites.append_to_list(self) self.inval() def set_label(self, new_label, i=0): @@ -141,106 +149,104 @@ class Sprite: self.inval() def _extend_labels_array(self, i): - if self.fd is None: + if self._fd is None: self.set_font('Sans') - if self.color is None: - self.color = self.sprites.cm.alloc_color('black') + if self._color is None: + self._color = self._sprites.cm.alloc_color('black') while len(self.labels) < i+1: self.labels.append(" ") - self.scale.append(self.scale[0]) - self.rescale.append(self.rescale[0]) - self.horiz_align.append(self.horiz_align[0]) - self.vert_align.append(self.vert_align[0]) + self._scale.append(self._scale[0]) + self._rescale.append(self._rescale[0]) + self._horiz_align.append(self._horiz_align[0]) + self._vert_align.append(self._vert_align[0]) def set_font(self, font): - self.fd = pango.FontDescription(font) + self._fd = pango.FontDescription(font) def set_label_color(self, rgb): - self.color = self.sprites.cm.alloc_color(rgb) + self._color = self._sprites.cm.alloc_color(rgb) def set_label_attributes(self, scale, rescale=True, horiz_align="center", vert_align="middle", i=0): self._extend_labels_array(i) - self.scale[i] = scale - self.rescale[i] = rescale - self.horiz_align[i] = horiz_align - self.vert_align[i] = vert_align + self._scale[i] = scale + self._rescale[i] = rescale + self._horiz_align[i] = horiz_align + self._vert_align[i] = vert_align def hide(self): self.inval() - self.sprites.remove_from_list(self) + self._sprites.remove_from_list(self) def inval(self): - # print "inval (%f,%f) (%f,%f)" % (self.x,self.y,self.width,self.height) - self.sprites.area.invalidate_rect( - gtk.gdk.Rectangle(self.x,self.y,self.width,self.height), False) + self._sprites.area.invalidate_rect( + gtk.gdk.Rectangle(self._x,self._y,self._width,self._height), False) def draw(self): - # print "draw (%f,%f)" % (self.x,self.y) if isinstance(self.image, gtk.gdk.Pixbuf): - self.sprites.area.draw_pixbuf( - self.sprites.gc, self.image, 0, 0, self.x, self.y) + self._sprites.area.draw_pixbuf( + self._sprites.gc, self.image, 0, 0, self._x, self._y) elif self.image is not None: - self.sprites.area.draw_drawable( - self.sprites.gc, self.image, 0, 0, self.x, self.y, -1, -1) + self._sprites.area.draw_drawable( + self._sprites.gc, self.image, 0, 0, self._x, self._y, -1, -1) if len(self.labels) > 0: self.draw_label() def hit(self, pos): x, y = pos - if x < self.x: + if x < self._x: return False - if x > self.x+self.width: + if x > self._x+self._width: return False - if y < self.y: + if y < self._y: return False - if y > self.y+self.height: + if y > self._y+self._height: return False return True def draw_label(self): for i in range(len(self.labels)): - pl = self.sprites.canvas.create_pango_layout(str(self.labels[i])) - self.fd.set_size(int(self.scale[i]*pango.SCALE)) - pl.set_font_description(self.fd) + pl = self._sprites.canvas.create_pango_layout(str(self.labels[i])) + self._fd.set_size(int(self._scale[i]*pango.SCALE)) + pl.set_font_description(self._fd) w = pl.get_size()[0]/pango.SCALE - if w > self.width: - if self.rescale[i] is True: - self.fd.set_size(int(self.scale[i]*pango.SCALE*\ - self.width/w)) - pl.set_font_description(self.fd) + if w > self._width: + if self._rescale[i] is True: + self._fd.set_size(int(self._scale[i]*pango.SCALE*\ + self._width/w)) + pl.set_font_description(self._fd) w = pl.get_size()[0]/pango.SCALE else: j = len(self.labels[i])-1 - while(w > self.width and j > 0): - pl = self.sprites.canvas.create_pango_layout( + while(w > self._width and j > 0): + pl = self._sprites.canvas.create_pango_layout( "…"+self.labels[i][len(self.labels[i])-j:]) - self.fd.set_size(int(self.scale[i]*pango.SCALE)) - pl.set_font_description(self.fd) + self._fd.set_size(int(self._scale[i]*pango.SCALE)) + pl.set_font_description(self._fd) w = pl.get_size()[0]/pango.SCALE j -= 1 - if self.horiz_align[i] == "center": - x = int(self.x+(self.width-w)/2) - elif self.horiz_align[i] == 'left': - x = self.x + if self._horiz_align[i] == "center": + x = int(self._x+(self._width-w)/2) + elif self._horiz_align[i] == 'left': + x = self._x else: # right - x = int(self.x+self.width-w) + x = int(self._x+self._width-w) h = pl.get_size()[1]/pango.SCALE - if self.vert_align[i] == "middle": - y = int(self.y+(self.height-h)/2) - elif self.vert_align[i] == "top": - y = self.y + if self._vert_align[i] == "middle": + y = int(self._y+(self._height-h)/2) + elif self._vert_align[i] == "top": + y = self._y else: # bottom - y = int(self.y+self.height-h) - self.sprites.gc.set_foreground(self.color) - self.sprites.area.draw_layout(self.sprites.gc, x, y, pl) + y = int(self._y+self._height-h) + self._sprites.gc.set_foreground(self._color) + self._sprites.area.draw_layout(self._sprites.gc, x, y, pl) def label_width(self): max = 0 for i in range(len(self.labels)): - pl = self.sprites.canvas.create_pango_layout(self.labels[i]) - self.fd.set_size(int(self.scale[i]*pango.SCALE)) - pl.set_font_description(self.fd) + pl = self._sprites.canvas.create_pango_layout(self.labels[i]) + self._fd.set_size(int(self._scale[i]*pango.SCALE)) + pl.set_font_description(self._fd) w = pl.get_size()[0]/pango.SCALE if w > max: max = w diff --git a/taexporthtml.py b/taexporthtml.py index 972f406..e753d24 100644 --- a/taexporthtml.py +++ b/taexporthtml.py @@ -297,7 +297,7 @@ def walk_stack(self, tw, spr): top = tawindow.find_top_block(spr) if spr == top: # only walk the stack if the block is the top block - return talogo.run_blocks(tw.lc, top, tawindow.blocks(tw), False) + return talogo.run_blocks(tw.lc, top, tw.block_list.list, False) else: # not top of stack, then return empty list return [] diff --git a/taexportlogo.py b/taexportlogo.py index 2fb22bf..939486c 100644 --- a/taexportlogo.py +++ b/taexportlogo.py @@ -322,7 +322,7 @@ def walk_stack(self, tw, spr): top = tawindow.find_top_block(spr) if spr == top: # only walk the stack if the block is the top block - code = talogo.run_blocks(tw.lc, top, tawindow.blocks(tw), False) + code = talogo.run_blocks(tw.lc, top, tw.block_list.list, False) return code else: # not top of stack, then return empty list diff --git a/talogo.py b/talogo.py index 072da45..9b85de5 100644 --- a/talogo.py +++ b/talogo.py @@ -71,65 +71,68 @@ def run_blocks(lc, spr, blocks, run_flag): # two built-in stacks lc.stacks['stack1'] = None lc.stacks['stack2'] = None - for i in blocks: - if i.proto.name=='hat1': - lc.stacks['stack1']= readline(lc,blocks_to_code(lc,i)) - if i.proto.name=='hat2': - lc.stacks['stack2']= readline(lc,blocks_to_code(lc,i)) - if i.proto.name=='hat': - if (i.connections[1]!=None): - text=i.connections[1].label - lc.stacks['stack3'+text]= readline(lc,blocks_to_code(lc,i)) - code = blocks_to_code(lc,spr) + for b in blocks: + if b.name=='hat1': + lc.stacks['stack1']= readline(lc,blocks_to_code(lc, b)) + if b.name=='hat2': + lc.stacks['stack2']= readline(lc,blocks_to_code(lc, b)) + if b.name=='hat': + if (b.connections[1]!=None): + text=b.connections[1].labels[0] + lc.stacks['stack3'+text]= readline(lc,blocks_to_code(lc, b)) + code = blocks_to_code(lc, lc.tw.block_list.spr_to_block(spr)) if run_flag == True: print code setup_cmd(lc, code) else: return code -def blocks_to_code(lc,spr): +def blocks_to_code(lc, blk): + spr = blk.spr if spr==None: return ['%nothing%'] code = [] - dock = spr.proto.docks[0] + dock = blk.docks[0] if len(dock)>4: code.append(dock[4]) - if spr.proto.primname != '': code.append(spr.proto.primname) + if hasattr(blk, 'primname') and blk.primname is not '': + code.append(blk.primname) else: - if spr.proto.name=='number': + if blk.name=='number': try: code.append(float(spr.labels[0])) except: code.append(float(ord(spr.labels[0][0]))) - elif spr.proto.name=='string' or spr.proto.name=='title': + elif blk.name=='string' or blk.name=='title': if type(spr.labels[0]) == float or type(spr.labels[0]) == int: if int(spr.labels[0]) == spr.labels[0]: spr.labels[0] = int(spr.labels[0]) code.append('#s'+str(spr.labels[0])) else: code.append('#s'+spr.labels[0]) - elif spr.proto.name=='journal': - if spr.ds_id != None: + elif blk.name=='journal': + if spr.ds_id != None: # TODO: put ds_id in blk code.append('#smedia_'+str(spr.ds_id)) else: code.append('#smedia_None') - elif spr.proto.name=='descriptionoff' or \ - spr.proto.name=='descriptionon': + elif blk.name=='descriptionoff' or \ + blk.name=='descriptionon': if spr.ds_id != None: code.append('#sdescr_'+str(spr.ds_id)) else: code.append('#sdescr_None') - elif spr.proto.name=='audiooff' or spr.proto.name=='audio': + elif blk.name=='audiooff' or blk.name=='audio': if spr.ds_id != None: code.append('#saudio_'+str(spr.ds_id)) else: code.append('#saudio_None') else: return ['%nothing%'] - for i in range(1,len(spr.connections)): - b = spr.connections[i] - dock = spr.proto.docks[i] + for i in range(1,len(blk.connections)): + s = blk.connections[i] + dock = blk.docks[i] if len(dock)>4: for c in dock[4]: code.append(c) - if b!=None: code.extend(blocks_to_code(lc,b)) - elif spr.proto.docks[i][0] not in \ + if s is not None: + code.extend(blocks_to_code(lc, lc.tw.block_list.spr_to_block(s))) + elif blk.docks[i][0] not in \ ['flow', 'numend', 'stringend', 'mediaend', \ 'audioend', 'unavailable', 'logi-']: code.append('%nothing%') diff --git a/taproject.py b/taproject.py index 48fd5af..9841b2c 100644 --- a/taproject.py +++ b/taproject.py @@ -63,7 +63,7 @@ shape_dict = {'journal':'texton', \ def new_project(tw): stop_logo(tw) for b in blocks(tw): b.hide() - tw.turtle.canvas.set_layer(600) + tw.turtle.canvas.set_layer(CANVAS_LAYER) clearscreen(tw.turtle) tw.save_file_name = None @@ -174,8 +174,8 @@ def load_spr(tw,b): print "swapping in a forward block for %s" % (btype) proto = tw.protodict['forward'] blk = block.Block(tw.block_list, tw.sprite_list, - btype, b[2]+tw.turtle.canvas.x, - b[3]+tw.turtle.canvas.y, [label]) + btype, b[2]+tw.turtle.cx, + b[3]+tw.turtle.cy, [label]) spr = blk.spr spr.type = 'block' # phasing out spr.proto = proto # phasing out @@ -271,8 +271,9 @@ def assemble_data_to_save(tw,save_turtle=True): connections = [get_id(tw.block_list, x) for x in b.connections] else: connections = None - data.append((b.id, name, b.spr.x-tw.turtle.canvas.x, - b.spr.y-tw.turtle.canvas.y, connections)) + (sx, sy) = b.spr.get_xy() + data.append((b.id, name, sx-tw.turtle.cx, + sy-tw.turtle.cy, connections)) if save_turtle is True: data.append((-1,'turtle', tw.turtle.xcor,tw.turtle.ycor,tw.turtle.heading, @@ -305,7 +306,7 @@ def assemble_stack_to_clone(tw): spr = tw.spr data = [] if spr is not None and spr.type == 'block': - bs = findgroup(find_top_block(spr)) + bs = findgroup(find_top_block(spr, tw.block_list), tw.block_list) for i in range(len(bs)): bs[i].id=i for b in bs: name = b.proto.name @@ -318,8 +319,9 @@ def assemble_stack_to_clone(tw): connections = [get_id(x) for x in b.connections] else: connections = None - data.append((b.id,name,b.x-tw.turtle.canvas.x+20, - b.y-tw.turtle.canvas.y+20,connections)) + (sx, sy) = b.get_xy() + data.append((b.id,name,sx-tw.turtle.cx+20, + sy-tw.turtle.cy+20,connections)) return data def save_pict(tw,fname): @@ -352,18 +354,17 @@ def do_dialog(tw,dialog): def blocks(tw): return [spr for spr in tw.sprite_list.list \ if spr.type == 'block'] -def findgroup(b): - group=[b] - for b2 in b.connections[1:]: - if b2 is not None: group.extend(findgroup(b2)) +def findgroup(spr, block_list): + group=[spr] + for spr2 in block_list.spr_to_block(spr).connections[1:]: + if spr2 is not None: group.extend(findgroup(spr2, block_list)) return group -def find_top_block(spr): - b = spr - if hasattr(b,"connections"): - while b.connections[0]!=None: - b=b.connections[0] - return b +def find_top_block(spr, block_list): + blk = block_list.spr_to_block(spr) + while blk.connections[0]!=None: + blk = block_list.spr_to_block(blk.connections[0]) + return blk.spr # start a new project with a start brick def load_start(tw): diff --git a/taturtle.py b/taturtle.py index 7660f97..5e72405 100644 --- a/taturtle.py +++ b/taturtle.py @@ -60,6 +60,7 @@ def tNew(tw,w,h): t.tw, t.width, t.height = tw, w, h t.canvas = sprites.Sprite(tw.sprite_list, 0, 0, gtk.gdk.Pixmap(tw.area,w,h,-1)) + (t.cx,t.cy) = t.canvas.get_xy() t.canvas.type = 'canvas' t.canvas.set_layer(CANVAS_LAYER) t.shapelist = \ @@ -294,9 +295,9 @@ def draw_line(t,x1,y1,x2,y2): else: miny,maxy=y2,y1 w,h=maxx-minx,maxy-miny t.canvas.image.draw_line(t.gc,x1,y1,x2,y2) - invalt(t,minx-t.pensize*t.tw.coord_scale/2-3, \ - miny-t.pensize*t.tw.coord_scale/2-3, \ - w+t.pensize*t.tw.coord_scale+6, \ + invalt(t,minx-t.pensize*t.tw.coord_scale/2-3, + miny-t.pensize*t.tw.coord_scale/2-3, + w+t.pensize*t.tw.coord_scale+6, h+t.pensize*t.tw.coord_scale+6) def turn_turtle(t): @@ -304,12 +305,11 @@ def turn_turtle(t): def move_turtle(t): x,y = t.width/2+int(t.xcor), t.height/2-int(t.ycor) - t.spr.move((t.canvas.x+x-30,t.canvas.y+y-30)) - invalt(t,x-30,y-30,60,60) + t.spr.move((t.cx+x-30, t.cy+y-30)) + invalt(t, x-30, y-30, 60, 60) def invalt(t,x,y,w,h): - rect = gtk.gdk.Rectangle(int(x+t.canvas.x),int(y+t.canvas.y), \ - int(w),int(h)) + rect = gtk.gdk.Rectangle(int(x+t.cx), int(y+t.cy), int(w),int(h)) t.tw.area.invalidate_rect(rect, False) diff --git a/tawindow.py b/tawindow.py index 7175190..7f95d45 100644 --- a/tawindow.py +++ b/tawindow.py @@ -102,6 +102,7 @@ class TurtleArtWindow(): self.keypress = "" self.keyvalue = 0 self.dead_key = "" + self.firstkey = True self.area = self.window.window self.gc = self.area.new_gc() # on an OLPC-XO-1, there is a scaling factor @@ -168,9 +169,9 @@ class TurtleArtWindow(): change the icon for user-defined blocks after Python code is loaded """ def set_userdefined(self): - for spr in self.sprite_list.list: - if hasattr(spr,'proto') and spr.proto.name == 'nop': - setimage(spr,self.media_shapes['pythonloaded']) + for blk in self.block_list.list: + if blk.name == 'nop': + blk.set_image(self.media_shapes['pythonloaded']) self.nop = 'pythonloaded' """ @@ -178,11 +179,13 @@ class TurtleArtWindow(): """ def hideshow_button(self): if self.hide is False: - for b in self._blocks(): b.set_layer(HIDE_LAYER) + for b in self.block_list.list: + b.spr.set_layer(HIDE_LAYER) self._hide_palette() self.hide = True else: - for b in self._blocks(): b.set_layer(BLOCK_LAYER) + for b in self.block_list.list: + b.spr.set_layer(BLOCK_LAYER) self.show_palette() self.hide = False self.turtle.canvas.inval() @@ -194,19 +197,19 @@ class TurtleArtWindow(): def run_button(self, time): print "you better run, turtle, run!!" # look for the start block - for b in self._blocks(): - if self._find_start_stack(b): + for b in self.block_list.list: + if self._find_start_stack(b.spr): self.step_time = time if hasattr(self, 'activity'): self.activity.recenter() - self._run_stack(b) + self._run_stack(b.spr) return # no start block, so run a stack that isn't a hat - for b in self._blocks(): - if self._find_block_to_run(b): - print "running " + b.proto.name + for b in self.blocks_list.list: + if self._find_block_to_run(b.spr): + print "running " + b.name self.step_time = time - self._run_stack(b) + self._run_stack(b.spr) return """ @@ -221,6 +224,7 @@ class TurtleArtWindow(): else: self.status_spr.set_layer(HIDE_LAYER) spr = self.sprite_list.find_sprite((x,y)) + blk = self.block_list.spr_to_block(spr) print "found %s at (%d,%d)" % (str(spr),x,y) self.x, self.y = x,y self.dx = 0 @@ -229,17 +233,17 @@ class TurtleArtWindow(): return True if hasattr(spr, 'type'): print "type: %s" % (spr.type) - if spr.type == "canvas": - spr.set_layer(CANVAS_LAYER) - return True - elif spr.type == 'selbutton': - self._select_category(spr) - elif spr.type == 'category': - self._block_selector_pressed(x,y) - elif spr.type == 'block': + if spr.type == "canvas": + spr.set_layer(CANVAS_LAYER) + return True + elif spr.type == 'selbutton': + self._select_category(spr) + elif spr.type == 'category': + self._block_selector_pressed(x,y) + elif spr.type == 'turtle': + self._turtle_pressed(x,y) + elif blk is not None: self._block_pressed(mask,x,y,spr) - elif spr.type == 'turtle': - self._turtle_pressed(x,y) self.spr = spr """ @@ -361,7 +365,7 @@ class TurtleArtWindow(): """ def _find_start_stack(self, spr): top = self._find_top_block(spr) - if spr.proto.name == 'start': + if self.block_list.spr_to_block(top).name == 'start': return True else: return False @@ -393,41 +397,48 @@ class TurtleArtWindow(): self.block_operation = 'move' spr = self.draggroup[0] - if self.block_list.spr_to_block(spr) is not None: + blk = self.block_list.spr_to_block(spr) + if blk is not None: self.spr = spr dragx, dragy = self.dragpos if mdx != 0 or mdy != 0: dx,dy = mdx,mdy else: - dx,dy = x-dragx-spr.x,y-dragy-spr.y + (sx,sy) = spr.get_xy() + dx,dy = x-dragx-sx,y-dragy-sy # skip if there was a move of 0,0 if dx == 0 and dy == 0: return # drag entire stack if moving lock block - if spr.proto.name == 'lock': - self.draggroup = findgroup(find_top_block(spr)) + + if blk.name == 'lock': + self.draggroup = findgroup(self._find_top_block(spr), + self.block_list) else: - self.draggroup = findgroup(spr) + self.draggroup = findgroup(spr, self.block_list) # check to see if any block ends up with a negative x for b in self.draggroup: - if b.x+dx < 0: - dx += -(b.x+dx) + (bx, by) = b.get_xy() + if bx+dx < 0: + dx += -(bx+dx) # move the stack for b in self.draggroup: - b.move((b.x+dx, b.y+dy)) + (bx, by) = b.get_xy() + b.move((bx+dx, by+dy)) if self.turtle_list.spr_to_turtle(spr) is not None: type,dragx,dragy = self.dragpos + (sx,sy) = spr.get_xy() if type == 'move': if mdx != 0 or mdy != 0: dx,dy = mdx,mdy else: - dx,dy = x-dragx-spr.x,y-dragy-spr.y - spr.move((spr.x+dx, spr.y+dy)) + dx,dy = x-dragx-sx,y-dragy-sy + spr.move((sx+dx, sy+dy)) else: if mdx != 0 or mdy != 0: dx,dy = mdx,mdy else: - dx,dy = x-spr.x-30,y-spr.y-30 + dx,dy = x-sx-30,y-sy-30 seth(self.turtle, int(dragx+atan2(dy,dx)/DEGTOR+5)/10*10) if mdx != 0 or mdy != 0: dx,dy = 0,0 @@ -439,9 +450,9 @@ class TurtleArtWindow(): get_proto_from_category """ def _get_proto_from_category(self, x, y): + (sx,sy) = self.category_spr.get_xy() pixel = self.current_category.get_pixel(self.current_category.mask, - x-self.category_spr.x, - y-self.category_spr.y) + x-sx, y-sy) index = ((pixel%256)>>3)-1 if index==0: return 'hide' @@ -456,7 +467,18 @@ class TurtleArtWindow(): def _show_popup(self, x, y): spr = self.sprite_list.find_sprite((x,y)) blk = self.block_list.spr_to_block(spr) - if spr and spr.type == 'category': + if spr and blk is not None: + if self.timeout_tag[0] == 0: + self.timeout_tag[0] = self._do_show_popup(blk.name) + self.spr = spr + 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 spr.type == 'category': proto = self._get_proto_from_category(x, y) if proto and proto!='hide': if self.timeout_tag[0] == 0: @@ -481,17 +503,6 @@ class TurtleArtWindow(): self.timeout_tag[0] = 0 except: self.timeout_tag[0] = 0 - elif spr and blk is not None: - if self.timeout_tag[0] == 0: - self.timeout_tag[0] = self._do_show_popup(blk.name) - self.spr = spr - 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 else: if self.timeout_tag[0] > 0: try: @@ -613,7 +624,8 @@ class TurtleArtWindow(): self._jog_block(10,0) elif keyname == 'KP_Page_Down': if self.draggroup == None: - self.draggroup = findgroup(self.spr) + self.draggroup = findgroup(self.spr, + self.block_list) for b in self.draggroup: b.hide() self.draggroup = None elif self.spr.type == 'selbutton': @@ -624,7 +636,8 @@ class TurtleArtWindow(): (x,y) = self.window.get_pointer() self._block_selector_pressed(x, y) for b in self.draggroup: - b.move((b.x+200, b.y)) + (bx, by) = b.get_xy() + b.move((bx+200, by)) self.draggroup = None return True if self.selected_block is None: @@ -698,10 +711,11 @@ class TurtleArtWindow(): spr = self.draggroup[0] if self.turtle_list.spr_to_turtle(spr) is not None: print "clicked on a turtle" - self.turtle.xcor = self.turtle.spr.x-self.turtle.canvas.x- \ - self.turtle.canvas.width/2+30 - self.turtle.ycor = self.turtle.canvas.height/2-self.turtle.spr.y+ \ - self.turtle.canvas.y-30 + (tx, ty) = self.turtle.spr.get_xy() + self.turtle.xcor = tx-self.turtle.cx- \ + self.turtle.canvas._width/2+30 + self.turtle.ycor = self.turtle.canvas._height/2-ty+ \ + self.turtle.cy-30 move_turtle(self.turtle) display_coordinates(self) self.draggroup = None @@ -713,34 +727,31 @@ class TurtleArtWindow(): return if self.block_operation=='new': for b in self.draggroup: - b.move((b.x+200, b.y)) + (bx, by) = b.get_xy() + b.move((bx+200, by)) self._snap_to_dock() for b in self.draggroup: b.set_layer(BLOCK_LAYER) self.draggroup = None if self.block_operation=='click': - if self.spr.proto.name=='number': + blk = self.block_list.spr_to_block(self.spr) + if blk is not None and blk.name=='number': self.selected_block = spr - self.selected_block.set_shape( - self.block_list.spr_to_block( - self.selected_block).selected_shape) + self.selected_block.set_shape(blk.selected_shape) self.firstkey = True - elif self.defdict.has_key(spr.proto.name): + elif blk is not None and self.defdict.has_key(blk.name): self.selected_block = spr - if self.spr.proto.name=='string': - self.selected_block.set_shape( - self.block_list.spr_to_block( - self.selected_block).selected_shape) + if blk.name=='string': + self.selected_block.set_shape(blk.selected_shape) self.firstkey = True - elif self.spr.proto.name in self.importblocks: + elif blk.name in self.importblocks: self._import_from_journal(spr) - elif self.spr.proto.name=='nop' and self.myblock==None: + elif blk is not None and blk.name=='nop' and self.myblock==None: self.activity.import_py() else: # mark block as selected self.selected_block = spr - self.selected_block.set_shape( - self.block_list.spr_to_block( - self.selected_block).selected_shape) + if blk is not None: + self.selected_block.set_shape(blk.selected_shape) spr.set_selected(True) self._run_stack(spr) @@ -748,16 +759,17 @@ class TurtleArtWindow(): click block """ def _click_block(self): - if self.spr.proto.name=='number': + blk = self.block_list.spr_to_block(self.spr) + if blk is not None and blk.name=='number': self.selected_block = self.spr self.firstkey = True - elif self.defdict.has_key(self.spr.proto.name): + elif blk is not None and self.defdict.has_key(blk.name): self.selected_block = self.spr - if self.spr.proto.name=='string': + if blk.name=='string': self.firstkey = True - elif self.spr.proto.name in self.importblocks: + elif blk.name in self.importblocks: self._import_from_journal(self.spr) - elif self.spr.proto.name=='nop' and self.myblock==None: + elif blk is not None and blk.name=='nop' and self.myblock==None: self.activity.import_py() else: self._run_stack(self.spr) @@ -815,10 +827,11 @@ class TurtleArtWindow(): break if d<200: for b in self.draggroup: - b.move((b.x+best_xy[0],b.y+best_xy[1])) + (bx, by) = b.get_xy() + b.move((bx+best_xy[0],by+best_xy[1])) block_in_dock = best_you.connections[best_your_dockn] if block_in_dock is not None: - for b in findgroup(block_in_dock): + for b in findgroup(block_in_dock, self.block_list): b.hide() best_you.connections[best_your_dockn] = my_block.spr if my_block.connections is not None: @@ -836,12 +849,13 @@ class TurtleArtWindow(): if result == gtk.RESPONSE_ACCEPT: dsobject = chooser.get_selected_object() # change block graphic to indicate that object is "loaded" - if spr.proto.name == 'journal': + blk = self.block_list.spr_to_block(spr) + if blk.name == 'journal': self._load_image(dsobject, spr) - elif spr.proto.name == 'audiooff': - setimage(spr,self.media_shapes['audioon']) + elif blk.name == 'audiooff': + spr.set_image(self.media_shapes['audioon']) else: - setimage(spr, self.media_shapes['decson']) + spr.set_image(self.media_shapes['decson']) spr.ds_id = dsobject.object_id dsobject.destroy() finally: @@ -856,10 +870,11 @@ class TurtleArtWindow(): def _run_stack(self, spr): self.lc.ag = None top = self._find_top_block(spr) - run_blocks(self.lc, top, self._blocks(), True) + run_blocks(self.lc, top, self.block_list.list, True) gobject.idle_add(doevalstep, self.lc) """ + # phased out filter out blocks """ def _blocks(self): @@ -900,51 +915,44 @@ class TurtleArtWindow(): newspr.set_layer(TOP_LAYER) self.dragpos = 20,20 - newspr.type = 'block' # phasing this out - newspr.proto = proto # phasing this out - if self.defdict.has_key(newspr.proto.name): + newblk.primname = proto.primname + if self.defdict.has_key(newblk.name): newspr.labels[0]=self.defdict[newblk.name] - newspr.connections = [None]*len(proto.docks) # phasing this out newblk.connections = [None]*len(newblk.docks) - print "new %s" % (newblk.connections) + print "%s: %s" % (newblk.name, newblk.connections) for i in range(len(newblk.defaults)): dock = newblk.docks[i+1] - print dock argproto = self.protodict[self.valdict[dock[0]]] - print argproto argdock = argproto.docks[0] - print argdock - nx,ny = newspr.x+dock[2]-argdock[2],newspr.y+dock[3]-argdock[3] + (sx, sy) = newspr.get_xy() + nx, ny = sx+dock[2]-argdock[2], sy+dock[3]-argdock[3] argblk = block.Block(self.block_list, self.sprite_list, argproto.name, nx, ny) argspr = argblk.spr - argspr.type = 'block' - argspr.proto = argproto argspr.set_label(str(newblk.defaults[i])) argspr.set_layer(TOP_LAYER) - argspr.connections = [newspr,None] # phasing this out argblk.connections = [newspr,None] - newspr.connections[i+1] = argspr # phasing this out newblk.connections[i+1] = argspr - print "%s %s" % (argblk.name, argblk.connections) - print "%s %s" % (newblk.name, newblk.connections) - self.draggroup = findgroup(newspr) + print "%s: %s" % (argblk.name, argblk.connections) + self.draggroup = findgroup(newspr, self.block_list) self.block_operation = 'new' - """ block pressed TODO: mark block as selected """ def _block_pressed(self, mask, x, y, spr): if spr is not None: - self.draggroup = findgroup(spr) + self.draggroup = findgroup(spr, self.block_list) for b in self.draggroup: b.set_layer(TOP_LAYER) - if spr.connections[0] != None and spr.proto.name == 'lock': + if self.block_list.spr_to_block(spr).connections[0] is not None and\ + self.block_list.spr_to_block(spr).name == 'lock': b = self._find_top_block(spr) - self.dragpos = x-b.x,y-b.y + (bx, by) = b.get_xy() + self.dragpos = x-bx,y-by else: - self.dragpos = x-spr.x,y-spr.y + (sx, sy) = spr.get_xy() + self.dragpos = x-sx,y-sy self._disconnect(spr) """ @@ -963,15 +971,14 @@ class TurtleArtWindow(): turtle pressed """ def _turtle_pressed(self, x, y): - dx,dy = x-self.turtle.spr.x-30,y-self.turtle.spr.y-30 + (tx, ty) = self.turtle.spr.get_xy() + dx, dy = x-tx-30, y-ty-30 if dx*dx+dy*dy > 200: - self.dragpos = ('turn', \ - self.turtle.heading-atan2(dy,dx)/DEGTOR,0) + self.dragpos = ('turn', self.turtle.heading-atan2(dy,dx)/DEGTOR, 0) else: - self.dragpos = ('move', x-self.turtle.spr.x,y-self.turtle.spr.y) + self.dragpos = ('move', x-tx, y-ty) self.draggroup = [self.turtle.spr] - """ Replace Journal block graphic with preview image """ @@ -979,27 +986,29 @@ class TurtleArtWindow(): from talogo import get_pixbuf_from_journal pixbuf = get_pixbuf_from_journal(picture,spr.width,spr.height) if pixbuf is not None: - setimage(spr, pixbuf) + spr.set_image(pixbuf) else: - setimage(spr, self.media_shapes['texton']) + spr.set_image(self.media_shapes['texton']) """ dock_dx_dy """ def _dock_dx_dy(self, block1, dock1n, block2, dock2n): + print "comparing %s %d, %s %d" % (block1.name, dock1n, + block2.name, dock2n) dock1 = block1.docks[dock1n] dock2 = block2.docks[dock2n] d1type, d1dir, d1x, d1y = dock1[0:4] d2type, d2dir, d2x, d2y = dock2[0:4] - ''' - if (d2type!='num') or (dock2n!=0): + print "%s %s %d %d" % (d1type, str(d1dir), d1x, d1y) + print "%s %s %d %d" % (d2type, str(d2dir), d2x, d2y) + if (d2type is not 'num') or (dock2n is not 0): if block1.connections is not None and dock1n < block1.connections\ and block1.connections[dock1n] is not None: return (100,100) 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) @@ -1031,10 +1040,12 @@ class TurtleArtWindow(): 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)) + (b1x, b1y) = block1.spr.get_xy() + (b2x, b2y) = block2.spr.get_xy() + display_coordinates(self, (b1x+d1x)-(b2x+d2x), + (b1y+d1y)-(b2y+d2y), 0) + return ((b1x+d1x)-(b2x+d2x), + (b1y+d1y)-(b2y+d2y)) """ magnitude @@ -1062,17 +1073,20 @@ class TurtleArtWindow(): """ def _jog_block(self,dx,dy): # drag entire stack if moving lock block - if self.spr.proto.name == 'lock': - self.draggroup = findgroup(self._find_top_block(self.spr)) + if self.block_list.spr_to_block(spr).name == 'lock': + self.draggroup = findgroup(self._find_top_block(self.spr), + self.block_list) else: - self.draggroup = findgroup(self.spr) + self.draggroup = findgroup(self.spr, self.block_list) # check to see if any block ends up with a negative x for b in self.draggroup: - if b.x+dx < 0: - dx += -(b.x+dx) + (bx, by) = b.get_xy() + if bx+dx < 0: + dx += -(bx+dx) # move the stack for b in self.draggroup: - b.move((b.x+dx, b.y-dy)) + (bx, by) = b.get_xy() + b.move((bx+dx, by-dy)) self._snap_to_dock() self.draggroup = None -- cgit v0.9.1