Beispiel #1
0
    def __init__(self, ui: UserInterface.UserInterface, app: typing.Optional[Application.BaseApplication] = None,
                 parent_window: typing.Optional[Window] = None, window_style: typing.Optional[str] = None,
                 persistent_id: typing.Optional[str] = None):
        Window.count += 1
        self.ui = ui
        self.parent_window = parent_window
        self.app: typing.Optional[Application.BaseApplication] = app or (parent_window.app if parent_window else None)
        self.on_close: typing.Optional[typing.Callable[[], None]] = None
        parent_ui_window = parent_window._document_window if parent_window else None
        self.__document_window = self.ui.create_document_window(parent_window=parent_ui_window)
        if window_style:
            self.__document_window.window_style = window_style
        self.__persistent_id = persistent_id
        self.__shown = False
        self.__request_close = False

        # Python 3.9+: should be weakref.ReferenceType[Dialog]
        self.__dialogs: typing.List[typing.Any] = list()

        self._window_close_event = Event.Event()

        self.__document_window.on_periodic = self.periodic
        self.__document_window.on_queue_task = self.queue_task
        self.__document_window.on_clear_queued_tasks = self.clear_queued_tasks
        self.__document_window.on_add_task = self.add_task
        self.__document_window.on_clear_task = self.clear_task
        self.__document_window.on_about_to_show = self.about_to_show
        self.__document_window.on_about_to_close = self.about_to_close
        self.__document_window.on_activation_changed = self.activation_changed
        self.__document_window.on_key_pressed = self.key_pressed
        self.__document_window.on_key_released = self.key_released
        self.__document_window.on_size_changed = self.size_changed
        self.__document_window.on_position_changed = self.position_changed
        self.__document_window.on_refocus_widget = self.refocus_widget
        self.__document_window.on_ui_activity = self._register_ui_activity
        self.__periodic_queue = Process.TaskQueue()
        self.__periodic_set = Process.TaskSet()
        self.__modal_actions: typing.List[Action] = list()

        # define old-style menu actions for backwards compatibility
        self._close_action = None
        self._page_setup_action = None
        self._print_action = None
        self._quit_action = None
        self._undo_action = None
        self._redo_action = None
        self._cut_action = None
        self._copy_action = None
        self._paste_action = None
        self._delete_action = None
        self._select_all_action = None
        self._minimize_action = None
        self._zoom_action = None
        self._bring_to_front_action = None

        # configure the event loop object. for backwards compatibility only.
        self.__event_loop = asyncio.get_event_loop_policy().get_event_loop()

        if app:
            app._window_created(self)
Beispiel #2
0
 def __init__(self,
              ui: UserInterface.UserInterface,
              app=None,
              window_style=None,
              persistent_id=None):
     self.ui = ui
     self.app = app
     self.__document_window = self.ui.create_document_window()
     if window_style:
         self.__document_window.window_style = window_style
     self.__persistent_id = persistent_id
     self.__shown = False
     self.__document_window.on_periodic = self.periodic
     self.__document_window.on_queue_task = self.queue_task
     self.__document_window.on_add_task = self.add_task
     self.__document_window.on_clear_task = self.clear_task
     self.__document_window.on_about_to_show = self.about_to_show
     self.__document_window.on_about_to_close = self.about_to_close
     self.__document_window.on_activation_changed = self.activation_changed
     self.__document_window.on_size_changed = self.size_changed
     self.__document_window.on_position_changed = self.position_changed
     self.__document_window.on_refocus_widget = self.refocus_widget
     self.__periodic_queue = Process.TaskQueue()
     self.__periodic_set = Process.TaskSet()
     # 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)
Beispiel #3
0
 def close(self) -> None:
     self.__request_close = False
     self._finish_periodic()  # required to finish periodic operations during tests
     self._close_dialogs()
     self._window_close_event.fire(self)
     self._window_close_event = typing.cast(Event.Event, None)
     self.on_close = None
     Process.close_event_loop(self.__event_loop)
     self.__event_loop = typing.cast(asyncio.AbstractEventLoop, None)
     self.ui.destroy_document_window(self.__document_window)  # close the ui window
     self.__document_window = typing.cast(UserInterface.Window, None)
     self.__periodic_queue = typing.cast(Process.TaskQueue, None)
     self.__periodic_set = typing.cast(Process.TaskSet, None)
     self.__modal_actions = typing.cast(typing.List[Action], None)
     self._close_action = None
     self._page_setup_action = None
     self._print_action = None
     self._quit_action = None
     self._undo_action = None
     self._redo_action = None
     self._cut_action = None
     self._copy_action = None
     self._paste_action = None
     self._delete_action = None
     self._select_all_action = None
     self._minimize_action = None
     self._zoom_action = None
     self._bring_to_front_action = None
     self.parent_window = None
     self.app = None
     Window.count -= 1
Beispiel #4
0
 def deinitialize(self):
     self._close_dialogs()
     Process.close_event_loop(self.__event_loop)
     self.__event_loop = typing.cast(asyncio.AbstractEventLoop, None)
     with open(
             os.path.join(self.ui.get_data_location(), "PythonConfig.ini"),
             'w') as f:
         f.write(sys.prefix + '\n')
     self.ui.close()
Beispiel #5
0
 def __init__(self, document_controller, panel_id, display_name):
     self.__document_controller_weakref = weakref.ref(document_controller)
     self.ui = document_controller.ui
     self.panel_id = panel_id
     self.display_name = display_name
     self.widget = None
     # useful for many panels.
     self.__periodic_task_queue = Process.TaskQueue()
     self.__periodic_task_set = Process.TaskSet()
Beispiel #6
0
 def __init__(self, document_controller: DocumentController.DocumentController, panel_id: str, display_name: str):
     Panel.count += 1
     self.__document_controller_weakref = weakref.ref(document_controller)
     self.ui = document_controller.ui
     self.panel_id = panel_id
     self.display_name = display_name
     self.widget = None  # gets closed by the dock widget
     self.dock_widget = None
     # useful for many panels.
     self.__periodic_task_queue = Process.TaskQueue()
     self.__periodic_task_set = Process.TaskSet()
Beispiel #7
0
    def test_process(self) -> None:
        ts = Process.TaskQueue()
        a = 0
        b = 0

        def aa() -> None:
            nonlocal a
            a += 1

        def bb() -> None:
            nonlocal b
            b += 1

        ts.put(aa)
        ts.put(aa)
        ts.put(bb)

        ts.perform_tasks()

        self.assertEqual(2, a)
        self.assertEqual(1, b)

        ts.put(aa)
        ts.clear_tasks()
        ts.put(aa)
        ts.put(bb)

        ts.perform_tasks()

        self.assertEqual(3, a)
        self.assertEqual(2, b)