예제 #1
0
파일: ui.py 프로젝트: eepp/yobr
def _parse_args(app):
    parser = qtcore.QCommandLineParser()
    parser.setApplicationDescription(yobr.__description__)
    parser.addHelpOption()
    log_lvl_opt = qtcore.QCommandLineOption('log-level', 'Log level', 'LVL',
                                            'INFO')
    parser.addOption(log_lvl_opt)
    parser.addVersionOption()
    parser.addPositionalArgument('BR-ROOT-DIR', 'Buildroot root directory')
    parser.addPositionalArgument(
        'BR-BUILD-DIR',
        'Buildroot build directory (default: `BR-ROOT-DIR/output/build`)')
    parser.process(app)
    pos_args = parser.positionalArguments()

    if len(pos_args) not in (1, 2):
        raise RuntimeError('Expecting one or two positional arguments.')

    if len(pos_args) == 2:
        # specific build directory
        br_build_dir = pos_args[1]
    else:
        # default to `BR-ROOT-DIR/output/build`
        br_build_dir = os.path.join(pos_args[0], 'output', 'build')

    return _Args(pos_args[0], br_build_dir, parser.value(log_lvl_opt))
예제 #2
0
 def __init__(self):
     """
     Initialize the CommandLineParser.
     """
     super().__init__()
     self.addHelpOption()
     self.addVersionOption()
     self.addOptions([
         QtCore.QCommandLineOption(
             [CommandLineParser.NO_SPLASH],
             'Do not show the application splash screen.'),
         QtCore.QCommandLineOption(
             [CommandLineParser.OPEN],
             'Look for a project in the workspace with the given name and open it.',
             valueName=CommandLineParser.OPEN),
     ])
     self.addPositionalArgument('project',
                                'Path to a project file to open.',
                                '[project]')
     self.setApplicationDescription(
         textwrap.dedent("""
     {0}, a graphical editor for the specification and visualization of Graphol ontologies.
     """).format(APPNAME))
예제 #3
0
파일: 9111.py 프로젝트: fulivi/mame_tools
def get_tcp_port(app):
    parser = QtCore.QCommandLineParser()
    parser.addHelpOption()
    default_port = 1234
    port_opt = QtCore.QCommandLineOption([ "p" , "port" ] , "Set TCP port fo remote488." , "TCP port" , str(default_port))
    parser.addOption(port_opt)
    parser.process(app)
    try:
        port = int(parser.value(port_opt))
    except ValueError:
        print("Invalid port, using default")
        port = default_port
    if 1 <= port <= 65535:
        return port
    else:
        print("Invalid port ({}), using default".format(port))
        return default_port
예제 #4
0
def main():
    "Main entry point of application"
    app = QtWidgets.QApplication(sys.argv)
    app.setOrganizationName("Accounting")
    app.setOrganizationDomain("accounting.com")
    app.setApplicationName("Accounting")
    app.setApplicationVersion("1.0")

    parser = QtCore.QCommandLineParser()
    parser.setApplicationDescription("Double accounting application")
    parser.addHelpOption()
    parser.addVersionOption()

    loadDbOption = QtCore.QCommandLineOption(
        "db", "Load selected database on startup", "PATH")
    loadDbOption.setDefaultValue("")
    parser.addOption(loadDbOption)

    parser.process(app)

    wnd = MainWindow(dbPath=parser.value(loadDbOption))

    return app.exec_()
예제 #5
0
def main():
    if "--no-gui" in sys.argv:
        application = QCoreApplication(sys.argv)
        gui_mode = False
    else:
        application = QApplication(sys.argv)
        application.setQuitOnLastWindowClosed(False)
        gui_mode = True

    application.setApplicationName(APP_NAME)
    application.setApplicationVersion(APP_VERSION)

    translator = QtCore.QTranslator(application)
    translator.load(QtCore.QLocale().name(), directory=TRANSLATIONS_DIR)
    application.installTranslator(translator)

    parser = QtCore.QCommandLineParser()
    parser.setApplicationDescription(APP_DESCRIPTION)
    parser.addHelpOption()
    parser.addVersionOption()

    config_dir = os.path.join(os.path.expanduser("~"), ".config",
                              "keyboard-mapper")

    config_dir_option = QtCore.QCommandLineOption(
        ["c", "config-dir"],
        "Path to the config dir (default: {})".format(config_dir),
        defaultValue=config_dir)
    parser.addOption(config_dir_option)

    hidden_option = QtCore.QCommandLineOption(["H", "hidden"], "Start hidden")
    parser.addOption(hidden_option)

    parser.addOption(QtCore.QCommandLineOption(["no-gui"],
                                               "Start without GUI"))

    parser.process(application)

    config_dir = parser.value(config_dir_option)

    if not os.path.isdir(config_dir):
        os.mkdir(config_dir)

    Config.filename = os.path.join(config_dir, "config.ini")
    Config.load()

    if gui_mode:
        application.setWindowIcon(
            QtGui.QIcon(
                os.path.join(ICONS_DIR,
                             "appicon-{}.png".format(Config.icons))))

    if Config.single_instance:
        user_run_dir = os.path.join("var", "run", "user", str(os.getuid()))
        if os.path.exists(user_run_dir):
            lock_file = os.path.join(user_run_dir, "keyboard-mapper.lock")
        else:
            lock_file = os.path.join(config_dir, "app.lock")

        lock = FileLock(lock_file, timeout=1)

        try:
            lock.acquire()
        except Timeout:
            message = translate("main", "Keyboard Mapper is already running!")
            if gui_mode:
                QtWidgets.QMessageBox.critical(None, APP_NAME, message)
            else:
                print(message)
            sys.exit(1)

    shortcuts_file = os.path.join(config_dir, "shortcuts.yaml")
    legacy_shortcuts_file = os.path.join(config_dir, "shortcuts.ini")

    shortcuts = Shortcuts(shortcuts_file)

    if os.path.exists(
            legacy_shortcuts_file) and not os.path.exists(shortcuts_file):
        if len(Config.input_devices):
            shortcuts.load_legacy(legacy_shortcuts_file,
                                  Config.input_devices[0])

    try:
        shortcuts.load()
    except Exception as exception:
        message = translate("main",
                            "Unable to load shortcuts from config file!"
                            ) + "\n\n" + str(exception)
        if gui_mode:
            if QtWidgets.QMessageBox.critical(None, APP_NAME, message,
                                              QtWidgets.QMessageBox.Close,
                                              QtWidgets.QMessageBox.Ignore
                                              ) == QtWidgets.QMessageBox.Close:
                sys.exit(1)
        else:
            print(message)
            sys.exit(1)

    key_listener_manager = KeyListenerManager(DEVICES_BASE_DIR, shortcuts)
    key_listener_manager.set_device_files(Config.input_devices)

    if gui_mode:
        main_window = MainWindow(shortcuts, key_listener_manager)

        if not parser.isSet(hidden_option):
            main_window.show()

        try:
            exit_code = application.exec_()
        finally:
            shortcuts.save()

        sys.exit(exit_code)
    else:
        print("Listening for keyboard events")

        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            pass

        key_listener_manager.stop_threads()
        shortcuts.save()