Exemple #1
0
 def initialize(self, *, load_plug_ins=True, use_root_dir=True):
     super().initialize()
     # configure app data
     if load_plug_ins:
         logging.info("Launch time " + str(datetime.datetime.now()))
         logging.info("Python version " +
                      str(sys.version.replace('\n', '')))
         logging.info("User interface class " + type(self.ui).__name__ +
                      " / " + type(self.ui.proxy).__name__)
         logging.info("Qt version " + self.ui.get_qt_version())
         app_data_file_path = self.ui.get_configuration_location(
         ) / pathlib.Path("nionswift_appdata.json")
         ApplicationData.set_file_path(app_data_file_path)
         logging.info("Application data: " + str(app_data_file_path))
         PlugInManager.load_plug_ins(
             self,
             get_root_dir() if use_root_dir else None)
         color_maps_dir = self.ui.get_configuration_location(
         ) / pathlib.Path("Color Maps")
         if color_maps_dir.exists():
             logging.info("Loading color maps from " + str(color_maps_dir))
             ColorMaps.load_color_maps(color_maps_dir)
         else:
             logging.info("NOT Loading color maps from " +
                          str(color_maps_dir) + " (missing)")
Exemple #2
0
 def deinitialize(self):
     # shut down hardware source manager, unload plug-ins, and really exit ui
     if self.__profile:
         self.__profile.close()
         self.__profile = None
     HardwareSource.HardwareSourceManager().close()
     PlugInManager.unload_plug_ins()
     self.__class__.count -= 1
     super().deinitialize()
Exemple #3
0
def load_tests(packages: typing.Sequence[str]) -> None:
    global suites
    global suite_dict
    global alltests

    base_prefix = sys.base_prefix
    directories = set()
    for path in sys.path:
        if not path.startswith(base_prefix):
            directories.add(path)
    for package in packages:
        for directory in directories:
            test_dir = os.path.join(directory, *package.split("."), "test")
            if os.path.isdir(test_dir):
                for file in os.listdir(test_dir):
                    if file.endswith("_test.py"):
                        module_name = package + ".test." + file.replace(
                            '.py', '')
                        module = importlib.import_module(module_name)
                        for maybe_a_class in inspect.getmembers(module):
                            if inspect.isclass(
                                    maybe_a_class[1]
                            ) and maybe_a_class[0].startswith("Test"):
                                test_name = maybe_a_class[0]
                                # It is a class... add it to the test suite.
                                cls = getattr(module, test_name)
                                suite = unittest.TestLoader(
                                ).loadTestsFromTestCase(cls)
                                suites.append(suite)
                                suite_dict[test_name] = suite

    suites.extend(PlugInManager.test_suites())

    alltests = unittest.TestSuite(suites)
Exemple #4
0
 def initialize(self, *, load_plug_ins=True, use_root_dir=True):
     # configure the event loop object
     logger = logging.getLogger()
     old_level = logger.level
     logger.setLevel(logging.INFO)
     self.__event_loop = asyncio.new_event_loop()  # outputs a debugger message!
     logger.setLevel(old_level)
     # configure app data
     if load_plug_ins:
         logging.info("Python version " + str(sys.version.replace('\n', '')))
         logging.info("User interface class " + type(self.ui).__name__ + " / " + type(self.ui.proxy).__name__)
         app_data_file_path = self.ui.get_configuration_location() / pathlib.Path("nionswift_appdata.json")
         ApplicationData.set_file_path(app_data_file_path)
         logging.info("Application data: " + str(app_data_file_path))
         PlugInManager.load_plug_ins(self, get_root_dir() if use_root_dir else None)
         color_maps_dir = self.ui.get_configuration_location() / pathlib.Path("Color Maps")
         if color_maps_dir.exists():
             logging.info("Loading color maps from " + str(color_maps_dir))
             ColorMaps.load_color_maps(color_maps_dir)
         else:
             logging.info("NOT Loading color maps from " + str(color_maps_dir) + " (missing)")
