Logging added

This commit is contained in:
Balthasar Reuter
2018-05-14 21:13:56 +02:00
parent e341fbc052
commit 5e2739bec8
13 changed files with 122 additions and 75 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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()