def _event(self, E): _log.debug('event1 %s', E) # called on PVA worker thread if isinstance(E, Cancelled): return QCoreApplication.postEvent(self, CBEvent(E))
def invoke_in_main_thread(fn, *args, force_event=False, **kwargs): """ Invoke a callable in the main thread. Use this for making callbacks to the gui where signals are inconvenient. """ # co_name = sys._getframe().f_back.f_code.co_name # msg.logMessage(f"Invoking {fn} in main thread from {co_name}") if not force_event and is_main_thread(): # we're already in the main thread; just do it! fn(*args, **kwargs) else: QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
def _add(self, slot, limitHz=10.0): holdoff = int(max(0.1, 1.0 / limitHz) * 1000) # Rate limiting for multiple consumers is hard. # We throttle to the highest consumer rate (shortest holdoff). if self._holdoff is None or self._holdoff > holdoff: self._holdoff = holdoff if self._active is not None: # restart timer self.killTimer(self._active) self._active = self.startTimer(self._holdoff) # TODO: re-adjust on slot disconnect? # schedule to receive initial update later (avoids recursion) QCoreApplication.postEvent(self, CBEvent(slot))
def _result(self, value): # called on PVA worker thread QCoreApplication.postEvent(self, CBEvent(value))
def _in_main_later(fn, exceptions_in_main, *args, **kwargs): queue = Queue() QCoreApplication.postEvent( caller, CallEvent(queue, exceptions_in_main, fn, *args, **kwargs)) return queue
def invoke_in_main_thread(fn, *args, **kwargs): """ Invoke a callable in the main thread. Use this for making callbacks to the gui where signals are inconvenient. """ QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
def _event(self): _log.debug('event1 %s', self.name) # called on PVA worker thread QCoreApplication.postEvent(self, CBEvent(None))