Setting up for per-pen settings
This commit is contained in:
parent
9487dda02c
commit
c5e3afbd95
37
HPGLWrap.py
37
HPGLWrap.py
@ -1,12 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
def write_pen_values(values, char):
|
||||
return "!v64" + char + "".join(["{:04d}".format(value) for value in values])
|
||||
|
||||
def pre_content(filename, power=50, speed=50, rate=2500):
|
||||
def pre_content(filename, power, speed, rate, pen_settings):
|
||||
jobName = os.path.basename(filename)[:80]
|
||||
# Start
|
||||
outString = "@PJL JOB NAME={}\r\n".format(jobName)
|
||||
@ -35,13 +36,28 @@ def pre_content(filename, power=50, speed=50, rate=2500):
|
||||
|
||||
# Use same value for all 16 pens
|
||||
# doesn't seem to affect vector settings
|
||||
outString += write_pen_values([speed * 10] * 16, 'V') # Velocity, 1000=100%
|
||||
outString += write_pen_values([power * 10] * 16, 'P') # Power, 1000=100%
|
||||
outString += write_pen_values([rate] * 16, 'I') # PPI
|
||||
# TODO: try unsetting values in HPGL and see if these take over
|
||||
outString += write_pen_values(pen_settings['power'], 'P') # Power, 1000=100%
|
||||
outString += write_pen_values(pen_settings['speed'], 'V') # Velocity, 1000=100%
|
||||
outString += write_pen_values(pen_settings['rate'], 'I') # PPI, does affect vector
|
||||
|
||||
# Enter HPGL vector mode
|
||||
outString += "%1B"
|
||||
|
||||
return outString
|
||||
|
||||
def set_vector_pens(content, pen_settings):
|
||||
settings = "".join(
|
||||
["FS{power:d},{penNum:d};VS{speed:d},{penNum:d};".format(
|
||||
power=pen_settings['power'][num],
|
||||
speed=pen_settings['speed'][num],
|
||||
penNum=num+1) for num in range(0, 16)])
|
||||
content = re.sub(
|
||||
"FS\d{1,4};VS\d{1,4};SP1;",
|
||||
settings + "SP1;",
|
||||
content, count=1)
|
||||
return content
|
||||
|
||||
def post_content():
|
||||
outString = "%1A" # Leave HPGL vector mode
|
||||
outString += "E" # Reset
|
||||
@ -49,11 +65,16 @@ def post_content():
|
||||
return outString
|
||||
|
||||
def main(infile, outfile, power=50, speed=50, rate=100):
|
||||
with open(infile, 'r') as f:
|
||||
data = f.read()
|
||||
# set all pens the same
|
||||
pen_settings = {'power': [int(power) * 10] * 16,
|
||||
'speed': [int(speed) * 10] * 16,
|
||||
'rate': [int(rate)] * 16}
|
||||
|
||||
with open(outfile, 'w') as f:
|
||||
f.write(pre_content(outfile, int(power), int(speed), int(rate)))
|
||||
f.write(data)
|
||||
f.write(pre_content(
|
||||
outfile, int(power), int(speed), int(rate), pen_settings))
|
||||
with open(infile, 'r') as input_f:
|
||||
f.write(set_vector_pens(input_f.read(), pen_settings))
|
||||
f.write(post_content())
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user