Skip to content

Commit

Permalink
Add Type Annotations for Improved Type Safety in Windows (#2251)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc authored Jul 10, 2024
2 parents bdf37e9 + 18b0521 commit 59558cd
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ def __init__(self, view: AddImagesToDatasetDialog):
super().__init__(view)
self._images = None

def notify(self, n: Notification):
def notify(self, n: Notification) -> None:
try:
if n == Notification.IMAGE_FILE_SELECTED:
self.load_images()
except RuntimeError as err:
self.view.show_exception(str(err), traceback.format_exc())

def load_images(self):
def load_images(self) -> None:
"""
Loads the images from the file path provided by the user.
"""
start_async_task_view(self.view, self.view.parent_view.presenter.model.load_image_stack,
self._on_images_load_done, {'file_path': self.view.path})

def _on_images_load_done(self, task: TaskWorkerThread):
def _on_images_load_done(self, task: TaskWorkerThread) -> None:
"""
Checks if loading images was successful and then triggers the necessary updates.
:param task: The file loading task.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def __init__(self, parent, dataset_id: uuid.UUID, strict_dataset: bool, dataset_
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.accepted.connect(self._on_accepted)

def _on_accepted(self):
def _on_accepted(self) -> None:
self.presenter.notify(Notification.IMAGE_FILE_SELECTED)

def choose_file_path(self):
def choose_file_path(self) -> None:
"""
Select a file in the stack path that we wish to add/replace in the dataset.
"""
Expand Down
2 changes: 1 addition & 1 deletion mantidimaging/gui/windows/image_load_dialog/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def do_update_sample(self, selected_file: str) -> None:
if related_group:
self.update_field_with_filegroup(file_info, related_group)

def update_field_with_filegroup(self, file_info: FILE_TYPES, file_group: FilenameGroup):
def update_field_with_filegroup(self, file_info: FILE_TYPES, file_group: FilenameGroup) -> None:
"""
Update the field with the given file group by finding all files in the group and setting them in the field.
Expand Down
2 changes: 1 addition & 1 deletion mantidimaging/gui/windows/move_stack_dialog/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, parent, origin_dataset_id: uuid.UUID, stack_id: uuid.UUID, or
self.datasetSelector.subscribe_to_main_window(parent)
self._on_destination_dataset_changed()

def accept(self):
def accept(self) -> None:
self.presenter.notify(Notification.ACCEPTED)
self.close()

Expand Down
14 changes: 7 additions & 7 deletions mantidimaging/gui/windows/welcome_screen/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def __init__(self, parent=None, view=None):

self.do_set_up()

def do_set_up(self):
def do_set_up(self) -> None:
self.view.set_version_label(f"Mantid Imaging {versions.get_version()}")
self.set_up_links()
self.set_up_show_at_start()
self.check_issues()

def show(self):
def show(self) -> None:
self.view.show()

@staticmethod
Expand All @@ -55,26 +55,26 @@ def show_today():
else:
return show_at_start

def set_up_links(self):
def set_up_links(self) -> None:
for link_name, url in WELCOME_LINKS:
self.add_link(link_name, url)

def add_link(self, link_name, url):
def add_link(self, link_name: str, url: str) -> None:
rich_text = f'<a href="{url}">{link_name}</a>'
self.view.add_link(rich_text, self.link_count)
self.link_count += 1

def set_up_show_at_start(self):
def set_up_show_at_start(self) -> None:
show_at_start = WelcomeScreenPresenter.show_at_start_enabled()
self.view.set_show_at_start(show_at_start)
self.show_at_start_changed()

def show_at_start_changed(self):
def show_at_start_changed(self) -> None:
show_at_start = self.view.get_show_at_start()
self.settings.setValue("welcome_screen/show_at_start", show_at_start)
self.settings.setValue("welcome_screen/last_run_version", versions.get_version())

def check_issues(self):
def check_issues(self) -> None:
issues = []
if versions.needs_update():
msg, detailed = versions.conda_update_message()
Expand Down
10 changes: 5 additions & 5 deletions mantidimaging/gui/windows/welcome_screen/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ def __init__(self, parent, presenter):
self.show_at_start.stateChanged.connect(presenter.show_at_start_changed)
self.ok_button.clicked.connect(self.close)

def get_show_at_start(self):
def get_show_at_start(self) -> None:
return self.show_at_start.isChecked()

def set_show_at_start(self, checked):
def set_show_at_start(self, checked: bool) -> None:
self.show_at_start.setChecked(checked)

def set_version_label(self, contents):
def set_version_label(self, contents: str) -> None:
self.version_label.setText(contents)

def add_link(self, label, row):
def add_link(self, label: str, row: int) -> None:
link_label = QLabel(label)
link_label.setOpenExternalLinks(True)
self.link_box_layout.addWidget(link_label, row, 0)

def add_issues(self, contents):
def add_issues(self, contents: str) -> None:
self.issue_box.setVisible(True)
issues_label = QLabel(contents)
issues_label.setOpenExternalLinks(True)
Expand Down
6 changes: 3 additions & 3 deletions mantidimaging/gui/windows/wizard/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def __init__(self, parent: MainWindowView):
self.handle_stack_change()
self.show()

def show(self):
def show(self) -> None:
self.view.show()

def populate(self):
def populate(self) -> None:
for stage in self.wizard_data["stages"]:
self.view.add_stage(stage["name"])
for step in stage["steps"]:
self.view.add_step(stage["name"], step)

def run_action(self, action: str):
def run_action(self, action: str) -> None:
if action == "load":
self.main_window_presenter.wizard_action_load()

Expand Down

0 comments on commit 59558cd

Please sign in to comment.