def main():

    app = QApplication(sys.argv)

    # Create and set an event loop that combines qt and asyncio
    loop = QSelectorEventLoop(app)
    asyncio.set_event_loop(loop)

    main_window = MainUI()
    main_window.show()
    sys.exit(app.exec_())
Exemple #2
0
def main():
    """
    Check starting conditions and start GUI.

    First, check command line arguments and start loggers. Set log levels. Try
    all imports and exit verbosely if a library is not found. Disable outputs
    to stdout and start the GUI.
    """

    # Set ERROR level for PyQt5 logger
    qtlogger = logging.getLogger('PyQt5')
    qtlogger.setLevel(logging.ERROR)

    parser = argparse.ArgumentParser(
        description="cfclient - Crazyflie graphical control client")
    parser.add_argument('--debug', '-d', nargs=1, default='info', type=str,
                        help="set debug level "
                             "[minimal, info, debug, debugfile]")
    parser.add_argument('--check-imports', type=bool, default=False,
                        const=True, nargs="?",
                        help="Check python imports and exit successfully" +
                        " (intended for CI)")
    args = parser.parse_args()
    debug = args.debug

    cflogger = logging.getLogger('')

    # Set correct logging fuctionality according to commandline
    if ("debugfile" in debug):
        logging.basicConfig(level=logging.DEBUG)
        # Add extra format options for file logger (thread and time)
        formatter = logging.Formatter('%(asctime)s:%(threadName)s:%(name)'
                                      's:%(levelname)s:%(message)s')
        filename = "debug-%s.log" % datetime.datetime.now()
        filehandler = logging.FileHandler(filename)
        filehandler.setLevel(logging.DEBUG)
        filehandler.setFormatter(formatter)
        cflogger.addHandler(filehandler)
    elif ("debug" in debug):
        logging.basicConfig(level=logging.DEBUG)
    elif ("minimal" in debug):
        logging.basicConfig(level=logging.WARNING)
    elif ("info" in debug):
        logging.basicConfig(level=logging.INFO)

    logger = logging.getLogger(__name__)

    logger.debug("Using config path {}".format(cfclient.config_path))
    logger.debug("sys.path={}".format(sys.path))

    # Try all the imports used in the project here to control what happens....
    try:
        import usb  # noqa
    except ImportError:
        logger.critical("No pyusb installation found, exiting!")
        sys.exit(1)

    if not sys.platform.startswith('linux'):
        try:
            import sdl2  # noqa
        except ImportError:
            logger.critical("No pysdl2 installation found, exiting!")
            sys.exit(1)

    try:
        import PyQt5  # noqa
    except ImportError:
        logger.critical("No PyQT5 installation found, exiting!")
        sys.exit(1)

    # Disable printouts from STL
    if os.name == 'posix':
        stdout = os.dup(1)
        os.dup2(os.open('/dev/null', os.O_WRONLY), 1)
        sys.stdout = os.fdopen(stdout, 'w')
        logger.info("Disabling STL printouts")

    if os.name == 'nt':
        stdout = os.dup(1)
        os.dup2(os.open('NUL', os.O_WRONLY), 1)
        sys.stdout = os.fdopen(stdout, 'w')
        logger.info("Disabling STL printouts")

    if sys.platform == 'darwin':
        try:
            import Foundation
            bundle = Foundation.NSBundle.mainBundle()
            if bundle:
                info = (bundle.localizedInfoDictionary() or
                        bundle.infoDictionary())
                if info:
                    info['CFBundleName'] = 'Crazyflie'
        except ImportError:
            logger.info("Foundation not found. Menu will show python as "
                        "application name")

    if args.check_imports:
        logger.info("All imports successful!")
        sys.exit(0)

    # Start up the main user-interface
    from .ui.main import MainUI
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtGui import QIcon

    app = QApplication(sys.argv)
    app.setStyle("Fusion")
    from cfclient.utils.ui import UiUtils

    # Create and set an event loop that combines qt and asyncio
    loop = QSelectorEventLoop(app)
    asyncio.set_event_loop(loop)

    app.setWindowIcon(QIcon(cfclient.module_path + "/ui/icons/icon-256.png"))
    # Make sure the right icon is set in Windows 7+ taskbar
    if os.name == 'nt':
        import ctypes

        try:
            myappid = 'mycompany.myproduct.subproduct.version'
            ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
                myappid)
        except Exception:
            pass

    main_window = MainUI()
    app.setFont(UiUtils.FONT)
    main_window.show()
    main_window.set_default_theme()
    sys.exit(app.exec_())
