Commit 014bf6db authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'enh/notebook_imagepanel' into 'master'

Enh/notebook imagepanel

See merge request fsl/fsleyes/widgets!27
parents 31525f82 afe1dc42
......@@ -31,8 +31,6 @@ if [[ -f /.dockerenv ]]; then
if [[ "$CI_PROJECT_PATH" == "$UPSTREAM_PROJECT" ]]; then
echo "$SSH_PRIVATE_KEY_DOC_DEPLOY" > $HOME/.ssh/id_doc_deploy;
echo "$SSH_PRIVATE_KEY_CONDA_DEPLOY" > $HOME/.ssh/id_conda_deploy;
echo "$SSH_PRIVATE_KEY_CONDA_INDEX" > $HOME/.ssh/id_conda_index;
fi;
chmod go-rwx $HOME/.ssh/id_*;
......@@ -41,10 +39,10 @@ if [[ -f /.dockerenv ]]; then
if [[ "$CI_PROJECT_PATH" == "$UPSTREAM_PROJECT" ]]; then
ssh-add $HOME/.ssh/id_doc_deploy;
ssh-add $HOME/.ssh/id_conda_deploy;
fi
echo "$SSH_SERVER_HOSTKEYS" > $HOME/.ssh/known_hosts;
ssh-keyscan ${UPSTREAM_URL##*@} >> $HOME/.ssh/known_hosts;
ssh-keyscan ${DOC_HOST##*@} >> $HOME/.ssh/known_hosts;
touch $HOME/.ssh/config;
......@@ -57,16 +55,6 @@ if [[ -f /.dockerenv ]]; then
echo " User ${DOC_HOST%@*}" >> $HOME/.ssh/config;
echo " IdentityFile $HOME/.ssh/id_doc_deploy" >> $HOME/.ssh/config;
echo "Host condadeploy" >> $HOME/.ssh/config;
echo " HostName ${CONDA_HOST##*@}" >> $HOME/.ssh/config;
echo " User ${CONDA_HOST%@*}" >> $HOME/.ssh/config;
echo " IdentityFile $HOME/.ssh/id_conda_deploy" >> $HOME/.ssh/config;
echo "Host condaindex" >> $HOME/.ssh/config;
echo " HostName ${CONDA_HOST##*@}" >> $HOME/.ssh/config;
echo " User ${CONDA_HOST%@*}" >> $HOME/.ssh/config;
echo " IdentityFile $HOME/.ssh/id_conda_index" >> $HOME/.ssh/config;
echo "Host *" >> $HOME/.ssh/config;
echo " IdentitiesOnly yes" >> $HOME/.ssh/config;
......
......@@ -2,6 +2,19 @@ This document contains the ``fsleyes-widgets`` release history in reverse
chronological order.
0.7.0 (Sunday October 21st 2018)
--------------------------------
Added
^^^^^
* The :class:`.Notebook` class allows the text colour of buttons for
disabled pages to be changed.
* The :class:`.ImagePanel` has a new option to preserve the aspect
ratio of the displayed image.
0.6.6 (Saturday October 13th 2018)
----------------------------------
......
......@@ -17,15 +17,21 @@ class ImagePanel(wx.Panel):
:class:`wx.Image`. The image is scaled to the size of the panel.
"""
def __init__(self, parent, image=None):
def __init__(self,
parent,
image=None,
preserveAspect=False):
"""Create an ``ImagePanel``.
If the ``image`` is not passed in here, it can be set later with the
:meth:`SetImage` method.
:arg parent: The :mod:`wx` parent object.
:arg parent: The :mod:`wx` parent object.
:arg image: The :class:`wx.Image` object to display.
:arg image: The :class:`wx.Image` object to display.
:arg preserveAspect: Defaults to ``False``. If ``True``, the image
aspect ratio is preserved.
"""
wx.Panel.__init__(self, parent)
......@@ -35,6 +41,8 @@ class ImagePanel(wx.Panel):
self.SetImage(image)
self.__preserveAspect = preserveAspect
def SetImage(self, image):
"""Set the image that is displayed on this ``ImagePanel``.
......@@ -70,11 +78,26 @@ class ImagePanel(wx.Panel):
if not dc.IsOk():
return
width, height = dc.GetSize().Get()
dwidth, dheight = dc.GetSize().Get()
if width == 0 or height == 0:
if dwidth == 0 or dheight == 0:
return
bitmap = self.__image.Scale(width, height).ConvertToBitmap()
if self.__preserveAspect:
iwidth, iheight = self.__image.GetSize().Get()
iratio = float(iwidth) / iheight
dratio = float(dwidth) / dheight
# canvas is too wide - reduce
# the display image width
if dratio > iratio:
dwidth = dheight / iratio
# canvas is too tall - reduce
# the display image height
elif dratio < iratio:
dheight = dwidth * iratio
bitmap = self.__image.Scale(dwidth, dheight).ConvertToBitmap()
dc.DrawBitmap(bitmap, 0, 0, False)
......@@ -68,18 +68,19 @@ class Notebook(wx.Panel):
wx.Panel.__init__(self, parent, style=style)
self.__border = border
self.__borderflags = borderflags
self.__btnside = btnside
self.__btnorient = btnorient
self.__invbtnorient = invbtnorient
self.__textorient = textorient
self.__textColour = None
self.__defaultColour = None
self.__selectColour = '#ffffff'
self.__buttonPanel = wx.Panel(self)
self.__sizer = wx.BoxSizer(invbtnorient)
self.__buttonSizer = wx.BoxSizer(btnorient)
self.__border = border
self.__borderflags = borderflags
self.__btnside = btnside
self.__btnorient = btnorient
self.__invbtnorient = invbtnorient
self.__textorient = textorient
self.__textColour = None
self.__defaultColour = None
self.__disabledTextColour = None
self.__selectColour = '#ffffff'
self.__buttonPanel = wx.Panel(self)
self.__sizer = wx.BoxSizer(invbtnorient)
self.__buttonSizer = wx.BoxSizer(btnorient)
self. SetSizer(self.__sizer)
self.__buttonPanel.SetSizer(self.__buttonSizer)
......@@ -174,18 +175,21 @@ class Notebook(wx.Panel):
to ``None`` to use the default colours. All arguments must be passed
as keyword arguments.
:arg text: Text colour
:arg default: Default (unselected) background colour.
:arg selected: Selected background colour.
:arg text: Text colour
:arg disabledText: Text colour for disabled pages.
:arg default: Default (unselected) background colour.
:arg selected: Selected background colour.
"""
text = kwargs.pop('text', None)
default = kwargs.pop('default', None)
selected = kwargs.pop('selected', '#ffffff')
text = kwargs.pop('text', None)
disabledText = kwargs.pop('disabledText', None)
default = kwargs.pop('default', None)
selected = kwargs.pop('selected', '#ffffff')
self.__textColour = text
self.__defaultColour = default
self.__selectColour = selected
self.__textColour = text
self.__disabledTextColour = disabledText
self.__defaultColour = default
self.__selectColour = selected
if self.PageCount() > 0:
self.SetSelection(self.GetSelection())
......@@ -343,7 +347,10 @@ class Notebook(wx.Panel):
button = self.__buttons[i]
showThis = i == self.__selected
button.SetForegroundColour(self.__textColour)
if button.IsEnabled():
button.SetForegroundColour(self.__textColour)
else:
button.SetForegroundColour(self.__disabledTextColour)
if showThis:
button.SetBackgroundColour(self.__selectColour)
......
......@@ -26,8 +26,12 @@ def _test_ImagePanel():
icon = wx.Bitmap(icon, wx.BITMAP_TYPE_PNG)
icon = icon.ConvertToImage()
frame = wx.GetApp().GetTopWindow()
panel = ip.ImagePanel(frame)
frame = wx.GetApp().GetTopWindow()
panel1 = ip.ImagePanel(frame)
wx.Yield()
panel.SetImage(icon)
panel1.SetImage(icon)
wx.Yield()
panel2 = ip.ImagePanel(frame, preserveAspect=True)
wx.Yield()
panel2.SetImage(icon)
wx.Yield()
......@@ -41,6 +41,7 @@ def _test_setColours():
notebook.AddPage(page1, 'page1')
notebook.SetButtonColours(text='#ffffff',
disabledText='#d0d0d0',
default='#000000',
selected='#0000ff')
......
Supports Markdown
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