# Path: guild/qtactor.py
# class ActorSignal(QtActorMixin, QtCore.QObject):
#     signal = QtCore.pyqtSignal(object)
# 
#     @actor_method
#     def input(self, msg):
#         self.signal.emit(msg)
# 
# class QtActorMixin(ActorMixin):
#     # create unique event types
#     _qtactor_queue_event = QtCore.QEvent.registerEventType()
#     _qtactor_step_event  = QtCore.QEvent.registerEventType()
#     _qtactor_stop_event  = QtCore.QEvent.registerEventType()
# 
#     def __init__(self, *argv, **argd):
#         super(QtActorMixin, self).__init__(*argv, **argd)
#         self._qtactor_dispatch = {
#             self._qtactor_queue_event : self._actor_do_queued,
#             self._qtactor_step_event  : self._qtactor_step,
#             self._qtactor_stop_event  : self._qtactor_stop,
#             }
#         self._qtactor_gen = None
#         # if not a Widget, move to a Qt thread
#         if isinstance(self, QtGui.QWidget):
#             # widgets can't be moved to another thread
#             self._qtactor_thread = None
#         else:
#             # create a thread and move to it
#             self._qtactor_thread = QtCore.QThread()
#             self.moveToThread(self._qtactor_thread)
#             self._qtactor_thread.started.connect(self._qtactor_run)
# 
#     def start(self):
#         if self._qtactor_thread:
#             self._qtactor_thread.start()
#         else:
#             self._qtactor_run()
# 
#     def _qtactor_run(self):
#         self.process_start()
#         self.process()
#         # get gen_process generator
#         try:
#             self._qtactor_gen = self.gen_process()
#         except AttributeError:
#             self._qtactor_gen = None
#         # do first step
#         if self._qtactor_gen:
#             self._qtactor_step()
# 
#     def _qtactor_step(self):
#         try:
#             self._qtactor_gen.next()
#         except StopIteration:
#             self._qtactor_gen = None
#             return
#         # trigger next step
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_step_event),
#             QtCore.Qt.LowEventPriority)
# 
#     def _qtactor_stop(self):
#         self._qtactor_dispatch = {}
#         if self._qtactor_gen:
#             self._qtactor_gen.close()
#         self.onStop()
#         if self._qtactor_thread:
#             self._qtactor_thread.quit()
# 
#     def _actor_notify(self):
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_queue_event),
#             QtCore.Qt.LowEventPriority)
# 
#     def event(self, event):
#         event_type = event.type()
#         if event_type in self._qtactor_dispatch:
#             event.accept()
#             self._qtactor_dispatch[event_type]()
#             return True
#         return super(QtActorMixin, self).event(event)
# 
#     def stop(self):
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_stop_event),
#             QtCore.Qt.HighEventPriority)
# 
#     def join(self):
#         if self._qtactor_thread:
#             self._qtactor_thread.wait()


import re
import subprocess
import sys
import time
from guild.actor import *
from guild.qtactor import ActorSignal, QtActorMixin
from PyQt4 import QtGui, QtCore

    def gen_process(self):
        self.reader = VideoFileReader(self.video_file)
        raw_image = None
        while True:
            yield 1
            if not (self.paused and raw_image):
                try:
                    xlen, ylen, raw_image = next(self.reader)
                except StopIteration:
                    break
            image = QtGui.QImage(
                raw_image, xlen, ylen, QtGui.QImage.Format_RGB888)
            self.signal.emit(image)
            time.sleep(1.0/25)

    @actor_method
    @QtCore.pyqtSlot(bool)
    def set_paused(self, paused):
        self.paused = paused

    def onStop(self):
        self.reader.close()

class Display(QtGui.QLabel):
    @QtCore.pyqtSlot(QtGui.QImage)
    def show_frame(self, frame):
        pixmap = QtGui.QPixmap.fromImage(frame)
        self.setPixmap(pixmap)


