def loadfromschooldata(string): # init an empty sketch sketch = Sketch.Sketch(sketch_id='shape', strokes=[]) # find lines lines = string.splitlines() laststroke = -1 pointid = 0 strokelist = [] # for each line for line in lines: # obtain point parameters numbers = line.split('\t') # if a new stroke is found if int(numbers[2]) > laststroke: # init a new empty stroke laststroke = laststroke + 1 strokelist.append(Stroke.Stroke(str(laststroke))) # add the point to its corresponding stroke strokelist[laststroke].addPoint( Point.Point('p' + str(pointid), float(numbers[3]), float(numbers[0]), float(numbers[1]))) pointid = pointid + 1 # finally add the strokes to the sketch for stroke in strokelist: sketch.addStrokes(stroke) return sketch
def jsonshape(string): # parse json string shapejson = json.loads(string) # init an empty sketch sketch = Sketch.Sketch(sketch_id=shapejson['id'], strokes=[]) # for each stroke for stroke in shapejson['strokes']: # init an empty stroke st = Stroke.Stroke(stroke['id']) # for each point in a stroke for point in stroke['points']: # add the point to the stroke st.addPoint( Point.Point(point['pid'], float(point['time']), float(point['x']), float(point['y']))) # add the stroke to the sketch sketch.addStrokes(st) return sketch
def extractFromXML(string): root = ET.fromstring(string) points = getPoints(root) strokes = getStrokes(points, root) sketch = Sketch.Sketch(root.get('id'), strokes) return sketch
def __init__(self, master, **options): Canvas.__init__(self, master, options) self.configure(background='white') self.sketch = Sketch(self) self.pack(side=LEFT)