Пример #1
0
def _run_reg(worker_id, queue, method_name, mode, reg_data, ref_data, options):
    """
    Generic registration function for asynchronous process
    """
    try:
        set_local_file_path()
        method = get_reg_method(method_name)
        if method is None:
            raise QpException("Unknown registration method: %s (known: %s)" %
                              (method_name, str(get_plugins("reg-methods"))))

        if not reg_data:
            raise QpException("No registration data")
        elif mode == "moco":
            return _reg_moco(worker_id, method, reg_data, ref_data, options,
                             queue)
        elif reg_data[0].ndim == 3:
            return _reg_3d(worker_id, method, reg_data, ref_data, options,
                           queue)
        else:
            return _reg_4d(worker_id, method, reg_data, ref_data, options,
                           queue)
    except:
        traceback.print_exc()
        return worker_id, False, sys.exc_info()[1]
Пример #2
0
def _worker_initialize():
    """
    Initializer function for multiprocessing workers.
    
    This makes sure plugins are loaded and paths to local files are set
    """
    set_local_file_path()
    get_plugins()
Пример #3
0
def main():
    """
    Parse any input arguments and run the application
    """

    # Enable multiprocessing on windows frozen binaries. Does nothing on other systems
    multiprocessing.freeze_support()

    # Parse input arguments to pass info to GUI
    parser = argparse.ArgumentParser()
    parser.add_argument('data', help='Load data files', nargs="*", type=str)
    parser.add_argument('--batch', help='Run batch file', default=None, type=str)
    parser.add_argument('--debug', help='Activate debug mode', action="store_true")
    parser.add_argument('--test-all', help='Run all tests', action="store_true")
    parser.add_argument('--test', help='Specify test suite to be run (default=run all)', default=None)
    parser.add_argument('--test-fast', help='Run only fast tests', action="store_true")
    parser.add_argument('--qv', help='Activate quick-view mode', action="store_true")
    parser.add_argument('--register', help='Force display of registration dialog', action="store_true")
    args = parser.parse_args()

    # Apply global options
    if args.debug:
        set_base_log_level(logging.DEBUG)
    else:
        set_base_log_level(logging.WARN)

    if args.register:
        QtCore.QSettings().setValue("license_accepted", 0)

    # Set the local file path, used for finding icons, plugins, etc
    set_local_file_path()

    # Handle CTRL-C correctly
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    if args.batch is not None:
        # Batch runs need a QCoreApplication to avoid initializing the GUI - this
        # would fail when running on a displayless system 
        app = QtCore.QCoreApplication(sys.argv)
        runner = BatchScript()
        # Add delay to make sure script is run after the main loop starts, in case
        # batch script is completely synchronous
        QtCore.QTimer.singleShot(200, lambda: runner.execute({"yaml-file" : args.batch}))
        sys.exit(app.exec_())
    else:
        # Otherwise we need a QApplication and to initialize the GUI
        
        if sys.platform.startswith("darwin") and PYSIDE1:
            # Required on Mac with Pyside 1
            QtGui.QApplication.setGraphicsSystem('native')

        app = QtGui.QApplication(sys.argv)
        app.setStyle('plastique')
        QtCore.QCoreApplication.setOrganizationName("ibme-qubic")
        QtCore.QCoreApplication.setOrganizationDomain("eng.ox.ac.uk")
        QtCore.QCoreApplication.setApplicationName("Quantiphyse")
        QtGui.QApplication.setWindowIcon(QtGui.QIcon(get_icon("main_icon.png")))

        if args.debug:
            import pyqtgraph as pg
            pg.systemInfo()

        if args.test_all or args.test:
            # Run tests
            run_tests(args.test)
            sys.exit(0)
        else:
            # Create window and start main loop
            pixmap = QtGui.QPixmap(get_icon("quantiphyse_splash.png"))
            splash = QtGui.QSplashScreen(pixmap)
            splash.show()
            app.processEvents()

            win = MainWindow(load_data=args.data, widgets=not args.qv)
            splash.finish(win)
            sys.excepthook = my_catch_exceptions
            set_main_window(win)
            register.check_register()
            sys.exit(app.exec_())