Logging added
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
from .. import printer
|
||||
@@ -19,6 +21,11 @@ class GuiPostprocess:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def confirm(self, picture):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
|
||||
|
||||
class PrintPostprocess(GuiPostprocess):
|
||||
@@ -33,17 +40,15 @@ class PrintPostprocess(GuiPostprocess):
|
||||
|
||||
def get(self, picture):
|
||||
|
||||
return PrintState(lambda : self.do(picture))
|
||||
return PrintState(lambda : self.do(picture), False)
|
||||
|
||||
# reply = QMessageBox.question(parent, 'Print?',
|
||||
# 'Do you want to print the picture?',
|
||||
# QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
|
||||
# if reply == QMessageBox.Yes:
|
||||
# self._printer.print(picture)
|
||||
def confirm(self, picture):
|
||||
|
||||
return PrintState(lambda : None, True)
|
||||
|
||||
|
||||
def do(self, picture):
|
||||
|
||||
print('Printing')
|
||||
logging.info('Printing picture')
|
||||
self._printer.print(picture)
|
||||
|
||||
@@ -147,11 +147,12 @@ class TeardownState(GuiState):
|
||||
|
||||
class PrintState(GuiState):
|
||||
|
||||
def __init__(self, handler, **kwargs):
|
||||
def __init__(self, handler, confirmed, **kwargs):
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.handler = handler
|
||||
self.confirmed = confirmed
|
||||
|
||||
|
||||
@property
|
||||
@@ -166,4 +167,19 @@ class PrintState(GuiState):
|
||||
if not callable(handler):
|
||||
raise ValueError('handler must be callable')
|
||||
|
||||
self._handler = handler
|
||||
self._handler = handler
|
||||
|
||||
|
||||
@property
|
||||
def confirmed(self):
|
||||
|
||||
return self._confirmed
|
||||
|
||||
@confirmed.setter
|
||||
def confirmed(self, confirmed):
|
||||
|
||||
if not isinstance(confirmed, bool):
|
||||
raise ValueError('confirmed status must be bool')
|
||||
|
||||
self._confirmed = confirmed
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import multiprocessing as mp
|
||||
import queue
|
||||
import logging
|
||||
|
||||
from PIL import ImageQt
|
||||
|
||||
@@ -141,7 +142,6 @@ class PyQt5Gui(Gui):
|
||||
elif isinstance(state, PictureState):
|
||||
img = ImageQt.ImageQt(state.picture)
|
||||
self._p.setCentralWidget(PyQt5PictureMessage('', img))
|
||||
# QTimer.singleShot(cfg.getInt('Photobooth', 'display_time') * 1000, self.sendAck)
|
||||
QTimer.singleShot(cfg.getInt('Photobooth', 'display_time') * 1000,
|
||||
lambda : self.postprocessPicture(state.picture))
|
||||
|
||||
@@ -179,6 +179,8 @@ class PyQt5Gui(Gui):
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
task.handler()
|
||||
QMessageBox.information(self._p, 'Printing',
|
||||
'Picture sent to printer.', QMessageBox.Ok)
|
||||
else:
|
||||
raise ValueError('Unknown task')
|
||||
|
||||
@@ -217,9 +219,9 @@ class PyQt5Gui(Gui):
|
||||
|
||||
def showError(self, title, message):
|
||||
|
||||
print('ERROR: ' + title + ': ' + message)
|
||||
reply = QMessageBox.warning(self._p, title, message, QMessageBox.Close | QMessageBox.Retry,
|
||||
QMessageBox.Retry)
|
||||
logging.error('%s: %s', title, message)
|
||||
reply = QMessageBox.warning(self._p, title, message,
|
||||
QMessageBox.Close | QMessageBox.Retry, QMessageBox.Retry)
|
||||
if reply == QMessageBox.Retry:
|
||||
self.sendAck()
|
||||
self._lastState()
|
||||
|
||||
Reference in New Issue
Block a user