From b96ab8e4669893babbcbd4a0bfbb80f245d39194 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 24 Jan 2021 18:11:14 -0800 Subject: [PATCH] SPL track items/annotations: annotate SPL track item class methods across base class and subclasses. Re #155. Annotate class methods for SPL track item class and derivatives. This mostly concerns indexOf method, and for Studio version, additoinal methods. --- addon/appModules/splcreator.py | 6 +++--- addon/appModules/splstudio/__init__.py | 12 ++++++------ addon/appModules/tracktool.py | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/addon/appModules/splcreator.py b/addon/appModules/splcreator.py index 8b9628f7c..62249b30e 100755 --- a/addon/appModules/splcreator.py +++ b/addon/appModules/splcreator.py @@ -6,7 +6,7 @@ # #155 (21.03): remove __future__ import when NVDA runs under Python 3.10. from __future__ import annotations -from typing import Any +from typing import Any, Optional import appModuleHandler import addonHandler import scriptHandler @@ -40,14 +40,14 @@ class SPLCreatorItem(SPLTrackItem): """An entry in SPL Creator (mostly tracks). """ - def indexOf(self, header): + def indexOf(self, header: str) -> Optional[int]: try: return indexOf(self.appModule.productVersion).index(header) except ValueError: return None @property - def exploreColumns(self): + def exploreColumns(self) -> list[str]: return splconfig.SPLConfig["General"]["ExploreColumnsCreator"] diff --git a/addon/appModules/splstudio/__init__.py b/addon/appModules/splstudio/__init__.py index 0ca27d117..17c2b5862 100644 --- a/addon/appModules/splstudio/__init__.py +++ b/addon/appModules/splstudio/__init__.py @@ -143,7 +143,7 @@ def _getColumnContentRaw(self, index): # #103: provide an abstract index of function. @abstractmethod - def indexOf(self, columnHeader): + def indexOf(self, columnHeader: str) -> Optional[int]: return None @scriptHandler.script(gesture="kb:control+alt+home") @@ -291,7 +291,7 @@ def script_select(self, gesture): # 8.0: Make this a public function. # #109 (19.08): now standardized around this function. # #142 (20.09): do not ignore Status column (0) just because it is the name of the track as reported by MSAA. - def indexOf(self, columnHeader): + def indexOf(self, columnHeader: str) -> Optional[int]: try: columnHeaders = ["Status"] + splconfig._SPLDefaults["ColumnAnnouncement"]["ColumnOrder"] return columnHeaders.index(columnHeader) @@ -344,7 +344,7 @@ def doAction(self, index=None): # A convenience method that calls column content getter for a list of columns. # Readable flag will transform None into an empty string, suitable for output. # #61 (18.07): readable flag will become a string parameter to be used in columns viewer. - def _getColumnContents(self, columns=None, readable=False): + def _getColumnContents(self, columns: Optional[list[int]] = None, readable: bool = False) -> list[Optional[str]]: if columns is None: columns = list(range(18)) columnContents = [self._getColumnContentRaw(col) for col in columns] @@ -391,7 +391,7 @@ def _moveToRow(self, row): # Overlay class version of Columns Explorer. @property - def exploreColumns(self): + def exploreColumns(self) -> list[str]: return splconfig.SPLConfig["General"]["ExploreColumns"] # Toggle screen column order. @@ -418,7 +418,7 @@ def script_toggleScreenColumnOrder(self, gesture): # Track comment announcer. # Levels indicate what should be done. # 0 indicates reportFocus, subsequent levels indicate script repeat count+1. - def announceTrackComment(self, level): + def announceTrackComment(self, level: int) -> None: filename = self._getColumnContentRaw(self.indexOf("Filename")) if filename is not None and filename in splconfig.trackComments: if level == 0: @@ -449,7 +449,7 @@ def announceTrackComment(self, level): ui.message(_("Comments cannot be added to this kind of track")) # A proxy function to call the track comments entry dialog. - def _trackCommentsEntry(self, filename, comment): + def _trackCommentsEntry(self, filename: str, comment: str) -> None: dlg = wx.TextEntryDialog( gui.mainFrame, _("Track comment"), # Translators: The title of the track comments dialog. diff --git a/addon/appModules/tracktool.py b/addon/appModules/tracktool.py index 47e49b580..d6fd9b200 100755 --- a/addon/appModules/tracktool.py +++ b/addon/appModules/tracktool.py @@ -9,6 +9,7 @@ # #155 (21.03): remove __future__ import when NVDA runs under Python 3.10. from __future__ import annotations +from typing import Optional import appModuleHandler import addonHandler import tones @@ -47,14 +48,14 @@ def reportFocus(self): tones.beep(550, 100) super(TrackToolItem, self).reportFocus() - def indexOf(self, header): + def indexOf(self, header: str) -> Optional[int]: try: return indexOf(self.appModule.productVersion).index(header) except ValueError: return None @property - def exploreColumns(self): + def exploreColumns(self) -> list[str]: return splconfig.SPLConfig["General"]["ExploreColumnsTT"]