Files
@ f669c32706e5
Branch filter:
Location: Diana/src/drawer/base.py - annotation
f669c32706e5
1.4 KiB
text/x-python
refactoring: much of SourceFile.createDiagram moved to drawer, created drawer.Base class
f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 f669c32706e5 | import os
from itertools import count
from jinja2 import Environment,FileSystemLoader
class DiagramPoint:
def __init__(self,x,y,color="",label=""):
self.x=x
self.y=y
self.color=color
self.label=label
def __repr__(self):
return 'DiagramPoint({0},{1},"{2}","{3}")'.format(self.x,self.y,self.color,self.label)
class Base:
highNumbers=True
def __init__(self,start=0):
self.overlays=[]
self._letter="a"
self._index=dict()
self._indexGen=count(start)
curDir=os.path.dirname(__file__)
templateDir=os.path.join(curDir,"..","templ")
self._env=Environment(loader=FileSystemLoader(templateDir))
self._env.trim_blocks=True
self._env.lstrip_blocks=True
def addStone(self,x,y,color):
assert (x,y) not in self._index
self._index[(x,y)]=(next(self._indexGen),DiagramPoint(x,y,color))
def addMove(self,x,y,color,label):
if (not self.highNumbers) and isinstance(label,int) and label%100!=0:
label%=100
if (x,y) not in self._index:
self._index[(x,y)]=(next(self._indexGen),DiagramPoint(x,y,color,label))
else:
(_,point)=self._index[(x,y)]
if not point.label:
point.label=self._letter
self._letter=chr(ord(self._letter)+1)
self.overlays.append((label, point.label))
def addLabel(self,x,y,label):
self._index[(x,y)]=(next(self._indexGen),DiagramPoint(x,y,"",label))
def save(self,filename):
notes=open(filename+".txt", 'w')
notes.write("\n".join("{0} = {1}".format(a,b) for (a,b) in self.overlays))
notes.close()
|