Exemple #3
0
def startApp():
    app = QtWidgets.QApplication(sys.argv)
    loop = QSelectorEventLoop(app)
    asyncio.set_event_loop(loop)
    gui = ExperimentBase()
    QtWidgets.QApplication.instance().exec_()
Exemple #4
0
                    Please report it to <a href='https://github.com/duniter/sakia/issues/new'>the developers github</a>""",
                     QMessageBox.Ok, QApplication.activeWindow())
    mb.setDetailedText(message)
    mb.setTextFormat(Qt.RichText)

    mb.setTextInteractionFlags(Qt.TextSelectableByMouse)
    mb.exec()

if __name__ == '__main__':
    # activate ctrl-c interrupt
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sakia = QApplication(sys.argv)
    sys.excepthook = exception_handler

    sakia.setStyle('Fusion')
    loop = QSelectorEventLoop(sakia)
    loop.set_exception_handler(async_exception_handler)
    asyncio.set_event_loop(loop)

    with loop:
        app = Application.startup(sys.argv, sakia, loop)
        window = MainWindow.startup(app)
        loop.run_forever()
        try:
            loop.set_exception_handler(None)
            loop.run_until_complete(app.stop())
            logging.debug("Application stopped")
        except asyncio.CancelledError:
            logging.info('CancelledError')
    logging.debug("Exiting")
    sys.exit()
    def refreshShapes(self):
        shapes = self.shapes[self.frame]
        self.cbShoulderShape.setCurrentText(SHAPE_DICT_REVERSE[shapes[0]])
        self.cbArmShape.setCurrentText(SHAPE_DICT_REVERSE[shapes[1]])
        self.cbHandShape.setCurrentText(SHAPE_DICT_REVERSE[shapes[2]])
        self.cbMalletShape.setCurrentText(SHAPE_DICT_REVERSE[shapes[3]])

    def toggleVid(self):
        if self.playing:
            self.timer.stop()
            self.sound.stop()
            self.btStart.setText("Play")
        else:
            self.timer.start(
                int((self.times[self.frame + 1] - self.times[self.frame]) *
                    1000))
            self.btStart.setText("Pause")
        self.playing = not self.playing

    def getCurrentState(self):
        self.currentTest.note = self.noteList[self.cbNote.currentText()]
        self.currentTest.path = self.pathList[self.cbPath.currentText()]


if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    loop = QSelectorEventLoop(app)
    asyncio.set_event_loop(loop)
    gui = TestPlot()
    QtGui.QApplication.instance().exec_()
Exemple #6
0
def main():
    # activate ctrl-c interrupt
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sakia = QApplication(sys.argv)

    sys.excepthook = exception_handler

    sakia.setStyle('Fusion')
    loop = QSelectorEventLoop(sakia)
    loop.set_exception_handler(async_exception_handler)
    #loop.set_debug(True)
    asyncio.set_event_loop(loop)

    with loop:
        app = Application.startup(sys.argv, sakia, loop)

        lock = single_instance_lock(app.currency)
        if not lock:
            lock = single_instance_lock(app.currency)
            if not lock:
                QMessageBox.critical(None, "Sakia",
                                     "Sakia is already running.")

                sys.exit(1)
        app.start_coroutines()
        app.get_last_version()
        keep_trying = True
        while not app.blockchain_service.initialized():
            try:
                box = QMessageBox()
                box.setWindowTitle("Initialization")
                box.setText("Connecting to the network...")
                wFlags = box.windowFlags()
                if Qt.WindowCloseButtonHint == (wFlags
                                                & Qt.WindowCloseButtonHint):
                    wFlags = wFlags ^ Qt.WindowCloseButtonHint
                    box.setWindowFlags(wFlags)
                box.show()
                loop.run_until_complete(app.initialize_blockchain())
                box.hide()
            except (DuniterError, NoPeerAvailable) as e:
                reply = QMessageBox.critical(
                    None, "Error",
                    "Error connecting to the network : {:}. Keep Trying ?".
                    format(str(e)), QMessageBox.Ok | QMessageBox.Abort)
                if reply == QMessageBox.Ok:
                    loop.run_until_complete(
                        PreferencesDialog(app).async_exec())
                else:
                    break
        else:
            if not app.connection_exists():
                conn_controller = ConnectionConfigController.create_connection(
                    None, app)
                loop.run_until_complete(conn_controller.async_exec())
            window = MainWindowController.startup(app)
            loop.run_forever()
        try:
            loop.set_exception_handler(None)
            loop.run_until_complete(app.stop_current_profile())
            logging.debug("Application stopped")
        except asyncio.CancelledError:
            logging.info('CancelledError')
    logging.debug("Exiting")
    cleanup_lock(lock)
    sys.exit()
Exemple #7
0
def main():
    # activate ctrl-c interrupt
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sakia = QApplication(sys.argv)

    sys.excepthook = exception_handler

    #sakia.setStyle('Fusion')
    loop = QSelectorEventLoop(sakia)
    loop.set_exception_handler(async_exception_handler)
    #loop.set_debug(True)
    asyncio.set_event_loop(loop)

    with loop:
        app = Application.startup(sys.argv, sakia, loop)

        lock = single_instance_lock(app.currency)
        if not lock:
            lock = single_instance_lock(app.currency)
            if not lock:
                QMessageBox.critical(None, "Sakia",
                                 "Sakia is already running.")

                sys.exit(1)
        app.start_coroutines()
        app.get_last_version()
        keep_trying = True
        while not app.blockchain_service.initialized():
            try:
                box = QMessageBox()
                box.setWindowTitle("Initialization")
                box.setText("Connecting to the network...")
                wFlags = box.windowFlags()
                if Qt.WindowCloseButtonHint == (wFlags & Qt.WindowCloseButtonHint):
                    wFlags = wFlags ^ Qt.WindowCloseButtonHint
                    box.setWindowFlags(wFlags)
                box.show()
                loop.run_until_complete(app.initialize_blockchain())
                box.hide()
            except (DuniterError, NoPeerAvailable) as e:
                reply = QMessageBox.critical(None, "Error", "Error connecting to the network : {:}. Keep Trying ?".format(str(e)),
                                             QMessageBox.Ok | QMessageBox.Abort)
                if reply == QMessageBox.Ok:
                    loop.run_until_complete(PreferencesDialog(app).async_exec())
                else:
                    break
        else:
            if not app.connection_exists():
                conn_controller = ConnectionConfigController.create_connection(None, app)
                loop.run_until_complete(conn_controller.async_exec())
            window = MainWindowController.startup(app)
            loop.run_forever()
        try:
            loop.set_exception_handler(exit_exception_handler)
            loop.run_until_complete(app.stop_current_profile())
            logging.debug("Application stopped")
        except asyncio.CancelledError:
            logging.info('CancelledError')
    logging.debug("Exiting")
    cleanup_lock(lock)
    sys.exit()
Exemple #8
0
    # activate ctrl-c interrupt
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sakia = QApplication(sys.argv)

    lock = single_instance_lock()
    if not lock:
        lock = single_instance_lock()
        if not lock:
            QMessageBox.critical(None, "Sakia", "Sakia is already running.")

            sys.exit(1)

    sys.excepthook = exception_handler

    sakia.setStyle('Fusion')
    loop = QSelectorEventLoop(sakia)
    loop.set_exception_handler(async_exception_handler)
    asyncio.set_event_loop(loop)

    with loop:
        app = Application.startup(sys.argv, sakia, loop)
        app.start_coroutines()
        try:
            if not app.blockchain_service.initialized():
                box = QMessageBox()
                box.setWindowTitle("Initialization")
                box.setText("Connecting to the network...")
                wFlags = box.windowFlags()
                if Qt.WindowCloseButtonHint == (wFlags
                                                & Qt.WindowCloseButtonHint):
                    wFlags = wFlags ^ Qt.WindowCloseButtonHint