コード例 #1
0
ファイル: gui.py プロジェクト: flsantanna/FQM
    def reset_admin_pass(self):
        with self.app.app_context():
            User.reset_default_password()

        QMessageBox.information(
            self, self.get_translation('Password reset'),
            self.get_translation('Admin password was reset successfully.'),
            QMessageBox.Ok)
コード例 #2
0
def interface(cli, quiet, reset, ip, port):
    ''' FQM command-line interface (CLI):

    * if `--cli` is not used, initializing GUI will be attempted.\n
    * If no `ip` is passed it will default to `127.0.0.1`.\n
    * If no `port` is passed it will default to a random port.\n
    '''
    app = bundle_app()

    def start_cli():
        alt_ip = ip or get_accessible_ips()[0][1]
        alt_port = port or get_random_available_port(alt_ip)
        app.config['LOCALADDR'] = alt_ip
        app.config['CLI_OR_DEPLOY'] = True
        app.config['QUIET'] = quiet

        click.echo(
            click.style(
                f'FQM {VERSION} is running on http://{alt_ip}:{alt_port}',
                bold=True,
                fg='green'))
        click.echo('')
        click.echo(
            click.style('Press Control-c to stop',
                        blink=True,
                        fg='black',
                        bg='white'))

        try:
            monkey.patch_socket()
            pywsgi.WSGIServer(
                (str(alt_ip), int(alt_port)),
                app,
                log=None if quiet else 'default').serve_forever()
        except KeyboardInterrupt:
            stop_tasks()

    if cli:
        start_cli()
    elif reset:
        with app.app_context():
            User.reset_default_password()
            click.echo('Admmin password was reset.')
    else:
        try:
            app.config['CLI_OR_DEPLOY'] = False
            gui_process = import_module('PyQt5.QtWidgets').QApplication(
                sys.argv)
            window = import_module('app.gui').MainWindow(
                app)  # NOTE: has to be decleared in a var to work properly

            import_module('PyQt5.QtCore').QCoreApplication.processEvents()
            gui_process.exec_()
        except Exception as e:
            if not quiet:
                print('Failed to start PyQt GUI, fallback to CLI.')
                log_error(e, quiet=quiet)

            start_cli()

    stop_tasks()