Commit 1d764fca authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'rel/0.12.1' into 'v0.12'

Rel/0.12.1

See merge request fsl/fsleyes/widgets!75
parents 206b63c5 200eacbf
......@@ -2,6 +2,17 @@ This document contains the ``fsleyes-widgets`` release history in reverse
chronological order.
0.12.1 (Wednesday April 21st 2021)
----------------------------------
Changed
^^^^^^^
* Removed some hard-coded colours to improve support for dark themes.
0.12.0 (Tuesday April 20th 2021)
--------------------------------
......
......@@ -18,7 +18,7 @@ This file is used to store the current ``fsleyes-widgets`` version.
"""
__version__ = '0.12.0'
__version__ = '0.12.1'
from fsleyes_widgets.utils import (WX_PYTHON, # noqa
......
......@@ -96,10 +96,11 @@ class SimpleMessageDialog(wx.Dialog):
self.__sizer.Add(self.__message,
border=25,
proportion=1,
flag=wx.EXPAND | wx.CENTRE | wx.ALL)
flag=wx.CENTRE | wx.ALL)
self.SetTransparent(240)
self.SetBackgroundColour((225, 225, 255))
self.SetBackgroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK))
self.SetSizer(self.__sizer)
......@@ -714,7 +715,9 @@ class FSLDirDialog(wx.Dialog):
label='Hint: Press \u2318+\u21e7+G in the file '
'dialog to manually type in a location.')
self.__hint.SetForegroundColour('#888888')
self.__hint.SetForegroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
.ChangeLightness(75))
self.__contentSizer.Insert(2, self.__hint, flag=wx.EXPAND)
self.__contentSizer.Insert(3, (1, 20))
......@@ -882,7 +885,9 @@ class CheckBoxMessageDialog(wx.Dialog):
if hintText is not None:
self.__hint = wx.StaticText(self, label=hintText)
self.__hint.SetForegroundColour('#888888')
self.__hint.SetForegroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
.ChangeLightness(75))
else:
self.__hint = None
......
......@@ -80,20 +80,29 @@ class EditableListBox(wx.Panel):
functionality. This implementation supports single selection only.
"""
_selectedFG = '#000000'
"""Default foreground colour for the currently selected item."""
_selectedFG = None
"""Default foreground colour for the currently selected item. Initialised
in :meth:`__init__` to a default based on the system appearance.
"""
_defaultFG = '#000000'
"""Default foreground colour for unselected items."""
_defaultFG = None
"""Default foreground colour for unselected items. Initialised
in :meth:`__init__` to a default based on the system appearance.
"""
_selectedBG = '#cdcdff'
"""Background colour for the currently selected item."""
_selectedBG = None
"""Background colour for the currently selected item. Initialised
in :meth:`__init__` to a default based on the system appearance.
"""
_defaultBG = '#FFFFFF'
"""Background colour for the unselected items."""
_defaultBG = None
"""Background colour for the unselected items. Initialised
in :meth:`__init__` to a default based on the system appearance.
"""
def __init__(
......@@ -128,6 +137,21 @@ class EditableListBox(wx.Panel):
wx.Panel.__init__(self, parent, style=wx.WANTS_CHARS)
defaultfg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOXTEXT)
defaultbg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
selectfg = wx.SystemSettings.GetColour(
wx.SYS_COLOUR_LISTBOXHIGHLIGHTTEXT)
selectbg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
if EditableListBox._selectedFG is None:
EditableListBox._selectedFG = selectfg
if EditableListBox._selectedBG is None:
EditableListBox._selectedBG = selectbg
if EditableListBox._defaultFG is None:
EditableListBox._defaultFG = defaultfg
if EditableListBox._defaultBG is None:
EditableListBox._defaultBG = defaultbg
reverseOrder = style & ELB_REVERSE
addScrollbar = not (style & ELB_NO_SCROLL)
addSupport = not (style & ELB_NO_ADD)
......@@ -242,9 +266,6 @@ class EditableListBox(wx.Panel):
self.__scrollUp .Enable(False)
self.__scrollDown.Enable(False)
self.__scrollUp .SetBackgroundColour('#e0e0e0')
self.__scrollDown.SetBackgroundColour('#e0e0e0')
self.__scrollUp .Bind(wx.EVT_LEFT_UP, self.__onScrollButton)
self.__scrollDown.Bind(wx.EVT_LEFT_UP, self.__onScrollButton)
......@@ -1309,7 +1330,7 @@ class EditableListBox(wx.Panel):
(self.__selection != self.GetCount() - 1))
class _ListItem(object):
class _ListItem:
"""Internal class used to represent items in the list."""
def __init__(self,
......
......@@ -77,7 +77,7 @@ class Notebook(wx.Panel):
self.__textColour = None
self.__defaultColour = None
self.__disabledTextColour = None
self.__selectColour = '#ffffff'
self.__selectColour = None
self.__buttonPanel = wx.Panel(self)
self.__sizer = wx.BoxSizer(invbtnorient)
self.__buttonSizer = wx.BoxSizer(btnorient)
......@@ -113,6 +113,9 @@ class Notebook(wx.Panel):
self.__buttons = []
self.__selected = None
# initialise default values for colours
self.SetButtonColours()
@property
def pages(self):
......@@ -181,10 +184,15 @@ class Notebook(wx.Panel):
:arg selected: Selected background colour.
"""
text = kwargs.pop('text', None)
disabledText = kwargs.pop('disabledText', None)
default = kwargs.pop('default', None)
selected = kwargs.pop('selected', '#ffffff')
defaultbg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE)
selectbg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
defaultfg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT)
selectfg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT)
text = kwargs.pop('text', selectfg)
disabledText = kwargs.pop('disabledText', defaultfg)
default = kwargs.pop('default', defaultbg)
selected = kwargs.pop('selected', selectbg)
self.__textColour = text
self.__disabledTextColour = disabledText
......
......@@ -11,16 +11,10 @@ some text, oriented either horizontally or vertically.
import wx
import fsleyes_widgets as fw
if fw.wxFlavour() == fw.WX_PHOENIX: TextPanelBase = wx.Panel
else: TextPanelBase = wx.PyPanel
class TextPanel(TextPanelBase):
class TextPanel(wx.Panel):
"""A :class:`wx.PyPanel` which may be used to display a string of
text, oriented either horizotnally or vertically.
text, oriented either horizontally or vertically.
"""
def __init__(self, parent, text=None, orient=wx.HORIZONTAL, **kwargs):
......@@ -37,7 +31,7 @@ class TextPanel(TextPanelBase):
All other arguments are passed through to ``wx.Panel.__init__`` .
"""
TextPanelBase.__init__(self, parent, **kwargs)
super().__init__(parent, **kwargs)
self.Bind(wx.EVT_PAINT, self.Draw)
self.Bind(wx.EVT_SIZE, self.__onSize)
......
......@@ -19,18 +19,48 @@
"""
import colorsys
import logging
import random
import wx
import wx.lib.newevent as wxevent
import wx.lib.newevent as wxevent
import numpy as np
import matplotlib.colors as mplcolors
from . import autotextctrl as atc
import fsleyes_widgets.autotextctrl as atc
log = logging.getLogger(__name__)
def complementary_colour(rgb):
"""Given a RGB colour, estimates a colour which complements it. Used
by the :class:`StaticTextTag` class to generate a foreground (text) colour
for a specific background colour.
Taken from the FSLeyes source code (fsleyes.colourmaps.complementaryColour)
"""
# if matplotlib doesn't recognise the colour,
# assume it is a sequence of numbers in the
# range [0, 255], and convert it to a sequence
# in the range [0, 1]
if not mplcolors.is_color_like(rgb):
rgb = np.array(rgb) / 255
else:
rgb = mplcolors.to_rgb(rgb)
h, l, s = colorsys.rgb_to_hls(*(rgb[:3]))
nh = 1.0 - h
nl = 1.0 - l
ns = s
if abs(nl - l) < 0.3:
if l > 0.5: nl = 0.0
else: nl = 1.0
nr, ng, nb = colorsys.hls_to_rgb(nh, nl, ns)
return mplcolors.to_hex((nr, ng, nb))
class StaticTextTag(wx.Panel):
"""The ``StaticTextTag`` class is a ``wx.Panel`` which contains a
``StaticText`` control, and a *close* button. The displayed text
......@@ -87,7 +117,6 @@ class StaticTextTag(wx.Panel):
self .SetBackgroundColour(bgColour)
self .SetBorderColour( borderColour)
self.__closeBtn.SetForegroundColour('#404040')
self.SetText(text)
self.__closeBtn.Bind(wx.EVT_LEFT_UP, self.__onCloseButton)
......@@ -121,10 +150,18 @@ class StaticTextTag(wx.Panel):
def SetBackgroundColour(self, colour):
"""Sets the background colour of this ``StaticTextTag``. """
"""Sets the background colour of this ``StaticTextTag``.
Also automatically sets the foreground (text) colour to a
complementary colour.
"""
fgColour = complementary_colour(colour)
wx.Panel.SetBackgroundColour(self, colour)
self.__text .SetForegroundColour(fgColour)
self.__text .SetBackgroundColour(colour)
self.__closeBtn.SetForegroundColour(fgColour)
self.__closeBtn.SetBackgroundColour(colour)
self.__bgColour = colour
......
......@@ -20,8 +20,8 @@ import wx
def textOverlay(target,
text,
box=True,
bgColour=(205, 205, 255),
fgColour=(0, 0, 0)):
bgColour=None,
fgColour=None):
"""Shows the given ``text`` on the given ``target``.
:arg target: ``wx.Window`` object
......@@ -36,6 +36,11 @@ def textOverlay(target,
:arg fgColour: Colour to draw the text in
"""
if bgColour is None:
bgColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOBK)
if fgColour is None:
fgColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT)
dc = wx.ClientDC(target)
w, h = dc.GetSize().Get()
w = dc.DeviceToLogicalX(w)
......
......@@ -103,30 +103,40 @@ class WidgetGrid(wx.ScrolledWindow):
"""
_defaultBorderColour = '#000000'
_defaultBorderColour = None
"""The colour of border a border which is shown around every cell in the
grid.
grid. Initialised in :meth:`__init__`.
"""
_defaultOddColour = '#ffffff'
"""Background colour for cells on odd rows."""
_defaultOddColour = None
"""Background colour for cells on odd rows.
Initialised in :meth:`__init__`.
"""
_defaultEvenColour = '#eeeeee'
"""Background colour for cells on even rows."""
_defaultEvenColour = None
"""Background colour for cells on even rows.
Initialised in :meth:`__init__`.
"""
_defaultLabelColour = '#dddddd'
"""Background colour for row and column labels."""
_defaultLabelColour = None
"""Background colour for row and column labels.
Initialised in :meth:`__init__`.
"""
_defaultSelectedColour = '#cdcdff'
"""Background colour for selected cells. """
_defaultSelectedColour = None
"""Background colour for selected cells.
Initialised in :meth:`__init__`.
"""
_defaultDragColour = '#ffcdcd'
"""Background colour for columns being dragged. """
_defaultDragColour = None
"""Background colour for columns being dragged.
Initialised in :meth:`__init__`.
"""
def __init__(self, parent, style=None):
......@@ -140,6 +150,27 @@ class WidgetGrid(wx.ScrolledWindow):
and :data:`WG_DRAGGABLE_COLUMNS`.
"""
border = wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVEBORDER)
odd = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
even = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)\
.ChangeLightness(90)
label = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
select = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
drag = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHT)
if WidgetGrid._defaultBorderColour is None:
WidgetGrid._defaultBorderColour = border
if WidgetGrid._defaultOddColour is None:
WidgetGrid._defaultOddColour = odd
if WidgetGrid._defaultEvenColour is None:
WidgetGrid._defaultEvenColour = even
if WidgetGrid._defaultLabelColour is None:
WidgetGrid._defaultLabelColour = label
if WidgetGrid._defaultSelectedColour is None:
WidgetGrid._defaultSelectedColour = select
if WidgetGrid._defaultDragColour is None:
WidgetGrid._defaultDragColour = drag
if style is None:
style = wx.HSCROLL | wx.VSCROLL
......
......@@ -9,13 +9,11 @@ of widgets.
"""
from collections import OrderedDict
import wx
import wx.lib.newevent as wxevent
import wx.lib.scrolledpanel as scrolledpanel
from . import togglepanel
import fsleyes_widgets.togglepanel as togglepanel
class WidgetList(scrolledpanel.ScrolledPanel):
......@@ -50,16 +48,22 @@ class WidgetList(scrolledpanel.ScrolledPanel):
"""
_defaultOddColour = '#eaeaea'
"""Background colour for widgets on odd rows. """
_defaultOddColour = None
"""Background colour for widgets on odd rows.
Iniitalised in :meth:`__init__`.
"""
_defaultEvenColour = '#ffffff'
"""Background colour for widgets on even rows. """
_defaultEvenColour = None
"""Background colour for widgets on even rows.
Iniitalised in :meth:`__init__`.
"""
_defaultGroupColour = '#cdcdff'
"""Border and title background colour for widget groups. """
_defaultGroupColour = None
"""Border and title background colour for widget groups.
Iniitalised in :meth:`__init__`.
"""
def __init__(self, parent, style=0, minHeight=-1):
......@@ -69,13 +73,25 @@ class WidgetList(scrolledpanel.ScrolledPanel):
:arg style: Passed through to ``wx.ScrolledPanel.__init__``
:arg minHeight: Minimum height of each row
"""
odd = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
even = odd.ChangeLightness(90)
group = odd
if WidgetList._defaultOddColour is None:
WidgetList._defaultOddColour = odd
if WidgetList._defaultEvenColour is None:
WidgetList._defaultEvenColour = even
if WidgetList._defaultGroupColour is None:
WidgetList._defaultGroupColour = group
self.__minHeight = minHeight
self.__widgSizer = wx.BoxSizer(wx.VERTICAL)
self.__sizer = wx.BoxSizer(wx.VERTICAL)
self.__groupSizer = wx.BoxSizer(wx.VERTICAL)
self.__widgets = OrderedDict()
self.__groups = OrderedDict()
self.__widgets = {}
self.__groups = {}
self.__oddColour = WidgetList._defaultOddColour
self.__evenColour = WidgetList._defaultEvenColour
......@@ -95,7 +111,6 @@ class WidgetList(scrolledpanel.ScrolledPanel):
scrolledpanel.ScrolledPanel.__init__(self, parent)
self.SetSizer(self.__sizer)
self.SetBackgroundColour((255, 255, 255))
self.SetupScrolling()
self.SetAutoLayout(1)
......@@ -524,7 +539,7 @@ class WidgetList(scrolledpanel.ScrolledPanel):
self.__refresh()
class _Widget(object):
class _Widget:
"""The ``_Widget`` class is used internally by the :class:`WidgetList`
to organise references to each widget in the list.
"""
......@@ -547,12 +562,6 @@ class _Widget(object):
self.panel.SetBackgroundColour(colour)
self.label.SetBackgroundColour(colour)
if isinstance(self.widget, wx.Sizer):
for c in self.widget.GetChildren():
c.GetWindow().SetBackgroundColour(colour)
else:
self.widget.SetBackgroundColour(colour)
def SetTooltip(self, tooltip):
......@@ -584,7 +593,7 @@ class _Widget(object):
self.widget.Destroy()
class _Group(object):
class _Group:
"""The ``_Group`` class is used internally by :class:`WidgetList`
instances to represent groups of widgets that are in the list.
"""
......@@ -603,7 +612,7 @@ class _Group(object):
self.colPanel = colPanel
self.widgPanel = widgPanel
self.sizer = sizer
self.widgets = OrderedDict()
self.widgets = {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment