Ejemplo n.º 1
0
 def _cleanThreads(self):
     reactor = self._getReactor()
     if interfaces.IReactorThreads.providedBy(reactor):
         if reactor.threadpool is not None:
             # Stop the threadpool now so that a new one is created. 
             # This improves test isolation somewhat (although this is a
             # post class cleanup hook, so it's only isolating classes
             # from each other, not methods from each other).
             reactor._stopThreadPool()
Ejemplo n.º 2
0
 def _cleanThreads(self):
     reactor = self._getReactor()
     if interfaces.IReactorThreads.providedBy(reactor):
         reactor.suggestThreadPoolSize(0)
         if getattr(reactor, "threadpool", None) is not None:
             try:
                 reactor.removeSystemEventTrigger(reactor.threadpoolShutdownID)
             except KeyError:
                 pass
             # Remove the threadpool, and let the reactor put it back again
             # later like a good boy
             reactor._stopThreadPool()
Ejemplo n.º 3
0
 def _cleanThreads(self):
     reactor = self._getReactor()
     if interfaces.IReactorThreads.providedBy(reactor):
         reactor.suggestThreadPoolSize(0)
         if getattr(reactor, 'threadpool', None) is not None:
             try:
                 reactor.removeSystemEventTrigger(
                     reactor.threadpoolShutdownID)
             except KeyError:
                 pass
             # Remove the threadpool, and let the reactor put it back again
             # later like a good boy
             reactor._stopThreadPool()
Ejemplo n.º 4
0
def main(args=None):
    """
    Entrypoint for EPyQ. Initializes the general Qt settings, accepts some command line args,
    and sets up the main GUI window. Final thing to be spun up is the reactor from twisted
    allowing for async functionality with the otherwise single threaded UI.

    Args:
        args (Union[int, float, str], optional): [description]. Defaults to None.
        - verbose: sets the logger level
        - quit-after: sets the time for the duration of the application GUI
        - load-offline: loads only the windows in the device tree denoted as offline from the
        given UI file
    """
    print("starting epyq")

    signal.signal(signal.SIGINT, sigint_handler)

    # TODO: CAMPid 9757656124812312388543272342377
    app = QApplication(sys.argv)
    epyqlib.utils.qt.exception_message_box_register_versions(
        version_tag=epyq.__version_tag__,
        build_tag=epyq.__build_tag__,
    )
    sys.excepthook = functools.partial(
        epyqlib.utils.qt.exception_message_box, )
    QtCore.qInstallMessageHandler(epyqlib.utils.qt.message_handler)
    app.setStyleSheet(
        "QMessageBox {{ messagebox-text-interaction-flags: {}; }}".format(
            Qt.TextBrowserInteraction))
    app.setOrganizationName("EPC Power Corp.")
    app.setApplicationName("EPyQ")

    os_signal_timer = QtCore.QTimer()
    os_signal_timer.start(200)
    os_signal_timer.timeout.connect(lambda: None)

    # TODO: CAMPid 03127876954165421679215396954697
    # https://github.com/kivy/kivy/issues/4182#issuecomment-253159955
    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
    if "twisted.internet.reactor" in sys.modules:
        del sys.modules["twisted.internet.reactor"]

    import qt5reactor

    qt5reactor.install()

    import argparse

    ui_default = "main.ui"

    parser = argparse.ArgumentParser()
    parser.add_argument("--verbose", "-v", action="count", default=0)
    parser.add_argument("--quit-after", type=float, default=None)
    parser.add_argument("--load-offline", default=None)
    if args is None:
        args = parser.parse_args()
    else:
        args = parser.parse_args(args)

    can_logger_modules = ("can", "can.socketcan.native")

    for module in can_logger_modules:
        logging.getLogger(module).setLevel(logging.WARNING)

    if args.verbose >= 1:
        logger = logging.getLogger(__name__)
        logger.setLevel(logging.DEBUG)

    if args.verbose >= 2:
        import twisted.internet.defer

        twisted.internet.defer.setDebugging(True)

    if args.verbose >= 3:
        logging.getLogger().setLevel(logging.DEBUG)

    if args.verbose >= 4:
        logging.getLogger().setLevel(logging.INFO)
        for module in can_logger_modules:
            logging.getLogger(module).setLevel(logging.DEBUG)

    window = Window()
    epyqlib.utils.qt.exception_message_box_register_parent(parent=window)

    window.show()

    if args.quit_after:
        QtCore.QTimer.singleShot(args.quit_after * 1000, app.quit)

    if args.load_offline:

        def load_offline():
            (bus_node, ) = [
                node for node in window.ui.device_tree.model.root.children
                if node.fields.name == "Offline"
            ]

            split = args.load_offline.split("_", maxsplit=1)
            if split[0] == "test":
                path = epyqlib.tests.common.devices[split[1]]
            else:
                path = args.load_offline

            window.ui.device_tree.add_device(
                bus=bus_node,
                device=epyqlib.device.Device(
                    file=path,
                    bus=bus_node.bus,
                    node_id=247,
                ),
            )

        QtCore.QTimer.singleShot(0.5 * 1000, load_offline)

    from twisted.internet import reactor

    reactor.runReturn()
    result = app.exec()
    if reactor.threadpool is not None:
        reactor._stopThreadPool()
        logging.debug("Thread pool stopped")
    logging.debug("Application ended")
    reactor.stop()
    logging.debug("Reactor stopped")

    # TODO: this should be sys.exit() but something keeps the process
    #       from terminating.  Ref T679  Ref T711
    os._exit(result)
