From a30ed7c96cee279ac0449d5bf816d7f23dcf3d94 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 20 Jan 2010 14:14:27 +0000 Subject: broken sprites, but closer to working? --- diff --git a/block.py b/block.py index 45412b8..5a7cb3d 100644 --- a/block.py +++ b/block.py @@ -62,11 +62,11 @@ class Blocks: # A class for the individual blocks # class Block: - def __init__(self, blocks, prototype_style, labels=[], + def __init__(self, blocks, proto_name, x, y, labels=[], colors=["#00A000","#00FF00"], scale=1.0): self.blocks = blocks self.spr = None - self._new_block_from_prototype(prototype_style, labels, colors, scale) + self._new_block_from_prototype(proto_name, labels, colors, scale, x, y) self.blocks.append_to_list(self) # # TODO: @@ -78,10 +78,11 @@ class Block: # debug code # etc. - def _new_block_from_prototype(self, proto_name, labels, colors, scale): + def _new_block_from_prototype(self, name, labels, colors, scale, x, y): + print "%s %s (%d %d)" % (name, labels[0], x, y) basic_style = ['forward', 'back', 'left', 'right'] box_style = ['number'] - if proto_name in basic_style: + if name in basic_style: svg = block_factory.SVG() svg.set_scale(scale) svg.expand(20,0) @@ -91,15 +92,19 @@ class Block: svg.set_slot(True) svg.set_gradiant(True) svg.set_colors(colors) - self.spr = sprites.Sprite(self.blocks.sprites, 0, 0, + print "creating new basic block" + self.spr = sprites.Sprite(self.blocks.sprites, x, y, svg_str_to_pixbuf(svg.basic_block())) - elif proto_name in number_style: + self.spr.set_layer(2000) + self.spr.draw() + self.spr.set_label(labels[0]) + elif name in box_style: svg = block_factory.SVG() svg.set_scale(scale) svg.expand(20,0) svg.set_gradiant(True) svg.set_colors(colors) - self.spr = sprites.Sprite(self.blocks.sprites, 0, 0, + self.spr = sprites.Sprite(self.blocks.sprites, x, y, svg_str_to_pixbuf(svg.basic_box())) for l in labels: diff --git a/sprites.py b/sprites.py index e737057..bf1433d 100644 --- a/sprites.py +++ b/sprites.py @@ -31,10 +31,14 @@ import pango # A class for the list of sprites and everything they share in common # class Sprites: - def __init__(self, canvas): + def __init__(self, canvas, area=None, gc=None): self.canvas = canvas - self.area = self.canvas.window - self.gc = self.area.new_gc() + if area == None: + self.area = self.canvas.window + self.gc = self.area.new_gc() + else: + self.area = area + self.gc = gc self.cm = self.gc.get_colormap() self.list = [] diff --git a/talogo.py b/talogo.py index 849e1e7..6487ec8 100644 --- a/talogo.py +++ b/talogo.py @@ -158,7 +158,7 @@ def readline(lc, line): return res def setup_cmd(lc, str): - lc.tw.turtle.spr.setlayer(100) + lc.tw.turtle.spr.set_layer(100) lc.procstop=False list = readline(lc, str) lc.step = start_eval(lc, list) @@ -176,11 +176,11 @@ def evline(lc, list): lc.arglist = None while lc.iline: if lc.tw.step_time > 0: - lc.tw.turtle.spr.setlayer(630) + lc.tw.turtle.spr.set_layer(630) endtime = millis()+an_int(lc,lc.tw.step_time)*100 while millis()