Beispiel #1
0
def gui_thread_schedule_async(callable, args=None):
    if is_gui_thread():
        if args is None:
            callable()
        else:
            callable(*args)
        return

    event = ExecuteCodeEvent(callable, args)
    QCoreApplication.postEvent(GlobalInfo.main_window, event)
Beispiel #2
0
def headless_main(args):
    """
    Executes a project using :class:`QCoreApplication`.

    Args:
        args (argparser.Namespace): parsed command line arguments.
    Returns:
        int: exit status code; 0 for success, everything else for failure
    """
    application = QCoreApplication(sys.argv)
    startup_event_type = QEvent.Type(QEvent.registerEventType())
    task = ExecuteProject(args, startup_event_type, application)
    application.postEvent(task, QEvent(startup_event_type))
    return application.exec_()
Beispiel #3
0
def gui_thread_schedule(callable, args=None):
    if is_gui_thread():
        if args is None:
            return callable()
        else:
            return callable(*args)

    event = ExecuteCodeEvent(callable, args)
    QCoreApplication.postEvent(GlobalInfo.main_window, event)
    event.event.wait()  # TODO: unsafe. to be fixed later.

    if event.exception is not None:
        raise event.exception

    return event.result
Beispiel #4
0
def gui_thread_schedule_async(callable, args=None, kwargs=None):
    if is_gui_thread():
        if kwargs is None:
            if args is None:
                callable()
            else:
                callable(*args)
        else:
            if args is None:
                callable(**kwargs)
            else:
                callable(*args, **kwargs)
        return

    event = ExecuteCodeEvent(callable, args=args, kwargs=kwargs)
    try:
        QCoreApplication.postEvent(GlobalInfo.main_window, event)
    except RuntimeError:
        # the application is exiting and the main window has been destroyed. just let it go
        pass
Beispiel #5
0
 def run(self):
     """
     Thread body. loops and notifies the listener of new messages
     """
     while not self._stop_flag:
         # Wait for a new message
         cv = self.timeline._messages_cvs[self.topic]
         with cv:
             while (self.topic not in self.timeline._messages) or (
                     self.bag_msg_data
                     == self.timeline._messages[self.topic]):
                 cv.wait()
                 if self._stop_flag:
                     return
             bag_msg_data = self.timeline._messages[self.topic]
         # View the message
         self.bag_msg_data = bag_msg_data
         try:
             event = ListenerEvent(bag_msg_data)
             QCoreApplication.postEvent(self.listener, event)
         except Exception as ex:
             qWarning('Error notifying listener %s: %s' %
                      (type(self.listener), str(ex)))
Beispiel #6
0
def gui_thread_schedule(callable, args=None, timeout=None):
    if is_gui_thread():
        if args is None:
            return callable()
        else:
            return callable(*args)

    event = ExecuteCodeEvent(callable, args)
    try:
        QCoreApplication.postEvent(GlobalInfo.main_window, event)
    except RuntimeError:
        # the application is exiting and the main window has been destroyed. just let it go
        return None

    event.event.wait(timeout=timeout)  # TODO: unsafe. to be fixed later.
    if not event.event.is_set():
        # it timed out without getting scheduled to execute...
        return None

    if event.exception is not None:
        raise event.exception

    return event.result
Beispiel #7
0
 def run(self):
     for i in range(3):
         e = MyEvent(i)
         QCoreApplication.postEvent(self.owner, e)
Beispiel #8
0
 def show_input_field():
     QCoreApplication.postEvent(input_field, QShowEvent())
Beispiel #9
0
 def sendkeys(self, char, modifier=Qt.NoModifier):
     event = QKeyEvent(QEvent.KeyPress, char, modifier)
     QCoreApplication.postEvent(self.gameWidget, event)
Beispiel #10
0
 def send_victory_events(self, victory: bool):
     for cell in self.cells:
         QCoreApplication.postEvent(cell, VictoryEvent(victory))
Beispiel #11
0
 def begin_invoke(func, *args, **kwargs):
     # type: (Callable[[Any], Any], Any, Any) -> NoReturn
     QCoreApplication.postEvent(Dispatcher.invoker, _MethodInvokeEvent(func, args, kwargs))
Beispiel #12
-1
 def run(self):
     for i in range(3):
         e=MyEvent(i);
         QCoreApplication.postEvent(self.owner,e)