Skip to content

Commit

Permalink
Merge e627f94 into 3f82ab6
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanBurchett authored Jul 28, 2024
2 parents 3f82ab6 + e627f94 commit 7dbadc3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/brailleViewer/brailleViewerGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def _updateGui(self):
"""Ensure all GUI updates happen in one place to create a smooth update, all changes should happen
between freeze and thaw.
"""
gui.guiHelper.enableDarkMode(self)
self.Freeze()
if self._newBraille is not None:
self._brailleOutput.SetValue(self._newBraille)
Expand Down
4 changes: 4 additions & 0 deletions source/gui/configProfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, parent):
self.Sizer = mainSizer
self.profileList.SetFocus()
self.CentreOnScreen()
guiHelper.enableDarkMode(self)

def __del__(self):
ProfilesDialog._instance = None
Expand Down Expand Up @@ -407,6 +408,7 @@ def __init__(self, parent):
mainSizer.Fit(self)
self.Sizer = mainSizer
self.CentreOnScreen()
guiHelper.enableDarkMode(self)

def onTriggerListChoice(self, evt):
trig = self.triggers[self.triggerList.Selection]
Expand Down Expand Up @@ -482,6 +484,8 @@ def __init__(self, parent):
self.Sizer = mainSizer
self.profileName.SetFocus()
self.CentreOnScreen()
# Note: we don't call guiHelper.enableDarkMode() here because wx.RadioBox doesn't support
# changing the foreground color (https://github.com/wxWidgets/Phoenix/issues/1512)

def onOk(self, evt):
confTrigs = config.conf.triggersToProfiles
Expand Down
1 change: 1 addition & 0 deletions source/gui/exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, parent):
self.Sizer = mainSizer
self.actionsList.SetFocus()
self.CentreOnScreen()
guiHelper.enableDarkMode(self)

def onOk(self, evt):
action = [a for a in _ExitAction if a.displayString == self.actionsList.GetStringSelection()][0]
Expand Down
20 changes: 20 additions & 0 deletions source/gui/guiHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, parent):
from contextlib import contextmanager
import weakref
from typing import (
Generator,
Generic,
Optional,
Type,
Expand Down Expand Up @@ -84,6 +85,25 @@ def autoThaw(control: wx.Window):
control.Thaw()


def _getDescendants(widget: wx.Window) -> Generator[wx.Window, None, None]:
yield widget
if hasattr(widget, "GetChildren"):
for child in widget.GetChildren():
for descendant in _getDescendants(child):
yield descendant


def enableDarkMode(widget: wx.Window):
systemAppearance: wx.SystemAppearance = wx.SystemSettings.GetAppearance()
if systemAppearance.IsDark() or systemAppearance.IsUsingDarkBackground():
fgColor, bgColor = "White", "Dark Grey"
else:
fgColor, bgColor = "Black", "White"
for child in _getDescendants(widget):
child.SetBackgroundColour(bgColor)
child.SetForegroundColour(fgColor)


class ButtonHelper(object):
"""Class used to ensure that the appropriate space is added between each button, whether in horizontal or vertical
arrangement. This class should be used for groups of buttons. While it won't cause problems to use this class with a
Expand Down
1 change: 1 addition & 0 deletions source/gui/logViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, parent):

self.refresh()
self.outputCtrl.SetFocus()
gui.guiHelper.enableDarkMode(self)

def refresh(self, evt=None):
# Ignore if log is not initialized
Expand Down
4 changes: 3 additions & 1 deletion source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def __init__(
if resizeable:
self.SetMinSize(self.mainSizer.GetMinSize())
self.CentreOnScreen()
guiHelper.enableDarkMode(self)
if gui._isDebug():
log.debug("Loading %s took %.2f seconds" % (self.__class__.__name__, time.time() - startTime))

Expand Down Expand Up @@ -368,6 +369,7 @@ def __init__(self, parent: wx.Window):
super().__init__(parent)

self._buildGui()
guiHelper.enableDarkMode(self)

if gui._isDebug():
elapsedSeconds = time.time() - startTime
Expand All @@ -391,7 +393,7 @@ def makeSettings(self, sizer: wx.BoxSizer):
raise NotImplementedError

def onPanelActivated(self):
"""Called after the panel has been activated (i.e. de corresponding category is selected in the list of categories).
"""Called after the panel has been activated (i.e. the corresponding category is selected in the list of categories).
For example, this might be used for resource intensive tasks.
Sub-classes should extend this method.
"""
Expand Down
2 changes: 2 additions & 0 deletions source/gui/speechDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def __init__(self, parent, title=_("Edit Dictionary Entry")):
self.setType(speechDictHandler.ENTRY_TYPE_ANYWHERE)
self.patternTextCtrl.SetFocus()
self.Bind(wx.EVT_BUTTON, self.onOk, id=wx.ID_OK)
# Note: don't call guiHelper.enableDarkMode() here because wx.RadioBox doesn't support
# changing the foreground color (https://github.com/wxWidgets/Phoenix/issues/1512)

def getType(self):
typeRadioValue = self.typeRadioBox.GetSelection()
Expand Down
3 changes: 3 additions & 0 deletions source/gui/startupDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, parent):
self.SetSizer(mainSizer)
self.kbdList.SetFocus()
self.CentreOnScreen()
gui.guiHelper.enableDarkMode(self)

def onOk(self, evt):
layout = self.kbdNames[self.kbdList.GetSelection()]
Expand Down Expand Up @@ -220,6 +221,7 @@ def __init__(self, parent):
self.Sizer = mainSizer
mainSizer.Fit(self)
self.CentreOnScreen()
gui.guiHelper.enableDarkMode(self)

def _createLicenseAgreementGroup(self) -> wx.StaticBoxSizer:
# Translators: The label of the license text which will be shown when NVDA installation program starts.
Expand Down Expand Up @@ -326,6 +328,7 @@ def __init__(self, parent):
self.Sizer = mainSizer
mainSizer.Fit(self)
self.CentreOnScreen()
gui.guiHelper.enableDarkMode(self)

def onYesButton(self, evt):
log.debug("Usage stats gathering has been allowed")
Expand Down
1 change: 1 addition & 0 deletions source/pythonConsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def __init__(self, parent):
mainSizer.Add(inputSizer, proportion=1, flag=wx.EXPAND)
self.SetSizer(mainSizer)
mainSizer.Fit(self)
gui.guiHelper.enableDarkMode(self)

self.console = PythonConsole(
outputFunc=self.output,
Expand Down
1 change: 1 addition & 0 deletions source/speechViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, onDestroyCallBack: Callable[[], None]):

# Don't let speech viewer to steal keyboard focus when opened
self.ShowWithoutActivating()
gui.guiHelper.enableDarkMode(self)

def onSessionLockStateChange(self, isNowLocked: bool):
"""
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Unicode CLDR has also been updated.
* NVDA checks daily for add-on updates.
* Only updates within the same channel will be checked (e.g. installed beta add-ons will only notify for updates in the beta channel).
* Added support for the Help Tech Activator Pro displays. (#16668)
* Added support for dark mode. (#16683)

### Changes

Expand Down

0 comments on commit 7dbadc3

Please sign in to comment.