From d3e1f95ad97e9b2e3b55882221f0331bd616ea17 Mon Sep 17 00:00:00 2001 From: zacsimile Date: Thu, 18 Apr 2024 16:46:08 +0200 Subject: [PATCH 1/4] Dark mode options for wx --- traitsui/wx/constants.py | 47 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/traitsui/wx/constants.py b/traitsui/wx/constants.py index e9923f2cd..6787d126a 100644 --- a/traitsui/wx/constants.py +++ b/traitsui/wx/constants.py @@ -20,37 +20,60 @@ #: Define platform and wx version constants: is_mac = sys.platform == "darwin" +is_dark = wx.SystemSettings.GetAppearance().IsDark() #: Default dialog title DefaultTitle = "Edit properties" #: Color of valid input -OKColor = wx.WHITE +# Alternative: OKColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK) +if is_dark: + OKColor = wx.BLACK +else: + OKColor = wx.WHITE #: Color to highlight input errors -ErrorColor = wx.Colour(255, 192, 192) +if is_dark: + ErrorColor = wx.Colour(0xcf, 0x66, 0x79) +else: + ErrorColor = wx.Colour(255, 192, 192) + #: Color for background of read-only fields -ReadonlyColor = wx.Colour(244, 243, 238) +if is_dark: + ReadonlyColor = wx.Colour(22, 22, 24) +else: + ReadonlyColor = wx.Colour(244, 243, 238) #: Color for background of fields where objects can be dropped -DropColor = wx.Colour(215, 242, 255) +if is_dark: + DropColor = wx.Colour(94, 131, 167) +else: + DropColor = wx.Colour(215, 242, 255) #: Color for an editable field -EditableColor = wx.WHITE +EditableColor = OKColor #: Color for background of windows (like dialog background color) if is_mac: - WindowColor = wx.Colour(232, 232, 232) - BorderedGroupColor = wx.Colour(224, 224, 224) + # Alternative: WindowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) + if is_dark: + WindowColor = wx.Colour(72, 72, 72) + BorderedGroupColor = wx.Colour(64, 64, 64) + else: + WindowColor = wx.Colour(232, 232, 232) + BorderedGroupColor = wx.Colour(224, 224, 224) else: WindowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) #: Default colour for table foreground -TableCellColor = wx.BLACK +if is_dark: + TableCellColor = wx.WHITE +else: + TableCellColor = wx.BLACK #: Default colour for table background -TableCellBackgroundColor = wx.WHITE +TableCellBackgroundColor = OKColor #: Default colour for table background TableReadOnlyBackgroundColor = ReadonlyColor @@ -65,7 +88,11 @@ TableSelectionTextColor = TableCellColor #: Default background colour for table selection (light blue) -TableSelectionBackgroundColor = wx.Colour(173, 216, 230) +# Alternative: wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) +if is_dark: + TableSelectionBackgroundColor = wx.Colour(48, 78, 117) +else: + TableSelectionBackgroundColor = wx.Colour(173, 216, 230) #: Standard width of an image bitmap standard_bitmap_width = 120 From d9b6d4980a75c598b61f3528014aabe26a7cc72a Mon Sep 17 00:00:00 2001 From: zacsimile Date: Thu, 25 Apr 2024 10:04:49 +0200 Subject: [PATCH 2/4] Tweaks --- traitsui/wx/constants.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/traitsui/wx/constants.py b/traitsui/wx/constants.py index 6787d126a..e610486d5 100644 --- a/traitsui/wx/constants.py +++ b/traitsui/wx/constants.py @@ -26,11 +26,7 @@ DefaultTitle = "Edit properties" #: Color of valid input -# Alternative: OKColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK) -if is_dark: - OKColor = wx.BLACK -else: - OKColor = wx.WHITE +OKColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK) #: Color to highlight input errors if is_dark: @@ -56,13 +52,7 @@ #: Color for background of windows (like dialog background color) if is_mac: - # Alternative: WindowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND) - if is_dark: - WindowColor = wx.Colour(72, 72, 72) - BorderedGroupColor = wx.Colour(64, 64, 64) - else: - WindowColor = wx.Colour(232, 232, 232) - BorderedGroupColor = wx.Colour(224, 224, 224) + WindowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW) else: WindowColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_MENUBAR) @@ -70,7 +60,7 @@ if is_dark: TableCellColor = wx.WHITE else: - TableCellColor = wx.BLACK + TableCellColor = wx.Colour(23,23,23) #: Default colour for table background TableCellBackgroundColor = OKColor @@ -87,12 +77,8 @@ #: Default foreground colour for table selection TableSelectionTextColor = TableCellColor -#: Default background colour for table selection (light blue) -# Alternative: wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) -if is_dark: - TableSelectionBackgroundColor = wx.Colour(48, 78, 117) -else: - TableSelectionBackgroundColor = wx.Colour(173, 216, 230) +#: Default background colour for table selection +TableSelectionBackgroundColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT) #: Standard width of an image bitmap standard_bitmap_width = 120 From c0e8b37c29676796dae22ba9686a9a2cee653053 Mon Sep 17 00:00:00 2001 From: zacsimile Date: Thu, 25 Apr 2024 10:06:32 +0200 Subject: [PATCH 3/4] Revert one --- traitsui/wx/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traitsui/wx/constants.py b/traitsui/wx/constants.py index e610486d5..f53041629 100644 --- a/traitsui/wx/constants.py +++ b/traitsui/wx/constants.py @@ -60,7 +60,7 @@ if is_dark: TableCellColor = wx.WHITE else: - TableCellColor = wx.Colour(23,23,23) + TableCellColor = wx.BLACK #: Default colour for table background TableCellBackgroundColor = OKColor From 1fbd6abc5f63c3323580034f9e449b7ee0adb673 Mon Sep 17 00:00:00 2001 From: zacsimile Date: Thu, 25 Apr 2024 10:09:45 +0200 Subject: [PATCH 4/4] Better for light mode --- traitsui/wx/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traitsui/wx/constants.py b/traitsui/wx/constants.py index f53041629..3b4590500 100644 --- a/traitsui/wx/constants.py +++ b/traitsui/wx/constants.py @@ -26,7 +26,7 @@ DefaultTitle = "Edit properties" #: Color of valid input -OKColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK) +OKColor = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW) #: Color to highlight input errors if is_dark: