Files
photobooth/photobooth/gui/Qt5Gui/Receiver.py
2018-06-15 22:20:33 +02:00

48 lines
1.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Photobooth - a flexible photo booth software
# Copyright (C) 2018 Balthasar Reuter <photobooth at re - web dot eu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import multiprocessing as mp
from PyQt5 import QtCore
class Receiver(QtCore.QThread):
notify = QtCore.pyqtSignal(object)
def __init__(self, conn):
super().__init__()
self._conn = conn
def handle(self, state):
self.notify.emit(state)
def run(self):
while self._conn:
for c in mp.connection.wait(self._conn):
try:
state = c.recv()
except EOFError:
break
else:
self.handle(state)