From 8f715ebd18e6403bdcc81811660bf6cfba9e0adf Mon Sep 17 00:00:00 2001 From: Pootle Translation Date: Sun, 15 Feb 2009 18:17:06 +0000 Subject: Fix conflicts --- (limited to 'talogo.py') diff --git a/talogo.py b/talogo.py index 77a772a..e333455 100644 --- a/talogo.py +++ b/talogo.py @@ -1,4 +1,4 @@ -#Copyright (c) 2007-8, Playful Invention Company. +#Copyright (c) 2007-9, Playful Invention Company. #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal @@ -19,18 +19,28 @@ #THE SOFTWARE. import re -from time import clock +from time import * +import gobject from operator import isNumberType import random -from math import sqrt +import audioop +from math import * +import subprocess +from UserDict import UserDict +from sugar.datastore import datastore + +class noKeyError(UserDict): + __missing__=lambda x,y: 0 + class taLogo: pass from taturtle import * +from tagplay import * +from tajail import * procstop = False class symbol: - def __init__(self, name): self.name = name self.nargs = None @@ -45,40 +55,66 @@ class logoerror(Exception): def __str__(self): return repr(self.value) -def run_blocks(lc, spr, blocks): - 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(i)) - if i.proto.name=='hat2': lc.stacks['stack2']= readline(lc,blocks_to_code(i)) - code = blocks_to_code(spr) - print code - setup_cmd(lc, code) - -# walk through the blocks, but don't execute them -# used by save Logo code -def walk_blocks(lc, spr, blocks): +def run_blocks(lc, spr, blocks, run_flag): + # user-defined stacks + for x in lc.stacks.keys(): + lc.stacks[x]= None + # 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(i)) - if i.proto.name=='hat2': lc.stacks['stack2']= readline(lc,blocks_to_code(i)) - return blocks_to_code(spr) - -def blocks_to_code(spr): + 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) + if run_flag == True: + print code + setup_cmd(lc, code) + else: return code + +def blocks_to_code(lc,spr): if spr==None: return ['%nothing%'] code = [] dock = spr.proto.docks[0] if len(dock)>4: code.append(dock[4]) if spr.proto.primname != '': code.append(spr.proto.primname) - else: code.append(float(spr.label)) + else: + if spr.proto.name=='number': + try: + code.append(float(spr.label)) + except: + code.append(float(ord(spr.label[0]))) + elif spr.proto.name=='string' or spr.proto.name=='title': + if type(spr.label) == float or type(spr.label) == int: + code.append('#s'+str(spr.label)) + else: + code.append('#s'+spr.label) + elif spr.proto.name=='journal': + if spr.ds_id != None: + code.append('#smedia_'+str(spr.ds_id)) + else: + code.append('#smedia_None') + elif spr.proto.name=='audiooff' or spr.proto.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] if len(dock)>4: for c in dock[4]: code.append(c) - if b!=None: code.extend(blocks_to_code(b)) - elif spr.proto.docks[i][0] not in ['flow','numend','unavailable','logi-']: + if b!=None: code.extend(blocks_to_code(lc,b)) + elif spr.proto.docks[i][0] not in \ + ['flow', 'numend', 'stringend', 'mediaend', \ + 'audioend', 'unavailable', 'logi-']: code.append('%nothing%') return code @@ -88,7 +124,6 @@ def intern(lc, str): lc.oblist[str] = sym return sym - def parseline(str): split = re.split(r"\s|([\[\]()])", str) return [x for x in split if x and x != ""] @@ -99,16 +134,18 @@ def readline(lc, line): token = line.pop(0) if isNumberType(token): res.append(token) elif token.isdigit(): res.append(float(token)) - elif token[0]=='-' and token[1:].isdigit(): res.append(-float(token[1:])) + elif token[0]=='-' and token[1:].isdigit(): + res.append(-float(token[1:])) elif token[0] == '"': res.append(token[1:]) + elif token[0:2] == "#s": res.append(token[2:]) elif token == '[': res.append(readline(lc,line)) elif token == ']': return res else: res.append(intern(lc, token)) return res - def setup_cmd(lc, str): - stopsignon(lc); lc.procstop=False + setlayer(lc.tw.turtle.spr,100) + lc.procstop=False list = readline(lc, str) lc.step = start_eval(lc, list) @@ -121,6 +158,12 @@ def evline(lc, list): lc.iline = list[:] lc.arglist = None while lc.iline: + if lc.tw.step_time > 0: + setlayer(lc.tw.turtle.spr,630) + endtime = millis()+an_int(lc,lc.tw.step_time)*100 + while millis()float(y)) - defprim(lc,'less?', 2, lambda lc,x,y: float(x)