refactor to add mock plotter
added CLI for plot to svg set appropriate doc size for svg
This commit is contained in:
parent
49db82f099
commit
e5c84a0ae9
|
@ -9,12 +9,27 @@ def plot_to_svg(instream, outstream):
|
|||
p.read(instream)
|
||||
p.write(outstream)
|
||||
|
||||
class Apple410:
|
||||
"""A simple class for queing up commands for the Apple 410"""
|
||||
def __init__(self, portname, baud=9600, flow_control_safe=False, cts_hack=False):
|
||||
self.serial = serial.Serial(portname, baud, rtscts=False, dsrdtr=True, timeout=0.1)
|
||||
class Apple410Common:
|
||||
def __init__(self):
|
||||
self.pos = (0,0)
|
||||
self.wd = self.vp = (0,0,2394,1759)
|
||||
|
||||
def move_to(self, coords):
|
||||
self.send('MA{},{}'.format(coords[0],coords[1]))
|
||||
self.pos = coords
|
||||
|
||||
def draw_to(self, coords):
|
||||
self.send('DA{:.2f},{:.2f}'.format(coords[0],coords[1]))
|
||||
self.pos = coords
|
||||
|
||||
def pen_select(self, index):
|
||||
self.send('PS{}'.format(index))
|
||||
|
||||
class Apple410(Apple410Common):
|
||||
"""A simple class for queing up commands for the Apple 410"""
|
||||
def __init__(self, portname, baud=9600, flow_control_safe=False, cts_hack=False):
|
||||
Apple410Common.__init__(self)
|
||||
self.serial = serial.Serial(portname, baud, rtscts=False, dsrdtr=True, timeout=0.1)
|
||||
self.flow_control_safe = flow_control_safe
|
||||
self.cts_hack = cts_hack
|
||||
|
||||
|
@ -39,14 +54,21 @@ class Apple410:
|
|||
self.sendchar(c)
|
||||
self.sendchar('\x03')
|
||||
|
||||
def move_to(self, coords):
|
||||
self.send('MA{},{}'.format(coords[0],coords[1]))
|
||||
self.pos = coords
|
||||
def close(self):
|
||||
self.serial.close()
|
||||
|
||||
class MockApple410(Apple410Common):
|
||||
def __init__(self, path):
|
||||
Apple410Common.__init__(self)
|
||||
if type(path) == type(''):
|
||||
self.f = open(path,'w')
|
||||
else:
|
||||
self.f = path
|
||||
|
||||
def send(self, command):
|
||||
self.f.write(command)
|
||||
self.f.write('\n')
|
||||
|
||||
def close(self):
|
||||
self.f.close()
|
||||
|
||||
def draw_to(self, coords):
|
||||
self.send('DA{:.2f},{:.2f}'.format(coords[0],coords[1]))
|
||||
self.pos = coords
|
||||
|
||||
def pen_select(self, index):
|
||||
self.send('PS{}'.format(index))
|
||||
|
||||
|
|
|
@ -47,3 +47,18 @@ def svg2plot():
|
|||
f = open(args.SVG)
|
||||
plot_svg(f,center=args.center)
|
||||
|
||||
from .plot_to_svg import Plotter
|
||||
|
||||
def plot2svg():
|
||||
parser = argparse.ArgumentParser("plot2svg",
|
||||
description="Convert a set of Apple 410 Color Plotter commands to an SVG")
|
||||
parser.add_argument('PLOT', help='The plotter file to process. "-" will read plotter commands from standard input.')
|
||||
args = parser.parse_args()
|
||||
if args.PLOT == '-':
|
||||
f = sys.stdin
|
||||
else:
|
||||
f = open(args.PLOT)
|
||||
p = Plotter()
|
||||
p.read(f)
|
||||
p.write(sys.stdout)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class Plotter:
|
|||
self.window = (0, 0, W, H)
|
||||
self.cur_g = None
|
||||
self.cur_d = None
|
||||
self.d = svgwrite.Drawing(profile='tiny')
|
||||
self.d = svgwrite.Drawing(profile='tiny',size=(W,H))
|
||||
self.text_theta = 0
|
||||
self.text_size = 1
|
||||
self.pos = (0,0)
|
||||
|
@ -161,7 +161,7 @@ class Plotter:
|
|||
def read(self,inf):
|
||||
for line in inf.readlines():
|
||||
line = line.strip()
|
||||
p.process_cmd(line)
|
||||
self.process_cmd(line)
|
||||
|
||||
if __name__=='__main__':
|
||||
p = Plotter()
|
||||
|
|
Loading…
Reference in New Issue