Ejemplo n.º 5
0
def main(args=None):
    print('starting epyq')

    signal.signal(signal.SIGINT, sigint_handler)

    # TODO: CAMPid 9757656124812312388543272342377
    app = QApplication(sys.argv)
    epyqlib.utils.qt.exception_message_box_register_versions(
        version_tag=epyq.__version_tag__,
        build_tag=epyq.__build_tag__,
    )
    sys.excepthook = functools.partial(
        epyqlib.utils.qt.exception_message_box, )
    QtCore.qInstallMessageHandler(epyqlib.utils.qt.message_handler)
    app.setStyleSheet(
        'QMessageBox {{ messagebox-text-interaction-flags: {}; }}'.format(
            Qt.TextBrowserInteraction))
    app.setOrganizationName('EPC Power Corp.')
    app.setApplicationName('EPyQ')

    os_signal_timer = QtCore.QTimer()
    os_signal_timer.start(200)
    os_signal_timer.timeout.connect(lambda: None)

    # TODO: CAMPid 03127876954165421679215396954697
    # https://github.com/kivy/kivy/issues/4182#issuecomment-253159955
    # fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
    if 'twisted.internet.reactor' in sys.modules:
        del sys.modules['twisted.internet.reactor']

    import qt5reactor
    qt5reactor.install()

    import argparse

    ui_default = 'main.ui'

    parser = argparse.ArgumentParser()
    parser.add_argument('--verbose', '-v', action='count', default=0)
    parser.add_argument('--quit-after', type=float, default=None)
    parser.add_argument('--load-offline', default=None)
    if args is None:
        args = parser.parse_args()
    else:
        args = parser.parse_args(args)

    can_logger_modules = ('can', 'can.socketcan.native')

    for module in can_logger_modules:
        logging.getLogger(module).setLevel(logging.WARNING)

    if args.verbose >= 1:
        logger = logging.getLogger(__name__)
        logger.setLevel(logging.DEBUG)

    if args.verbose >= 2:
        import twisted.internet.defer
        twisted.internet.defer.setDebugging(True)

    if args.verbose >= 3:
        logging.getLogger().setLevel(logging.DEBUG)

    if args.verbose >= 4:
        logging.getLogger().setLevel(logging.INFO)
        for module in can_logger_modules:
            logging.getLogger(module).setLevel(logging.DEBUG)

    window = Window()
    epyqlib.utils.qt.exception_message_box_register_parent(parent=window)

    window.show()

    if args.quit_after is not None:
        QtCore.QTimer.singleShot(args.quit_after * 1000, app.quit)

    if args.load_offline is not None:

        def load_offline():
            bus_node, = [
                node for node in window.ui.device_tree.model.root.children
                if node.fields.name == 'Offline'
            ]

            split = args.load_offline.split('_', maxsplit=1)
            if split[0] == 'test':
                path = epyqlib.tests.common.devices[split[1]]
            else:
                path = args.load_offline

            window.ui.device_tree.add_device(
                bus=bus_node,
                device=epyqlib.device.Device(
                    file=path,
                    bus=bus_node.bus,
                    node_id=247,
                ),
            )

        QtCore.QTimer.singleShot(0.5 * 1000, load_offline)

    from twisted.internet import reactor
    reactor.runReturn()
    result = app.exec()
    if reactor.threadpool is not None:
        reactor._stopThreadPool()
        logging.debug('Thread pool stopped')
    logging.debug('Application ended')
    reactor.stop()
    logging.debug('Reactor stopped')

    # TODO: this should be sys.exit() but something keeps the process
    #       from terminating.  Ref T679  Ref T711
    os._exit(result)