- added ability to save the Source File as PDF (still have to adjust the page size)

This commit is contained in:
Marius Stanciu 2019-12-17 03:42:24 +02:00 committed by Marius
parent 4ac5f8e239
commit 2565dd75f1
3 changed files with 40 additions and 6 deletions

View File

@ -9975,11 +9975,11 @@ class App(QtCore.QObject):
flt = "All Files (*.*)"
if obj.kind == 'gerber':
flt = "Gerber Files (*.GBR);;All Files (*.*)"
flt = "Gerber Files (*.GBR);;PDF Files (*.PDF);;All Files (*.*)"
elif obj.kind == 'excellon':
flt = "Excellon Files (*.DRL);;All Files (*.*)"
flt = "Excellon Files (*.DRL);;PDF Files (*.PDF);;All Files (*.*)"
elif obj.kind == 'cncjob':
"GCode Files (*.NC);;All Files (*.*)"
flt = "GCode Files (*.NC);;PDF Files (*.PDF);;All Files (*.*)"
self.source_editor_tab = TextEditor(app=self, plain_text=True)

View File

@ -16,6 +16,7 @@ CAD program, and create G-Code for Isolation routing.
- maximum range for Cut Z is now zero to deal with the situation when using V-shape with tip-dia same value with cut width
- modified QValidator in FCDoubleSpinner() GUI element to allow entering the minus sign when the range maximum is set as 0.0; also for positive numbers allowed entering the symbol plus
- made sure that if in Gerber UI the isolation is made with a V-Shape tool then the tool type is automatically updated on the generated Geometry Object
- added ability to save the Source File as PDF (still have to adjust the page size)
16.12.2019

View File

@ -217,9 +217,42 @@ class TextEditor(QtWidgets.QWidget):
else:
try:
my_gcode = self.code_editor.toPlainText()
with open(filename, 'w') as f:
for line in my_gcode:
f.write(line)
if filename.rpartition('.')[2].lower() == 'pdf':
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
if self.app.defaults['units'].upper() == 'MM':
dims = self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']]
else:
dims = (
self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][0] / 25.4,
self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][1] / 25.4
)
styles = getSampleStyleSheet()
styleN = styles['Normal']
styleH = styles['Heading1']
story = []
doc = SimpleDocTemplate(
filename,
pagesize=dims,
bottomMargin=0.4 * 72,
topMargin=0.6 * 72,
rightMargin=0.8 * 72,
leftMargin=0.8 * 72)
P = Paragraph(my_gcode, styleN)
story.append(P)
doc.build(
story,
)
else:
with open(filename, 'w') as f:
for line in my_gcode:
f.write(line)
except FileNotFoundError:
self.app.inform.emit('[WARNING] %s' % _("No such file or directory"))
return