pylance standardization

This commit is contained in:
2026-07-21 00:54:51 -07:00
parent 2b019c1bc0
commit 8b017005c5
20 changed files with 608 additions and 277 deletions
+67 -18
View File
@@ -9,6 +9,8 @@ License: GPL-3.0
import os
import json
from pathlib import Path
from typing import Sequence, Any
from PySide6.QtWidgets import QApplication, QComboBox, QDialog, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QListView, QMessageBox, QPushButton, QScrollArea, QVBoxLayout, QWidget, QFrame, QSpinBox
from PySide6.QtGui import QStandardItemModel, QStandardItem, QPixmap, QIntValidator, QDoubleValidator
from PySide6.QtCore import QEvent, QSize, Qt
@@ -807,7 +809,11 @@ class FlaresBaseWidget(QWidget):
self.image_index_dropdown = None
def _create_multiselect_dropdown(self, items):
def _create_multiselect_dropdown(
self,
items: Sequence[str]
) -> FullClickComboBox:
combo = FullClickComboBox()
combo.setView(QListView())
model = QStandardItemModel()
@@ -874,7 +880,11 @@ class FlaresBaseWidget(QWidget):
# checked.append(item.text())
# return checked
def _get_checked_items(self, combo=None):
def _get_checked_items(
self,
combo: QComboBox | None = None
) -> list[str]:
target = combo if combo is not None else getattr(self, 'participant_dropdown', None)
if target is None or target.model() is None:
@@ -897,7 +907,10 @@ class FlaresBaseWidget(QWidget):
return checked_items
def update_participant_dropdown_label(self, combo=None):
def update_participant_dropdown_label(
self,
combo: QComboBox | int | None = None
) -> None:
"""
Handles label updates for ANY participant dropdown.
If 'combo' is None, it defaults to the standard self.participant_dropdown.
@@ -1142,7 +1155,13 @@ class FlaresBaseWidget(QWidget):
class CrossGroupUIMixin:
def setup_cross_group_ui(self, index_texts, placeholder_text=""):
participant_map: dict[str, str]
def setup_cross_group_ui(
self,
index_texts: Sequence[str],
placeholder_text: str = ""
) -> None:
self.group_to_paths = {}
for file_path, group_name in self.group_dict.items():
@@ -1293,7 +1312,13 @@ class CrossGroupUIMixin:
return file_paths
def get_common_request_data(self, parameterized_indexes, json_location=None, contrast_dfs=None):
def get_common_request_data(
self,
parameterized_indexes: dict[int, list[dict[str, Any]]],
json_location: str | Path | None = None,
contrast_dfs: dict[str, dict[str, Any]] | None = None,
) -> tuple[str | None, list[str], list[str], list[str], list[int], dict[str, Any]] | None:
selected_event = self.event_dropdown.currentText()
if selected_event == "<None Selected>":
selected_event = None
@@ -1412,11 +1437,14 @@ class CrossGroupUIMixin:
class CSVUIMixin:
def setup_csv_ui(self, index_texts):
def setup_csv_ui(
self,
index_texts: Sequence[str]
) -> None:
# Create mappings: file_path -> participant label and dropdown display text
self.participant_map = {} # file_path -> "Participant 1"
self.participant_dropdown_items = [] # "Participant 1 (filename)"
self.participant_map: dict[str, str] = {} # file_path -> "Participant 1"
self.participant_dropdown_items: list[str] = [] # "Participant 1 (filename)"
for i, file_path in enumerate(self.haemo_dict.keys(), start=1):
short_label = f"Participant {i}"
@@ -1428,12 +1456,12 @@ class CSVUIMixin:
self.top_bar = QHBoxLayout()
self.layout.addLayout(self.top_bar)
self.participant_dropdown = self._create_multiselect_dropdown(self.participant_dropdown_items)
self.participant_dropdown: FullClickComboBox = self._create_multiselect_dropdown(self.participant_dropdown_items)
self.participant_dropdown.currentIndexChanged.connect(self.update_participant_dropdown_label)
self.index_texts = index_texts
self.image_index_dropdown = self._create_multiselect_dropdown(self.index_texts)
self.image_index_dropdown: FullClickComboBox = self._create_multiselect_dropdown(self.index_texts)
self.image_index_dropdown.currentIndexChanged.connect(self.update_image_index_dropdown_label)
self.submit_button = QPushButton("Submit")
@@ -1456,13 +1484,20 @@ class CSVUIMixin:
self.showMaximized()
class InterGroupUIMixin:
def setup_inter_group_ui(self, index_texts, placeholder_text=""):
def setup_inter_group_ui(
self,
index_texts: Sequence[str],
placeholder_text: str = ""
) -> None:
self.show_all_events = True
self._updating_checkstates = False
# Create mappings: file_path -> participant label and dropdown display text
self.participant_map = {} # file_path -> "Participant 1"
self.participant_map: dict[str, str] = {} # file_path -> "Participant 1"
self.participant_dropdown_items = [] # "Participant 1 (filename)"
for i, file_path in enumerate(self.haemo_dict.keys(), start=1):
@@ -1525,7 +1560,13 @@ class InterGroupUIMixin:
self.thumb_size = QSize(280, 180)
self.showMaximized()
def get_common_request_data(self, parameterized_indexes, json_location=None, contrast_dfs=None):
def get_common_request_data(
self,
parameterized_indexes: dict[int, list[dict[str, Any]]],
json_location: str | Path | None = None,
contrast_dfs: dict[str, dict[str, Any]] | None = None,
) -> tuple[str | None, list[str], list[int], dict[str, Any]] | None:
selected_event = self.event_dropdown.currentText()
if selected_event == "<None Selected>":
selected_event = None
@@ -1570,7 +1611,7 @@ class InterGroupUIMixin:
dynamic_rois = []
# 1. Check for the JSON file and parse ROI names
if os.path.exists(json_location):
if json_location is not None and os.path.exists(json_location):
try:
with open(json_location, 'r', encoding='utf-8') as f:
regions_data = json.load(f)
@@ -1645,9 +1686,13 @@ class InterGroupUIMixin:
)
class ParticipantUIMixin:
def setup_participant_ui(self, index_texts):
def setup_participant_ui(
self,
index_texts: Sequence[str]
) -> None:
# Create mappings: file_path -> participant label and dropdown display text
self.participant_map = {} # file_path -> "Participant 1"
self.participant_map: dict[str, str] = {} # file_path -> "Participant 1"
self.participant_dropdown_items = [] # "Participant 1 (filename)"
for i, file_path in enumerate(self.haemo_dict.keys(), start=1):
@@ -1694,7 +1739,11 @@ class ParticipantUIMixin:
self.showMaximized()
def get_common_request_data(self, parameterized_indexes):
def get_common_request_data(
self,
parameterized_indexes: dict[int, list[dict[str, Any]]]
) -> tuple[str | None, list[str], list[int], dict[str, Any]] | None:
selected_event = self.event_dropdown.currentText()
if selected_event == "<None Selected>":
selected_event = None