Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tjkuson committed Jan 12, 2023
1 parent bbe356a commit 6e6bf7c
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 34 deletions.
25 changes: 24 additions & 1 deletion client/actions/update_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@


class UpdateTable(QAction):
def _on_selection_change(self):
"""Update the metadata when a new row is selected.
This method is called when the selection in the table changes.
"""

# Get the primary key from the first column (assume first column is the pk)
key: int = self.parent().selected_row()[0]

# Each item has a different metadata format; use the current table to method
metadata: tuple[tuple[any], list[str]]
if self.parent().current_table() == "project":
metadata = self.parent().db_view.get_project_metadata(key)
elif self.current_table() == "scan":
metadata = self.parent().db_view.get_scan_metadata(key)
elif self.current_table() == '"user"':
metadata = self.parent().db_view.get_user_metadata(key)
else:
raise NotImplementedError(f"Unknown table {self.parent().current_table()}")

# Update the metadata panel with the new metadata
self.parent().metadata_panel.update_metadata(metadata)

def _update_table(self) -> None:
"""Update table model using SQL command.
Expand Down Expand Up @@ -80,7 +103,7 @@ def _update_table(self) -> None:

# Make the table react to selection changes
self.parent().table_view.selectionModel().selectionChanged.connect(
self.parent().on_selection_changed
self._on_selection_change
)

# Let user sort table by column
Expand Down
20 changes: 0 additions & 20 deletions client/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,3 @@ def selected_row(self) -> tuple[Any, ...]:
row: tuple[Any] = self.table_model.get_row_data(row_index)

return row

def on_selection_changed(self) -> None:
"""Update the metadata when a new row is selected."""

# Get the primary key from the first column (assume first column is the pk)
key: int = self.selected_row()[0]

# Each item has a different metadata format; use the current table to method
metadata: tuple[tuple[any], list[str]]
if self.current_table() == "project":
metadata = self.db_view.get_project_metadata(key)
elif self.current_table() == "scan":
metadata = self.db_view.get_scan_metadata(key)
elif self.current_table() == '"user"':
metadata = self.db_view.get_user_metadata(key)
else:
raise NotImplementedError(f"Unknown table {self.current_table()}")

# Update the metadata panel with the new metadata
self.metadata_panel.update_metadata(metadata)
1 change: 1 addition & 0 deletions client/runners/generic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Generic worker class for running jobs in a separate thread.
"""
from __future__ import annotations

import logging
import sys
Expand Down
2 changes: 2 additions & 0 deletions client/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Base settings.
"""
from __future__ import annotations

from functools import wraps
from pathlib import Path
from typing import TYPE_CHECKING, Any
Expand Down
1 change: 1 addition & 0 deletions client/utils/hash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
File hashing algorithms.
"""
from __future__ import annotations

from hashlib import sha3_384
from typing import TYPE_CHECKING
Expand Down
1 change: 1 addition & 0 deletions client/widgets/dialogue/create_prj.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This window lets a user input and create a new project, which is added to the database
specified by the input connection string.
"""
from __future__ import annotations

import logging
from pathlib import Path
Expand Down
2 changes: 2 additions & 0 deletions client/widgets/dialogue/download_scan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Progress bar dialogue for downloading the scan.
"""
from __future__ import annotations

import logging
from typing import TYPE_CHECKING

Expand Down
1 change: 1 addition & 0 deletions client/widgets/table/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the type hints from the base class even though they are incorrect. This does not affect
the runtime behaviour of the code.
"""
from __future__ import annotations

from datetime import date, datetime
from typing import TYPE_CHECKING, Any
Expand Down
6 changes: 4 additions & 2 deletions client/widgets/thumbnail/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""


from __future__ import annotations

from typing import TYPE_CHECKING

from PySide6.QtCore import QSize, Qt
Expand All @@ -18,8 +20,8 @@
class Thumbnail(QFrame):
"""A widget that scales an image to fill a box while maintaining aspect ratio."""

def __init__(self) -> None:
super().__init__()
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

# Use a layout to prevent the image from being stretched
layout: QVBoxLayout = QVBoxLayout()
Expand Down
105 changes: 94 additions & 11 deletions poetry.lock

Large diffs are not rendered by default.

0 comments on commit 6e6bf7c

Please sign in to comment.