Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions source/gui/guiHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self,parent):
from contextlib import contextmanager

import wx
from wx.lib import scrolledpanel
from wx.lib import scrolledpanel, newevent
from abc import ABCMeta

#: border space to be used around all controls in dialogs
Expand Down Expand Up @@ -159,17 +159,49 @@ class LabeledControlHelper(object):
the two controls together.
Relies on guiHelper.associateElements(), any limitations in guiHelper.associateElements() also apply here.
"""
def __init__(self, parent, labelText, wxCtrlClass, **kwargs):

# When the control is enabled / disabled this event is raised.
# A handler is automatically added to the control to ensure the label is also enabled/disabled.
EnableChanged, EVT_ENABLE_CHANGED = newevent.NewEvent()

def __init__(self, parent: wx.Window, labelText: str, wxCtrlClass: wx.Control, **kwargs):
""" @param parent: An instance of the parent wx window. EG wx.Dialog
@param labelText: The text to associate with a wx control.
@type labelText: string
@param wxCtrlClass: The class to associate with the label, eg: wx.TextCtrl
@type wxCtrlClass: class
@param kwargs: The keyword arguments used to instantiate the wxCtrlClass
"""
object.__init__(self)
self._label = wx.StaticText(parent, label=labelText)
self._ctrl = wxCtrlClass(parent, **kwargs)

class LabelEnableChangedListener(wx.StaticText):
isDestroyed = False
isListening = False

def _onDestroy(self, evt: wx.WindowDestroyEvent):
self.isDestroyed = True

def listenForEnableChanged(self, _ctrl: wx.Window):
self.Bind(wx.EVT_WINDOW_DESTROY, self._onDestroy)
_ctrl.Bind(LabeledControlHelper.EVT_ENABLE_CHANGED, self._onEnableChanged)
self.isListening = True

def _onEnableChanged(self, evt: wx.Event):
if self.isListening and not self.isDestroyed:
self.Enable(evt.isEnabled)

class WxCtrlWithEnableEvnt(wxCtrlClass):
def Enable(self, enable=True):
evt = LabeledControlHelper.EnableChanged(isEnabled=enable)
wx.PostEvent(self, evt)
super().Enable(enable)

def Disable(self):
evt = LabeledControlHelper.EnableChanged(isEnabled=False)
wx.PostEvent(self, evt)
super().Disable()

self._label = LabelEnableChangedListener(parent, label=labelText)
self._ctrl = WxCtrlWithEnableEvnt(parent, **kwargs)
self._label.listenForEnableChanged(self._ctrl)
self._sizer = associateElements(self._label, self._ctrl)

Comment thread
CyrilleB79 marked this conversation as resolved.
Resolved
@property
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ What's New in NVDA
- In Mozilla Firefox and Chromium based browsers, updates to ARIA live regions are now suppressed when reporting of dynamic content changes is disabled. (#9077)
- NVDA will now report "Copied to clipboard" before the copied text. (#6757)
- Presentation of graphical view table in disk management has been improved. (#10048)
- Labels for controls are now disabled (greyed out) when the control is disabled. (#11809)


== Bug Fixes ==
Expand Down