def measure_height(blocks): PATH = "tests/measure.sb" if isinstance(blocks, kurt.Block): blocks = [blocks] p = kurt.Project() #s = kurt.Sprite(p, "measure") #s.costume = kurt.Costume("b", kurt.Image(PIL.Image.new("RGB", (1, 1)))) s = p.stage s.scripts.append(kurt.Script(blocks)) s.scripts.append(kurt.Script([kurt.Block("say")])) #p.sprites.append(s) p.convert("scratch14") p.save(PATH) mtime = os.stat(PATH).st_mtime os.system("open %s" % PATH) while 1: try: if os.stat(PATH).st_mtime != mtime: break except OSError: pass cp = kurt.Project.load(PATH) #scripts = sorted(cp.sprites[0].scripts, key=lambda s: s.pos[1]) scripts = sorted(cp.stage.scripts, key=lambda s: s.pos[1]) (x1, y1) = scripts[0].pos (x2, y2) = scripts[1].pos height = y2 - y1 - 15 return height
def parse(program, scriptable): global token, next, context, p_input # for errors p_input = program context = scriptable next = tokenize(program).next token = next() result = expression() if not isinstance(token, end_token): throw("Expected end of input") if isinstance(result, kurt.Block): result = [result] if not isinstance(result, list): throw("Result does not evaluate to a block") return kurt.Script(result)
def load_script(self, script_array): (pos, blocks) = script_array # comment? if len(blocks) == 1: block = blocks[0] if block: if (isinstance(block[0], Symbol) and block[0].value == 'scratchComment'): text = block[1].replace("\r", "\n") comment = kurt.Comment(text, pos) if len(block) > 4: comment._anchor = block[4] return comment # script return kurt.Script(map(self.load_block, blocks), pos)
def load_script(self, script_array): (x, y, blocks) = script_array blocks = map(self.load_block, blocks) return kurt.Script(blocks, pos=(x, y))