diff --git a/photobooth/Photobooth.py b/photobooth/Photobooth.py index a6e51d5..f2d4f5c 100644 --- a/photobooth/Photobooth.py +++ b/photobooth/Photobooth.py @@ -108,11 +108,12 @@ class Photobooth: def run(self, send, recv): self._send = send + self._recv = recv self.initRun() while True: try: - event = recv.recv() + event = self._recv.recv() if str(event) == 'start': print('Camera already started') @@ -129,7 +130,7 @@ class Photobooth: except RuntimeError as e: print('Camera error: ' + str(e)) self._send.send( gui.ErrorState('Camera error', str(e)) ) - event = recv.recv() + event = self._recv.recv() if str(event) == 'cancel': self.teardown() return 1 @@ -207,7 +208,15 @@ class Photobooth: self.triggerOff() self.setCameraActive() - sleep(self.greeterTime) + event = self._recv.recv() + if str(event) == 'cancel': + self.teardown() + return 1 + elif str(event) == 'ack': + pass + else: + print('Unknown event received: ' + str(event)) + raise RuntimeError('Unknown event received', str(event)) pics = self.capturePictures() self._send.send(gui.AssembleState()) diff --git a/photobooth/gui/PyQt5Gui.py b/photobooth/gui/PyQt5Gui.py index 9548f25..c33f6dd 100644 --- a/photobooth/gui/PyQt5Gui.py +++ b/photobooth/gui/PyQt5Gui.py @@ -3,10 +3,14 @@ from PIL import ImageQt -from PyQt5.QtCore import Qt, QObject, QPoint, QThread, pyqtSignal +from PyQt5.QtCore import Qt, QObject, QPoint, QThread, QTimer, pyqtSignal from PyQt5.QtWidgets import (QApplication, QCheckBox, QComboBox, QFormLayout, QFrame, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QLayout, QLineEdit, QMainWindow, QMessageBox, QPushButton, QVBoxLayout) from PyQt5.QtGui import QImage, QPainter, QPixmap +import math +from PyQt5.QtGui import QBrush, QPen, QColor +from PyQt5.QtCore import QRect + from . import * from .. import camera, printer @@ -78,17 +82,20 @@ class PyQt5Gui(Gui): elif isinstance(state, GreeterState): global cfg self._p.handleKeypressEvent = self.handleKeypressEventNoTrigger - num_pictures = ( cfg.getInt('Picture', 'num_x') * + num_pictures = ( + cfg.getInt('Picture', 'num_x') * cfg.getInt('Picture', 'num_y') ) self._p.setCentralWidget( PyQt5PictureMessage('Will capture {} pictures!'.format(num_pictures))) + QTimer.singleShot(cfg.getInt('Photobooth', 'greeter_time') * 1000, lambda : self._transport.send('ack')) + elif isinstance(state, PreviewState): img = ImageQt.ImageQt(state.picture) self._p.setCentralWidget(PyQt5PictureMessage(state.message, img)) elif isinstance(state, PoseState): self._p.setCentralWidget(PyQt5PictureMessage('Pose!')) elif isinstance(state, AssembleState): - self._p.setCentralWidget(PyQt5PictureMessage('Please wait!\nAssembling picture...')) + self._p.setCentralWidget(PyQt5WaitMessage('Processing picture...')) elif isinstance(state, PictureState): img = ImageQt.ImageQt(state.picture) self._p.setCentralWidget(PyQt5PictureMessage('', img)) @@ -118,7 +125,7 @@ class PyQt5Gui(Gui): self._lastState = self.showStartPhotobooth self._transport.send('start') - self._p.setCentralWidget(PyQt5PictureMessage('Starting the photobooth...')) + self._p.setCentralWidget(PyQt5WaitMessage('Starting the photobooth...')) def showIdle(self): @@ -535,6 +542,67 @@ class PyQt5Settings(QFrame): +class PyQt5WaitMessage(QFrame): + # With spinning wait clock, inspired by + # https://wiki.python.org/moin/PyQt/A%20full%20widget%20waiting%20indicator + + def __init__(self, message): + + super().__init__() + + self._message = message + + self.initFrame() + + + def initFrame(self): + + self.setStyleSheet('background-color: white;') + + + def paintEvent(self, event): + + painter = QPainter(self) + + rect = QRect(0, self.height() * 3 / 5, self.width(), self.height() * 3 / 10) + painter.drawText(rect, Qt.AlignCenter, self._message) + + painter.setRenderHint(QPainter.Antialiasing) + painter.setPen(QPen(Qt.NoPen)) + + center = (self.width() / 2, self.height() / 2) + + dots = 8 + pos = self._counter % dots + + for i in range(dots): + + distance = (pos - i) % dots + color = (distance + 1) / (dots + 1) * 255 + painter.setBrush(QBrush(QColor(color, color, color))) + + painter.drawEllipse( + center[0] + 180 / dots * math.cos(2 * math.pi * i / dots) - 20, + center[1] + 180 / dots * math.sin(2 * math.pi * i / dots) - 20, + 15, 15) + + painter.end() + + + def showEvent(self, event): + + self._counter = 0 + self.startTimer(100) + + + + def timerEvent(self, event): + + self._counter += 1 + self.update() + + + class PyQt5PictureMessage(QFrame): def __init__(self, message, picture=None):