def __init__(self, logMessages=False): super(GuiProcess, self).__init__() self.pid = Process.attach("GUI", self) self.messages = PatternMatcher() self.isOpen = True self.logger = Process.logger() self.logMessages = logMessages
class GuiProcess(QObject): def __init__(self, logMessages=False): super(GuiProcess, self).__init__() self.pid = Process.attach("GUI", self) self.messages = PatternMatcher() self.isOpen = True self.logger = Process.logger() self.logMessages = logMessages def __enter__(self): return self def __exit__(self, type, e, traceback): Process.detach() def event(self, ev): """ Handle events sent to the object. """ if ev.type() == MessageReceivedEvent.Type: if self.logMessages: self.logger.info("Received message %s.", repr(ev.m)) try: self.messages.match(ev.m) except Exception: Process.logger().exception("An exception was raised by the process") return True else: return False def put(self, m): """ Add a process message to the message loop's queue. """ QApplication.postEvent(self, MessageReceivedEvent(m)) def get(self): raise Exception("Can't receive messages on the GUI thread. " + "Use the message matching mechanism instead.") def try_get(self): return (False, None) def close(self): pass