diff --git a/photobooth/defaults.cfg b/photobooth/defaults.cfg index db8977e..ee311cb 100644 --- a/photobooth/defaults.cfg +++ b/photobooth/defaults.cfg @@ -30,6 +30,8 @@ lamp_pin = 4 [Printer] # Enable printing (True/False) enable = True +# Print to PDF (True/False) for debugging purposes +pdf = False # Printer module to use (PyQt5) module = PyQt5 # Paper width in mm diff --git a/photobooth/gui/GuiPostprocessor.py b/photobooth/gui/GuiPostprocessor.py index e9695c9..2eb7fea 100644 --- a/photobooth/gui/GuiPostprocessor.py +++ b/photobooth/gui/GuiPostprocessor.py @@ -33,7 +33,8 @@ class GuiPostprocessor: module = config.get('Printer', 'module') paper_size = (config.getInt('Printer', 'width'), config.getInt('Printer', 'height')) - self._task_list.append(PrintPostprocess(module, paper_size)) + pdf = config.getBool('Printer', 'pdf') + self._task_list.append(PrintPostprocess(module, paper_size, pdf)) def get(self, picture): @@ -89,12 +90,12 @@ class PostprocessItem: class PrintPostprocess(PostprocessTask): - def __init__(self, printer_module, paper_size, **kwargs): + def __init__(self, printer_module, paper_size, is_pdf, **kwargs): super().__init__(**kwargs) Printer = lookup_and_import(printer.modules, printer_module, 'printer') - self._printer = Printer(paper_size, True) + self._printer = Printer(paper_size, is_pdf) def get(self, picture): diff --git a/photobooth/gui/Qt5Gui/Frames.py b/photobooth/gui/Qt5Gui/Frames.py index ac74482..42321c0 100644 --- a/photobooth/gui/Qt5Gui/Frames.py +++ b/photobooth/gui/Qt5Gui/Frames.py @@ -734,6 +734,10 @@ class Settings(QtWidgets.QFrame): enable.setChecked(self._cfg.getBool('Printer', 'enable')) self.add('Printer', 'enable', enable) + pdf = QtWidgets.QCheckBox() + pdf.setChecked(self._cfg.getBool('Printer', 'pdf')) + self.add('Printer', 'pdf', pdf) + module = self.createModuleComboBox(printer.modules, self._cfg.get('Printer', 'module')) self.add('Printer', 'module', module) @@ -755,6 +759,7 @@ class Settings(QtWidgets.QFrame): layout = QtWidgets.QFormLayout() layout.addRow('Enable printing:', enable) layout.addRow('Module:', module) + layout.addRow('Print to PDF (for debugging):', pdf) layout.addRow('Paper size [mm]:', lay_size) widget = QtWidgets.QWidget() @@ -813,6 +818,8 @@ class Settings(QtWidgets.QFrame): self._cfg.set('Printer', 'enable', str(self.get('Printer', 'enable').isChecked())) + self._cfg.set('Printer', 'pdf', + str(self.get('Printer', 'pdf').isChecked())) self._cfg.set('Printer', 'module', printer.modules[self.get('Printer', 'module').currentIndex()][0]) diff --git a/photobooth/printer/PrinterPyQt5.py b/photobooth/printer/PrinterPyQt5.py index 02eedde..203665a 100644 --- a/photobooth/printer/PrinterPyQt5.py +++ b/photobooth/printer/PrinterPyQt5.py @@ -19,8 +19,6 @@ import logging -from PIL import ImageQt - from PyQt5 import QtCore, QtGui from PyQt5.QtPrintSupport import QPrinter @@ -55,15 +53,14 @@ class PrinterPyQt5(Printer): logging.info('Printing picture') - img = ImageQt.ImageQt(picture) - img = img.scaled(self._printer.pageRect().size(), - QtCore.Qt.KeepAspectRatio, - QtCore.Qt.SmoothTransformation) + picture = picture.scaled(self._printer.pageRect().size(), + QtCore.Qt.KeepAspectRatio, + QtCore.Qt.SmoothTransformation) printable_size = self._printer.pageRect(QPrinter.DevicePixel) - origin = ((printable_size.width() - img.width()) // 2, - (printable_size.height() - img.height()) // 2) + origin = ((printable_size.width() - picture.width()) // 2, + (printable_size.height() - picture.height()) // 2) painter = QtGui.QPainter(self._printer) - painter.drawImage(QtCore.QPoint(*origin), img) + painter.drawImage(QtCore.QPoint(*origin), picture) painter.end()