From b15c67c47e4d87e8efc82f6ff25853437d677e1f Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Mon, 4 Jun 2018 22:23:43 +0200 Subject: [PATCH] Pose state moved to Frames --- photobooth/Photobooth.py | 24 +++++------ photobooth/gui/GuiState.py | 17 +++++++- photobooth/gui/PyQt5Gui.py | 75 +++------------------------------ photobooth/gui/Qt5Gui/Frames.py | 71 +++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 83 deletions(-) diff --git a/photobooth/Photobooth.py b/photobooth/Photobooth.py index b297983..edcb96d 100644 --- a/photobooth/Photobooth.py +++ b/photobooth/Photobooth.py @@ -41,10 +41,10 @@ class Photobooth: if (config.getBool('Photobooth', 'show_preview') and self._cap.hasPreview): logging.info('Countdown with preview activated') - self._show_counter = self.showCounterPreview + self._show_counter = self.showCountdownPreview else: logging.info('Countdown without preview activated') - self._show_counter = self.showCounterNoPreview + self._show_counter = self.showCountdownNoPreview def initGpio(self, config): @@ -106,7 +106,7 @@ class Photobooth: raise TeardownException() @property - def showCounter(self): + def showCountdown(self): return self._show_counter @@ -147,7 +147,7 @@ class Photobooth: if self._cap.hasIdle: self._cap.setIdle() - def showCounterPreview(self): + def showCountdownPreview(self): self._conn.send(gui.CountdownState()) @@ -157,28 +157,28 @@ class Photobooth: self.recvAck() - def showCounterNoPreview(self): + def showCountdownNoPreview(self): self._conn.send(gui.CountdownState()) self.recvAck() - def showPose(self): + def showPose(self, num_picture): - self._conn.send(gui.PoseState()) + self._conn.send(gui.PoseState(num_picture)) - def captureSinglePicture(self): + def captureSinglePicture(self, num_picture): - self.showCounter() + self.showCountdown() self.setCameraIdle() - self.showPose() + self.showPose(num_picture) picture = self._cap.getPicture() self.setCameraActive() return picture def capturePictures(self): - return [self.captureSinglePicture() - for _ in range(self._pic_dims.totalNumPictures)] + return [self.captureSinglePicture(i+1) + for i in range(self._pic_dims.totalNumPictures)] def assemblePictures(self, pictures): diff --git a/photobooth/gui/GuiState.py b/photobooth/gui/GuiState.py index 433460f..bf50fa7 100644 --- a/photobooth/gui/GuiState.py +++ b/photobooth/gui/GuiState.py @@ -103,10 +103,25 @@ class GreeterState(GuiState): class PoseState(GuiState): - def __init__(self, **kwargs): + def __init__(self, num_picture, **kwargs): super().__init__(**kwargs) + self.num_picture = num_picture + + @property + def num_picture(self): + + return self._num_picture + + @num_picture.setter + def num_picture(self, num_picture): + + if not isinstance(num_picture, int): + raise ValueError('Picture number must be an integer') + + self._num_picture = num_picture + class AssembleState(GuiState): diff --git a/photobooth/gui/PyQt5Gui.py b/photobooth/gui/PyQt5Gui.py index 53a556c..8015887 100644 --- a/photobooth/gui/PyQt5Gui.py +++ b/photobooth/gui/PyQt5Gui.py @@ -114,7 +114,8 @@ class PyQt5Gui(Gui): elif isinstance(state, GreeterState): global cfg self._p.handleKeypressEvent = self.handleKeypressEventNoTrigger - self._p.setCentralWidget( PyQt5GreeterMessage( + # self._p.setCentralWidget( PyQt5GreeterMessage( + self._p.setCentralWidget( Frames.GreeterMessage( cfg.getInt('Picture', 'num_x'), cfg.getInt('Picture', 'num_y') ) ) QtCore.QTimer.singleShot(cfg.getInt('Photobooth', 'greeter_time') * 1000, self.sendAck) @@ -126,7 +127,9 @@ class PyQt5Gui(Gui): self._p.centralWidget().update() elif isinstance(state, PoseState): - self._p.setCentralWidget(PyQt5PoseMessage()) + # self._p.setCentralWidget(PyQt5PoseMessage()) + self._p.setCentralWidget(Frames.PoseMessage(state.num_picture, + cfg.getInt('Picture', 'num_x'), cfg.getInt('Picture', 'num_y'))) elif isinstance(state, AssembleState): self._p.setCentralWidget(Frames.WaitMessage('Processing picture...')) @@ -312,45 +315,6 @@ class PyQt5MainWindow(QtWidgets.QMainWindow): - -class PyQt5GreeterMessage(QtWidgets.QFrame): - - def __init__(self, num_x, num_y): - - super().__init__() - - self._num_x = num_x - self._num_y = num_y - self._title = 'Get ready!' - self._text = 'We will capture {} pictures!'.format(num_x * num_y) - - self.initFrame() - - - def initFrame(self): - - self.setStyleSheet('background-color: black; color: white;') - - - def paintEvent(self, event): - - painter = QtGui.QPainter(self) - f = self.font() - - f.setPixelSize(self.height() / 5) - painter.setFont(f) - rect = QtCore.QRect(0, self.height() * 1 / 5, self.width(), self.height() * 3 / 10) - painter.drawText(rect, QtCore.Qt.AlignCenter, self._title) - - f.setPixelSize(self.height() / 8) - painter.setFont(f) - rect = QtCore.QRect(0, self.height() * 3 / 5, self.width(), self.height() * 3 / 10) - painter.drawText(rect, QtCore.Qt.AlignCenter, self._text) - - painter.end() - - - class PyQt5CountdownMessage(QtWidgets.QFrame): def __init__(self, time, action): @@ -448,35 +412,6 @@ class PyQt5CountdownMessage(QtWidgets.QFrame): self.update() - -class PyQt5PoseMessage(QtWidgets.QFrame): - - def __init__(self): - - super().__init__() - - self.initFrame() - - - def initFrame(self): - - self.setStyleSheet('background-color: black; color: white;') - - - def paintEvent(self, event): - - painter = QtGui.QPainter(self) - - f = self.font() - f.setPixelSize(self.height() / 3) - painter.setFont(f) - - painter.drawText(event.rect(), QtCore.Qt.AlignCenter, 'Pose!') - - painter.end() - - - class PyQt5PictureMessage(QtWidgets.QFrame): def __init__(self, picture): diff --git a/photobooth/gui/Qt5Gui/Frames.py b/photobooth/gui/Qt5Gui/Frames.py index a41224c..cefcd7f 100644 --- a/photobooth/gui/Qt5Gui/Frames.py +++ b/photobooth/gui/Qt5Gui/Frames.py @@ -64,6 +64,77 @@ class IdleMessage(QtWidgets.QFrame): painter.end() +class GreeterMessage(QtWidgets.QFrame): + + def __init__(self, num_x, num_y): + + super().__init__() + + self._title = 'Get ready!' + if num_x * num_y > 1: + self._text = ('Capturing {} pictures...'.format(num_x * num_y)) + else: + self._text = 'Starting the countdown...' + + def _paintMessage(self, painter): + + f = self.font() + + f.setPixelSize(self.height() / 5) + painter.setFont(f) + rect = QtCore.QRect(0, self.height() * 1 / 5, + self.width(), self.height() * 3 / 10) + painter.drawText(rect, QtCore.Qt.AlignCenter, self._title) + + f.setPixelSize(self.height() / 8) + painter.setFont(f) + rect = QtCore.QRect(0, self.height() * 3 / 5, + self.width(), self.height() * 3 / 10) + painter.drawText(rect, QtCore.Qt.AlignCenter, self._text) + + def paintEvent(self, event): + + painter = QtGui.QPainter(self) + self._paintMessage(painter) + painter.end() + + +class PoseMessage(QtWidgets.QFrame): + + def __init__(self, num_picture, num_x, num_y): + + super().__init__() + + self._title = 'Pose!' + if num_x * num_y > 1: + self._text = 'Picture {} of {}...'.format(num_picture, + num_x * num_y) + else: + self._text = 'Taking a photo...' + + def _paintMessage(self, painter): + + f = self.font() + + f.setPixelSize(self.height() / 5) + painter.setFont(f) + rect = QtCore.QRect(0, self.height() * 1 / 5, + self.width(), self.height() * 3 / 10) + painter.drawText(rect, QtCore.Qt.AlignCenter, self._title) + + f.setPixelSize(self.height() / 8) + painter.setFont(f) + rect = QtCore.QRect(0, self.height() * 3 / 5, + self.width(), self.height() * 3 / 10) + painter.drawText(rect, QtCore.Qt.AlignCenter, self._text) + + def paintEvent(self, event): + + painter = QtGui.QPainter(self) + self._paintMessage(painter) + painter.end() + + class WaitMessage(QtWidgets.QFrame): # With spinning wait clock, inspired by # https://wiki.python.org/moin/PyQt/A%20full%20widget%20waiting%20indicator