Exemple #5
0
 def deinitialize(self):
     # shut down hardware source manager, unload plug-ins, and really exit ui
     HardwareSource.HardwareSourceManager().close()
     PlugInManager.unload_plug_ins()
     with open(os.path.join(self.ui.get_data_location(), "PythonConfig.ini"), 'w') as f:
         f.write(sys.prefix + '\n')
     # give cancelled tasks a chance to finish
     self.__event_loop.stop()
     self.__event_loop.run_forever()
     try:
         # this assumes that all outstanding tasks finish in a reasonable time (i.e. no infinite loops).
         self.__event_loop.run_until_complete(asyncio.gather(*asyncio.Task.all_tasks(loop=self.__event_loop), loop=self.__event_loop))
     except concurrent.futures.CancelledError:
         pass
     # now close
     # due to a bug in Python libraries, the default executor needs to be shutdown explicitly before the event loop
     # see http://bugs.python.org/issue28464
     if self.__event_loop._default_executor:
         self.__event_loop._default_executor.shutdown()
     self.__event_loop.close()
     self.__event_loop = None
     self.ui.close()
 def __init__(self,
              document_controller: DocumentController.DocumentController,
              panel_id: str, properties: dict):
     super().__init__(document_controller, panel_id, 'libertem-panel')
     panel_type = properties.get('panel_type')
     for component in Registry.get_components_by_type('libertem-panel'):
         if component.panel_type == panel_type:
             ui_handler = component.get_ui_handler(
                 api_broker=PlugInManager.APIBroker(),
                 event_loop=document_controller.event_loop)
             self.widget = Declarative.DeclarativeWidget(
                 document_controller.ui, document_controller.event_loop,
                 ui_handler)
    def show_conflict_check_dialog(self, document_controller, metadata_elab,
                                   metadata_nion, dataitem, conflict_keys):
        ui_handler = ConflictCheckDialogUI().get_ui_handler(
            api_broker=PlugInManager.APIBroker(),
            event_loop=document_controller.event_loop,
            metadata_elab=metadata_elab,
            metadata_nion=metadata_nion,
            dataitem=dataitem,
            conflict_keys=conflict_keys,
            title='Resolve conflicts')
        finishes = list()
        dialog = Declarative.construct(document_controller.ui,
                                       document_controller, ui_handler.ui_view,
                                       ui_handler, finishes)
        for finish in finishes:
            finish()
        ui_handler._event_loop = document_controller.event_loop

        ui_handler.request_close = dialog.request_close
        ui_handler.parent_request_close = self.request_close
        dialog.show()
    def show_file_param_dialog(self,
                               file_ext: str = None,
                               params_callback: callable = None):
        if self.__file_param_dialog_closed_event.is_set():
            document_controller = self.__api.application.document_controllers[
                0]._document_controller
            ui_handler = OpenFileDialogUI().get_ui_handler(
                api_broker=PlugInManager.APIBroker(),
                event_loop=document_controller.event_loop,
                file_ext=file_ext,
                title='File')

            def dialog_closed():
                self.__file_param_dialog_closed_event.set()

            ui_handler.on_closed = dialog_closed

            ui_handler.params_callback = params_callback

            finishes = list()
            dialog = Declarative.construct(document_controller.ui,
                                           document_controller,
                                           ui_handler.ui_view, ui_handler,
                                           finishes)
            for finish in finishes:
                finish()
            ui_handler._event_loop = document_controller.event_loop
            if callable(getattr(ui_handler, 'init_handler', None)):
                ui_handler.init_handler()

            dialog.show()

            ui_handler.request_close = dialog.request_close

            self.__file_param_dialog_closed_event.clear()
        self.__show_file_param_dialog_finished_event.set()
Exemple #9
0
 def get_api(self, version, ui_version=None):
     ui_version = ui_version if ui_version else "~1.0"
     api = PlugInManager.api_broker_fn(version, ui_version)
     queued_api = FacadeQueued.API(api, None)
     queued_api._queue_task = api.queue_task
     return queued_api
Exemple #10
0
 def get_api(self, version: str, ui_version: typing.Optional[str] = None) -> typing.Any:
     ui_version = ui_version if ui_version else "~1.0"
     api = PlugInManager.api_broker_fn(version, ui_version)
     queued_api = FacadeQueued.API(api, None)  # type: ignore
     queued_api._queue_task = api.queue_task  # type: ignore
     return queued_api
Exemple #11
0
 def deinitialize(self):
     # shut down hardware source manager, unload plug-ins, and really exit ui
     HardwareSource.HardwareSourceManager().close()
     PlugInManager.unload_plug_ins()
     super().deinitialize()