From bd06184b9a0d73d40e9645fdb54815bfad6c7bab Mon Sep 17 00:00:00 2001 From: Luke Davis Date: Sun, 29 Sep 2024 05:42:07 -0400 Subject: [PATCH] Use a new module and class for choosing directory --- addon/globalPlugins/speechLogger/configUI.py | 4 +-- .../speechLogger/slPathSelectionHelper.py | 29 +++++++++++++++++++ buildVars.py | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 addon/globalPlugins/speechLogger/slPathSelectionHelper.py diff --git a/addon/globalPlugins/speechLogger/configUI.py b/addon/globalPlugins/speechLogger/configUI.py index 74e0ee0..76810ca 100644 --- a/addon/globalPlugins/speechLogger/configUI.py +++ b/addon/globalPlugins/speechLogger/configUI.py @@ -17,11 +17,11 @@ import config import ui import globalVars -import gui from gui.settingsDialogs import PANEL_DESCRIPTION_WIDTH from logHandler import log from . import extensionPoint +from .slPathSelectionHelper import SLPathSelectionHelper try: addonHandler.initTranslation() @@ -155,7 +155,7 @@ def makeSettings(self, settingsSizer) -> None: browseButtonLabel: str = _("Browse...") # Translators: The title of the dialog presented when browsing for the log directory. dirChooserTitle: str = _("Select log directory") - dirChooserHelper = gui.guiHelper.PathSelectionHelper(fileGroupBox, browseButtonLabel, dirChooserTitle) + dirChooserHelper = SLPathSelectionHelper(fileGroupBox, browseButtonLabel, dirChooserTitle) directoryEntryControl = fileGroupHelper.addItem(dirChooserHelper) self.logDirectoryEdit = directoryEntryControl.pathControl self.logDirectoryEdit.SetValue(getConf("folder")) diff --git a/addon/globalPlugins/speechLogger/slPathSelectionHelper.py b/addon/globalPlugins/speechLogger/slPathSelectionHelper.py new file mode 100644 index 0000000..0e6fe48 --- /dev/null +++ b/addon/globalPlugins/speechLogger/slPathSelectionHelper.py @@ -0,0 +1,29 @@ +import wx +from gui.dpiScalingHelper import scaleSize +from wx.lib.expando import ExpandoTextCtrl +from gui import guiHelper + + +class SLPathSelectionHelper(guiHelper.PathSelectionHelper): + """ + Abstracts away details for creating a path selection helper. The path selection helper is a textCtrl with a + button in horizontal layout. The Button launches a directory explorer. To get the path selected by the user, use the + `pathControl` property which exposes a wx.TextCtrl. + """ + + def __init__(self, parent: wx.Dialog, buttonText: str, browseForDirectoryTitle: str) -> None: + """ + :param parent: An instance of the parent wx window. EG wx.Dialog + :param buttonText: The text for the button to launch a directory dialog (wx.DirDialog). This is typically 'Browse' + :param browseForDirectoryTitle: The text for the title of the directory dialog (wx.DirDialog) + """ + super().__init__(self) + self._textCtrl = ExpandoTextCtrl( + parent, + size=(scaleSize(250), -1), + style=wx.TE_READONLY, + ) + self._browseButton = wx.Button(parent, label=buttonText) + self._browseForDirectoryTitle = browseForDirectoryTitle + self._browseButton.Bind(wx.EVT_BUTTON, self.onBrowseForDirectory) + self._sizer = associateElements(self._textCtrl, self._browseButton) diff --git a/buildVars.py b/buildVars.py index 31b40f6..92efc67 100644 --- a/buildVars.py +++ b/buildVars.py @@ -25,7 +25,7 @@ def _(arg): # Translators: Long description to be shown for this add-on on add-on information from add-ons manager "addon_description": _("""Logs speech utterances to a file, after the user presses an initiating key. Can also log NVDA remote session speech from the NVDA Remote add-on, to the same or another file. Optionally includes speech from say-all."""), # version - "addon_version": "24.2.500", + "addon_version": "24.2.506", # Author(s) "addon_author": "Luke Davis , James Scholes", # URL for the add-on documentation support