Skip to content

Commit 30240b7

Browse files
author
Adam Duskett
committed
add dark mode compatibility
Currently, if a system is in dark mode, the cell text is unreadable because the cell background, highlight, and text color are permanently set to white. Add a new method setCellTheme to fix the above issue. - Set the text colour to WHITE if the system is in dark mode, otherwise BLACK - Set the cell background color equal to the window background color.
1 parent dee2860 commit 30240b7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/objdictgen/ui/subindextable.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ def SetValue(self, row, col, value):
165165
value = "None"
166166
self.data[row][colname] = value
167167

168+
def setCellTheme(self, row, col, grid):
169+
system_appearance = wx.SystemSettings.GetAppearance()
170+
background_colour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
171+
text_colour = wx.WHITE if system_appearance.IsDark() else wx.BLACK
172+
grid.SetCellBackgroundColour(row, col, background_colour)
173+
grid.SetCellTextColour(row, col, text_colour)
174+
168175
def ResetView(self, grid):
169176
"""
170177
(wx.grid.Grid) -> Reset the grid view. Call this to
@@ -274,8 +281,7 @@ def _updateColAttrs(self, grid):
274281

275282
grid.SetCellEditor(row, col, editor)
276283
grid.SetCellRenderer(row, col, renderer)
277-
278-
grid.SetCellBackgroundColour(row, col, wx.WHITE)
284+
self.setCellTheme(row, col, grid)
279285

280286
def SetData(self, data):
281287
self.data = data

0 commit comments

Comments
 (0)