Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] make number of prints configurable #188

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion photobooth/defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hide_cursor = False
style = default

[Camera]
# Camera module to use (python-gphoto2, gphoto2-cffi, gphoto2-commandline,
# Camera module to use (python-gphoto2, gphoto2-cffi, gphoto2-commandline,
# opencv, picamera, dummy)
module = python-gphoto2
# Specify rotation of camera in degree (possible values: 0, 90, 180, 270)
Expand Down Expand Up @@ -48,6 +48,8 @@ module = PyQt5
width = 148
# Paper height in mm
height = 100
# Number of prints from one image
num_prints = 1

[Photobooth]
# Show preview while posing time (True/False)
Expand Down
7 changes: 4 additions & 3 deletions photobooth/gui/GuiPostprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def __init__(self, config):
paper_size = (config.getInt('Printer', 'width'),
config.getInt('Printer', 'height'))
pdf = config.getBool('Printer', 'pdf')
num_prints = config.getInt('Printer', 'num_prints')
if config.getBool('Printer', 'confirmation'):
self._get_task_list.append(
PrintPostprocess(module, paper_size, pdf))
PrintPostprocess(module, paper_size, num_prints, pdf))
else:
self._do_task_list.append(
PrintPostprocess(module, paper_size, pdf))
PrintPostprocess(module, paper_size, num_prints, pdf))

def get(self, picture):

Expand Down Expand Up @@ -100,7 +101,7 @@ def action(self, action):

class PrintPostprocess(PostprocessTask):

def __init__(self, printer_module, paper_size, is_pdf, **kwargs):
def __init__(self, printer_module, paper_size, is_pdf, num_prints, **kwargs):

super().__init__(**kwargs)

Expand Down
8 changes: 8 additions & 0 deletions photobooth/gui/Qt5Gui/Frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,18 @@ def createPrinterSettings(self):
lay_size.addWidget(QtWidgets.QLabel('x'))
lay_size.addWidget(height)

num_prints = QtWidgets.QSpinBox()
num_prints.setRange(1, 99)
num_prints.setValue(self._cfg.getInt('Printer', 'num_prints'))
self.add('Printer', 'num_prints', num_prints)

layout = QtWidgets.QFormLayout()
layout.addRow(_('Enable printing:'), enable)
layout.addRow(_('Module:'), module)
layout.addRow(_('Print to PDF (for debugging):'), pdf)
layout.addRow(_('Ask for confirmation before printing:'), confirmation)
layout.addRow(_('Paper size [mm]:'), lay_size)
layout.addRow(_('Number of prints from one image:'), num_prints)

widget = QtWidgets.QWidget()
widget.setLayout(layout)
Expand Down Expand Up @@ -1048,6 +1054,8 @@ def storeConfigAndRestart(self):
self._cfg.set('Printer', 'width', self.get('Printer', 'width').text())
self._cfg.set('Printer', 'height',
self.get('Printer', 'height').text())
self._cfg.set('Printer', 'num_prints',
self.get('Printer', 'num_prints').text())

self._cfg.set('Mailer', 'enable',
str(self.get('Mailer', 'enable').isChecked()))
Expand Down
20 changes: 12 additions & 8 deletions photobooth/printer/PrinterPyCups.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

class PrinterPyCups(Printer):

def __init__(self, page_size, print_pdf=False):
def __init__(self, page_size, num_prints, print_pdf=False):

self.num_prints = num_prints

self._conn = cups.Connection() if cups else None

Expand All @@ -57,10 +59,12 @@ def __init__(self, page_size, print_pdf=False):

def print(self, picture):

if self._conn is not None:
if isinstance(picture, ImageQt.ImageQt):
picture.save(self._tmp_filename)
else:
picture.save(self._tmp_filename, format='JPEG')
self._conn.printFile(self._printer, self._tmp_filename,
"photobooth", {})
for n in range(num_prints):
logging.info('Printing picture, {} of {}'.format(n + 1, self.num_prints))
if self._conn is not None:
if isinstance(picture, ImageQt.ImageQt):
picture.save(self._tmp_filename)
else:
picture.save(self._tmp_filename, format='JPEG')
self._conn.printFile(self._printer, self._tmp_filename,
"photobooth", {})
27 changes: 15 additions & 12 deletions photobooth/printer/PrinterPyQt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@

class PrinterPyQt5(Printer):

def __init__(self, page_size, print_pdf=False):
def __init__(self, page_size, num_prints, print_pdf=False):

super().__init__(page_size)
super().__init__(page_size, num_prints)

self.num_prints = num_prints

self._printer = QPrinter(QPrinter.HighResolution)
self._printer.setFullPage(True)
Expand All @@ -47,15 +49,16 @@ def __init__(self, page_size, print_pdf=False):

def print(self, picture):

if self._print_pdf:
self._printer.setOutputFileName('print_%d.pdf' % self._counter)
self._counter += 1
for n in range(self.num_prints):
if self._print_pdf:
self._printer.setOutputFileName('print_%d.pdf' % self._counter)
self._counter += 1

logging.info('Printing picture')
logging.debug('Page Size: {}, Print Size: {}, PictureSize: {} '.format(
self._printer.paperRect(), self._printer.pageRect(),
picture.rect()))
logging.info('Printing picture, {} of {}'.format(n + 1, self.num_prints))
logging.debug('Page Size: {}, Print Size: {}, PictureSize: {} '.format(
self._printer.paperRect(), self._printer.pageRect(),
picture.rect()))

painter = QtGui.QPainter(self._printer)
painter.drawImage(self._printer.pageRect(), picture, picture.rect())
painter.end()
painter = QtGui.QPainter(self._printer)
painter.drawImage(self._printer.pageRect(), picture, picture.rect())
painter.end()
3 changes: 2 additions & 1 deletion photobooth/printer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

class Printer:

def __init__(self, page_size):
def __init__(self, page_size, num_prints):

self.pageSize = page_size
self.num_prints = num_prints

@property
def pageSize(self):
Expand Down