diff options
author | Walter Bender <walter@walter-laptop.(none)> | 2010-02-01 17:05:47 (GMT) |
---|---|---|
committer | Walter Bender <walter@walter-laptop.(none)> | 2010-02-01 17:05:47 (GMT) |
commit | 98f76c5aca9745cd83a67e7d1d4c725c4929381b (patch) | |
tree | 12fe0955c6ffa55357a6512c631a7ec1b877997e | |
parent | 861293558f6ab522d615839556de58db8bf04fb1 (diff) |
more cleaning up, bug chasing
-rw-r--r-- | constants.py | 15 | ||||
-rw-r--r-- | taexporthtml.py | 3 | ||||
-rw-r--r-- | taexportlogo.py | 3 | ||||
-rw-r--r-- | talogo.py | 75 | ||||
-rw-r--r-- | taproject.py | 6 | ||||
-rw-r--r-- | tawindow.py | 2 |
6 files changed, 54 insertions, 50 deletions
diff --git a/constants.py b/constants.py index fee8364..e57968f 100644 --- a/constants.py +++ b/constants.py @@ -78,7 +78,6 @@ STANDARD_STROKE_WIDTH = 1.0 PALETTE_SCALE = {'template2x2':1.0, 'template1x2':1.0} - # # block style definitions # @@ -396,7 +395,19 @@ OLD_NAMES = {'product':'product2', 'storeinbox':'storein', 'descriptionoff':'description','template3':'list', 'template1':'template1x1', 'template2':'template2x1', 'template6':'template1x2', 'template7':'template2x2', - 'template8':'template1x1' } + 'template4':'template1x1', 'hres':'width', 'vres':'height' } + +# +# Define the relative size and postion of media objects +# (w, h, x, y, dx, dy) +# +TEMPLATES = {'t1x1': (0.5, 0.5, 0.0625, 0.125, 1.05, 0), + 't2z1': (0.5, 0.5, 0.0625, 0.125, 1.05, 1.05), + 't1x2': (0.45, 0.45, 0.0625, 0.125, 1.05, 1.05), + 't2x2': (0.45, 0.45, 0.0625, 0.125, 1.05, 1.05), + 't1x1a': (0.9, 0.9, 0.0625, 0.125, 0, 0), + 'bullet': (1, 1, 0.0625, 0.125, 0, 0.1), + 'insertimage': (0.333, 0.333)} # # 'dead key' Unicode dictionaries diff --git a/taexporthtml.py b/taexporthtml.py index e753d24..4c7f5d2 100644 --- a/taexporthtml.py +++ b/taexporthtml.py @@ -19,7 +19,6 @@ #THE SOFTWARE. import tawindow -import talogo from sugar.activity import activity from sugar.datastore import datastore import os.path @@ -297,7 +296,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, tw.block_list.list, False) + return tw.lc.run_blocks(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 939486c..94e5016 100644 --- a/taexportlogo.py +++ b/taexportlogo.py @@ -19,7 +19,6 @@ #THE SOFTWARE. import tawindow -import talogo import math try: from sugar.datastore import datastore @@ -322,7 +321,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, tw.block_list.list, False) + code = tw.lc.run_blocks(top, tw.block_list.list, False) return code else: # not top of stack, then return empty list @@ -85,7 +85,7 @@ def careful_divide(x,y): except: return 0 -def taequal(self, x,y): +def taequal(x,y): try: return float(x)==float(y) except: @@ -99,7 +99,7 @@ def taequal(self, x,y): yy = y return xx==yy -def taless(self, x, y): +def taless(x, y): try: return float(x)<float(y) except: @@ -189,6 +189,16 @@ def get_pixbuf_from_journal(dsobject, w, h): pixbuf = None return pixbuf +def calc_position(tw, t): + w,h,x,y,dx,dy = TEMPLATES[t] + x *= tw.canvas.width + y *= tw.canvas.height + w *= (tw.canvas.width-x) + h *= (tw.canvas.height-y) + dx *= w + dy *= h + return(w,h,x,y,dx,dy) + def stop_logo(tw): tw.step_time = 0 tw.lc.step = just_stop() @@ -263,10 +273,10 @@ class LogoCode: self.defprim('left', 1, lambda self,x: self.tw.canvas.right(-x)) self.defprim('heading', 0, lambda self: self.tw.canvas.heading) self.defprim('setxy', 2, lambda self, x, y: self.tw.canvas.setxy(x, y)) - self.defprim('show',1,lambda self, x: show(self, x, True)) + self.defprim('show',1,lambda self, x: self.show(x, True)) self.defprim('setscale', 1, lambda self,x: self.set_scale(x)) self.defprim('scale', 0, lambda self: self.scale) - self.defprim('write',2,lambda self, x,y: self.write(self, x,y)) + self.defprim('write', 2, lambda self, x,y: self.write(self, x,y)) self.defprim('insertimage', 1, lambda self,x: self.insert_image(x, False)) self.defprim('arc', 2, lambda self, x, y: self.tw.canvas.arc(x, y)) @@ -310,7 +320,7 @@ class LogoCode: self.defprim('forever', 1, self.prim_forever, True) self.defprim('if', 2, self.prim_if, True) self.defprim('ifelse', 3, self.prim_ifelse, True) - self.defprim('stopstack', 0, self.prim_stopstack) + self.defprim('stopstack', 0, self.prim_stopstack, True) # blocks primitives self.defprim('stack1', 0, self.prim_stack1, True) @@ -318,7 +328,7 @@ class LogoCode: self.defprim('stack', 1, self.prim_stack, True) self.defprim('box1', 0, lambda self: self.boxes['box1']) self.defprim('box2', 0, lambda self: self.boxes['box2']) - self.defprim('box', 1, lambda self,x: box(self,x)) + self.defprim('box', 1, lambda self,x: self.box(x)) self.defprim('storeinbox1', 1, lambda self,x: self.setbox('box1',x)) self.defprim('storeinbox2', 1, lambda self,x: self.setbox('box2',x)) self.defprim('storeinbox', 2, @@ -372,17 +382,6 @@ class LogoCode: self.body_height = int((self.tw.canvas.height/60)*self.tw.scale) self.bullet_height = int((self.tw.canvas.height/45)*self.tw.scale) - # This dictionary is used to define the relative size and postion of - # template elements (w, h, x, y, dx, dy, dx1, dy1...). - self.templates = { - 't1x1': (0.5, 0.5, 0.0625, 0.125, 1.05, 0), - 't2z1': (0.5, 0.5, 0.0625, 0.125, 1.05, 1.05), - 'bullet': (1, 1, 0.0625, 0.125, 0, 0.1), - 't1x2': (0.45, 0.45, 0.0625, 0.125, 1.05, 1.05), - 't2x2': (0.45, 0.45, 0.0625, 0.125, 1.05, 1.05), - 't1x1a': (0.9, 0.9, 0.0625, 0.125, 0, 0), - 'insertimage': (0.333, 0.333) - } self.scale = 33 def run_blocks(self, blk, blocks, run_flag): @@ -566,7 +565,7 @@ class LogoCode: no_args_check(self) self.icall(self.eval, True); yield True self.arglist.append(self.iresult) - result = self.cfun.fcn(self,*self.arglist) + result = self.cfun.fcn(self, *self.arglist) self.cfun, self.arglist = oldcfun, oldarglist self.ireturn(result) yield True @@ -780,37 +779,33 @@ class LogoCode: if media == "" or media[6:] == "": pass elif media[6:] is not "None": + text = None if self.tw.running_sugar(): try: dsobject = datastore.get(media[6:]) text = dsobject.metadata['description'] dsobject.destroy() except: - print "no description?" + print "no description in %s" % (media[6:]) else: - f = open(media[6:], 'r') - text = f.read() - f.close() - self.tw.canvas.draw_text(text, int(x), int(y), - self.body_height, int(w)) + try: + f = open(media[6:], 'r') + text = f.read() + f.close() + except: + print "no text in %s?" % (media[6:]) + if text is not None: + print "text: %s" % (text) + self.tw.canvas.draw_text(text, int(x), int(y), + self.body_height, int(w)) def draw_title(self, title,x,y): self.tw.canvas.draw_text(title,int(x),int(y),self.title_height, self.tw.canvas.width-x) - def calc_position(self, t): - w,h,x,y,dx,dy = self.templates[t] - x *= self.tw.canvas.width - y *= self.tw.canvas.height - w *= (self.tw.canvas.width-x) - h *= (self.tw.canvas.height-y) - dx *= w - dy *= h - return(w,h,x,y,dx,dy) - # title, one image, and description def show_template1x1(self, title, media): - w,h,xo,yo,dx,dy = self.calc_position('t1x1') + w,h,xo,yo,dx,dy = calc_position(self.tw, 't1x1') x = -(self.tw.canvas.width/2)+xo y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) @@ -839,7 +834,7 @@ class LogoCode: # title, two images (horizontal), two descriptions def show_template2x1(self, title, media1, media2): - w,h,xo,yo,dx,dy = self.calc_position('t2x1') + w,h,xo,yo,dx,dy = calc_position(self.tw, 't2x1') x = -(self.tw.canvas.width/2)+xo y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) @@ -874,7 +869,7 @@ class LogoCode: # title and varible number of bullets def show_bullets(self, title, sarray): - w,h,xo,yo,dx,dy = self.calc_position('bullet') + w,h,xo,yo,dx,dy = calc_position(self.tw, 'bullet') x = -(self.tw.canvas.width/2)+xo y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) @@ -965,7 +960,7 @@ class LogoCode: # title, one media object def show_template1x1a(self, title, media1): - w,h,xo,yo,dx,dy = self.calc_position('t1x1a') + w,h,xo,yo,dx,dy = calc_position(self.tw, 't1x1a') x = -(self.tw.canvas.width/2)+xo y = self.tw.canvas.height/2 self.tw.canvas.setxy(x, y) @@ -999,7 +994,7 @@ class LogoCode: x -= w/2 y -= h/2 if media[0:5] == 'media': - show_picture(self, media, x, y, w, h) + self.show_picture(media, x, y, w, h) # description text only (at current x,y) def insert_desc(self, media): @@ -1009,7 +1004,7 @@ class LogoCode: x = self.tw.canvas.width/2+int(self.tw.canvas.xcor) y = self.tw.canvas.height/2-int(self.tw.canvas.ycor) if media[0:5] == 'descr': - show_description(self, media, x, y, w, h) + self.show_description(media, x, y, w, h) def set_scale(self, x): self.scale = x diff --git a/taproject.py b/taproject.py index 978ded8..29495de 100644 --- a/taproject.py +++ b/taproject.py @@ -186,7 +186,7 @@ def load_block(tw, b): blk = block.Block(tw.block_list, tw.sprite_list, btype, b[2]+tw.canvas.cx, b[3]+tw.canvas.cy, 'block', values) - # Some blocks t a skin. + # Some blocks get a skin. if btype == 'nop': if tw.nop == 'pythonloaded': blk.spr.set_image(tw.media_shapes['pythonon'], 1, 17, 8) @@ -201,9 +201,9 @@ def load_block(tw, b): elif btype == 'list': for i in range(len(b[4])-4): dy = blk.add_arg() - - elif btype in BOX_STYLE_MEDIA and blk.values[0] is not None: + elif btype in BOX_STYLE_MEDIA and len(blk.values)>0: if btype == 'audio' or btype == 'description': + print "restoring %s to %s block" % (blk.values[0],blk.name) blk.spr.set_image(tw.media_shapes[btype+'on'], 1, 37, 6) elif tw.running_sugar(): try: diff --git a/tawindow.py b/tawindow.py index dbe1685..d0c1587 100644 --- a/tawindow.py +++ b/tawindow.py @@ -1062,7 +1062,7 @@ class TurtleArtWindow(): blk.spr.set_image(self.media_shapes['audioon'], 1, 37, 6) else: - blk.spr.set_image(self.media_shapes['decsriptionon'], + blk.spr.set_image(self.media_shapes['descriptionon'], 1, 37, 6) blk.values[0] = dsobject.object_id dsobject.destroy() |