From 195b840e6feca6089768941a694ec9832f509006 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 03 Feb 2010 18:28:17 +0000 Subject: tighter turtle display code --- diff --git a/tacanvas.py b/tacanvas.py index bc42a63..362cc7f 100644 --- a/tacanvas.py +++ b/tacanvas.py @@ -99,7 +99,6 @@ class TurtleGraphics: self.xcor, self.ycor, self.heading = 0, 0, 0 self.move_turtle() self.turn_turtle() - self.tw.turtle_list.show_all() self.set_turtle(0) def forward(self, n): @@ -307,14 +306,13 @@ class TurtleGraphics: def move_turtle(self): x, y = self.width/2+int(self.xcor), self.height/2-int(self.ycor) self.tw.active_turtle.move((self.cx+x-30, self.cy+y-30)) - self.invalt(x-30,y-30,60,60) + # self.invalt(x-30,y-30,60,60) def invalt(self, x, y, w, h): rect = gtk.gdk.Rectangle(int(x+self.cx), int(y+self.cy), int(w),int(h)) self.tw.area.invalidate_rect(rect, False) def set_turtle(self, i): - # TODO: reskin active turtle if i > self.tw.turtle_list.turtle_count()-1: # if it is a new turtle, start it in the center of the screen self.tw.active_turtle = self.tw.turtle_list.get_turtle(i, True) @@ -333,5 +331,3 @@ class TurtleGraphics: self.setshade(self.tw.active_turtle.get_shade()) self.setpensize(self.tw.active_turtle.get_pen_size()) self.pendown = self.tw.active_turtle.get_pen_state() - self.tw.turtle_list.show_all() - diff --git a/talogo.py b/talogo.py index 0180ff5..09c18b4 100644 --- a/talogo.py +++ b/talogo.py @@ -158,7 +158,8 @@ def calc_position(tw, t): def stop_logo(tw): tw.step_time = 0 tw.lc.step = just_stop() - + tw.turtle_list.show_all() + def just_stop(): yield False @@ -400,8 +401,8 @@ class LogoCode: self.tw.active_turtle.hide() # Hide the turtle while we are running. self.procstop = False list = self.readline(str) - # print list self.step = self.start_eval(list) + # self.tw.turtle_list.show_all() """ Convert the pseudocode into a list of commands. @@ -462,7 +463,6 @@ class LogoCode: oldiline = self.iline self.iline = list[:] self.arglist = None - # print "evline: %s" % (self.iline) while self.iline: if self.tw.step_time > 0: # show the turtle during idle time self.tw.active_turtle.show() @@ -490,7 +490,6 @@ class LogoCode: """ def eval(self, infixarg=False): token = self.iline.pop(0) - # print "eval: %s" % (str(token)) if type(token) == self.symtype: self.icall(self.evalsym, token) yield True @@ -513,7 +512,6 @@ class LogoCode: self.undefined_check(token) oldcfun, oldarglist = self.cfun, self.arglist self.cfun, self.arglist = token, [] - # print " evalsym: %s %s" % (str(self.cfun), str(self.arglist)) if token.nargs == None: raise logoerror("#noinput") for i in range(token.nargs): @@ -532,7 +530,6 @@ class LogoCode: else: # TODO: find out why stopstack args are mismatched if token.name == 'stopstack': - print "%s: %d" % (token.name, len(self.arglist)) result = self.cfun.fcn() else: result = self.cfun.fcn(self, *self.arglist) diff --git a/taturtle.py b/taturtle.py index 42a54c9..acf051e 100644 --- a/taturtle.py +++ b/taturtle.py @@ -80,6 +80,7 @@ class Turtle: scale=1.0): self.x = 0 self.y = 0 + self.hidden = False self.shapes = [] self.type = 'turtle' self.heading = 0 @@ -110,9 +111,11 @@ class Turtle: self.heading = heading i = (int(self.heading+5)%360)/10 try: - self.spr.set_shape(self.shapes[i]) + if self.hidden is False: + self.spr.set_shape(self.shapes[i]) except IndexError: - self.spr.set_shape(self.shapes[0]) + if self.hidden is False: + self.spr.set_shape(self.shapes[0]) print "Turtle shape IndexError %f -> %d" % (heading, i) def set_color(self, color): @@ -129,13 +132,18 @@ class Turtle: def hide(self): self.spr.set_layer(HIDE_LAYER) + self.hidden = True def show(self): self.spr.set_layer(TURTLE_LAYER) + self.hidden = False + self.move((self.x, self.y)) + self.set_heading(self.heading) def move(self, pos): self.x, self.y = pos[0], pos[1] - self.spr.move(pos) + if self.hidden is False: + self.spr.move(pos) def get_xy(self): return(self.x, self.y) diff --git a/tawindow.py b/tawindow.py index 6841d01..4309912 100644 --- a/tawindow.py +++ b/tawindow.py @@ -1606,11 +1606,11 @@ class TurtleArtWindow(): elif btype == 'hspace' or btype == 'identity2': if value is not None: blk.expand_in_x(value) - elif btype == 'list': + elif btype == 'templatelist': for i in range(len(b[4])-4): dy = blk.add_arg() elif btype in BOX_STYLE_MEDIA and len(blk.values)>0: - if blk.values[0] == 'None': + if blk.values[0] == 'None' or blk.values[0] == None: blk.spr.set_image(self.media_shapes[btype+'off'], 1, MEDIA_X, MEDIA_Y) elif btype == 'audio' or btype == 'description': -- cgit v0.9.1