コード例 #1
0
ファイル: iocontrol.py プロジェクト: linux4sam/iocontrol
def main():
    signal(SIGINT, SIG_DFL)
    app = QApplication(sys.argv)
    sys.excepthook = excepthook

    splash_pix = QPixmap(path.join(path.dirname(__file__), 'loading.png'))
    splash = QSplashScreen(splash_pix)
    splash.show()
    splash.raise_()
    app.processEvents()

    with open(path.join(path.dirname(__file__), "style.qss"), 'r') as f:
        app.setStyleSheet(f.read())

    win = MainWindow()

    from argparse import ArgumentParser
    parser = ArgumentParser(description='Microchip Peripheral I/O Control')
    parser.add_argument('--fullscreen', dest='fullscreen', action='store_true',
                        help='show the main window in fullscreen')
    parser.set_defaults(fullscreen=False)

    # ignore unknown arguments, necessary for ignoring only -smallresolution
    args, unknown = parser.parse_known_args()

    if args.fullscreen:
        win.setFixedSize(QApplication.desktop().size())
        win.showFullScreen()
    else:
        win.show()
    win.setFocus()

    splash.finish(win)
    sys.exit(app.exec_())
コード例 #2
0
def run():
    """
    Creates all the top-level assets for the application, sets things up and
    then runs the application. Specific tasks include:

    - set up logging
    - create an application object
    - create an editor window and status bar
    - display a splash screen while starting
    - close the splash screen after startup timer ends
    """
    setup_logging()
    logging.info("\n\n-----------------\n\nStarting Mu {}".format(__version__))
    logging.info(platform.uname())
    logging.info("Python path: {}".format(sys.path))
    # logging.info("Language code: {}".format(language_code))

    # The app object is the application running on your computer.
    app = QApplication(sys.argv)
    # By default PyQt uses the script name (run.py)
    app.setApplicationName("mu")
    # Set hint as to the .desktop files name
    app.setDesktopFileName("mu.codewith.editor")
    app.setApplicationVersion(__version__)
    app.setAttribute(Qt.AA_DontShowIconsInMenus)
    # Images (such as toolbar icons) aren't scaled nicely on retina/4k displays
    # unless this flag is set
    app.setAttribute(Qt.AA_UseHighDpiPixmaps)

    # Create the "window" we'll be looking at.
    editor_window = Window()

    @editor_window.load_theme.connect
    def load_theme(theme):
        if theme == "contrast":
            app.setStyleSheet(CONTRAST_STYLE)
        elif theme == "night":
            app.setStyleSheet(NIGHT_STYLE)
        else:
            app.setStyleSheet(DAY_STYLE)

    # Display a friendly "splash" icon.
    splash = QSplashScreen(load_pixmap("splash-screen"))
    splash.show()

    # Make sure the splash screen stays on top while
    # the mode selection dialog might open
    raise_splash = QTimer()
    raise_splash.timeout.connect(lambda: splash.raise_())
    raise_splash.start(10)

    # Hide the splash icon.
    def remove_splash():
        splash.finish(editor_window)
        raise_splash.stop()

    splash_be_gone = QTimer()
    splash_be_gone.timeout.connect(remove_splash)
    splash_be_gone.setSingleShot(True)
    splash_be_gone.start(2000)

    # Make sure all windows have the Mu icon as a fallback
    app.setWindowIcon(load_icon(editor_window.icon))
    # Create the "editor" that'll control the "window".
    editor = Editor(view=editor_window)
    editor.setup(setup_modes(editor, editor_window))
    # Setup the window.
    editor_window.closeEvent = editor.quit
    editor_window.setup(editor.theme)
    # Restore the previous session along with files passed by the os
    editor.restore_session(sys.argv[1:])
    # Connect the various UI elements in the window to the editor.
    editor_window.connect_tab_rename(editor.rename_tab, "Ctrl+Shift+S")
    editor_window.connect_find_replace(editor.find_replace, "Ctrl+F")
    editor_window.connect_toggle_comments(editor.toggle_comments, "Ctrl+K")
    editor.connect_to_status_bar(editor_window.status_bar)

    # Stop the program after the application finishes executing.
    sys.exit(app.exec_())