# Path: guild/qtactor.py
# class ActorSignal(QtActorMixin, QtCore.QObject):
#     signal = QtCore.pyqtSignal(object)
# 
#     @actor_method
#     def input(self, msg):
#         self.signal.emit(msg)
# 
# class QtActorMixin(ActorMixin):
#     # create unique event types
#     _qtactor_queue_event = QtCore.QEvent.registerEventType()
#     _qtactor_step_event  = QtCore.QEvent.registerEventType()
#     _qtactor_stop_event  = QtCore.QEvent.registerEventType()
# 
#     def __init__(self, *argv, **argd):
#         super(QtActorMixin, self).__init__(*argv, **argd)
#         self._qtactor_dispatch = {
#             self._qtactor_queue_event : self._actor_do_queued,
#             self._qtactor_step_event  : self._qtactor_step,
#             self._qtactor_stop_event  : self._qtactor_stop,
#             }
#         self._qtactor_gen = None
#         # if not a Widget, move to a Qt thread
#         if isinstance(self, QtGui.QWidget):
#             # widgets can't be moved to another thread
#             self._qtactor_thread = None
#         else:
#             # create a thread and move to it
#             self._qtactor_thread = QtCore.QThread()
#             self.moveToThread(self._qtactor_thread)
#             self._qtactor_thread.started.connect(self._qtactor_run)
# 
#     def start(self):
#         if self._qtactor_thread:
#             self._qtactor_thread.start()
#         else:
#             self._qtactor_run()
# 
#     def _qtactor_run(self):
#         self.process_start()
#         self.process()
#         # get gen_process generator
#         try:
#             self._qtactor_gen = self.gen_process()
#         except AttributeError:
#             self._qtactor_gen = None
#         # do first step
#         if self._qtactor_gen:
#             self._qtactor_step()
# 
#     def _qtactor_step(self):
#         try:
#             self._qtactor_gen.next()
#         except StopIteration:
#             self._qtactor_gen = None
#             return
#         # trigger next step
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_step_event),
#             QtCore.Qt.LowEventPriority)
# 
#     def _qtactor_stop(self):
#         self._qtactor_dispatch = {}
#         if self._qtactor_gen:
#             self._qtactor_gen.close()
#         self.onStop()
#         if self._qtactor_thread:
#             self._qtactor_thread.quit()
# 
#     def _actor_notify(self):
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_queue_event),
#             QtCore.Qt.LowEventPriority)
# 
#     def event(self, event):
#         event_type = event.type()
#         if event_type in self._qtactor_dispatch:
#             event.accept()
#             self._qtactor_dispatch[event_type]()
#             return True
#         return super(QtActorMixin, self).event(event)
# 
#     def stop(self):
#         QtCore.QCoreApplication.postEvent(
#             self, QtCore.QEvent(self._qtactor_stop_event),
#             QtCore.Qt.HighEventPriority)
# 
#     def join(self):
#         if self._qtactor_thread:
#             self._qtactor_thread.wait()


# Path: examples/qt_video_player.py
import re
import subprocess
import sys
import time
from guild.actor import *
from guild.qtactor import ActorSignal, QtActorMixin
from PyQt4 import QtGui, QtCore


    def gen_process(self):
        self.reader = VideoFileReader(self.video_file)
        raw_image = None
        while True:
            yield 1
            if not (self.paused and raw_image):
                try:
                    xlen, ylen, raw_image = next(self.reader)
                except StopIteration:
                    break
            image = QtGui.QImage(
                raw_image, xlen, ylen, QtGui.QImage.Format_RGB888)
            self.signal.emit(image)
            time.sleep(1.0/25)

    @actor_method
    @QtCore.pyqtSlot(bool)
    def set_paused(self, paused):
        self.paused = paused

    def onStop(self):
        self.reader.close()

class Display(QtGui.QLabel):
    @QtCore.pyqtSlot(QtGui.QImage)
    def show_frame(self, frame):
        pixmap = QtGui.QPixmap.fromImage(frame)
        self.setPixmap(pixmap)


class DisplayActor(QtActorMixin, QtGui.QLabel):