Skip to content
Snippets Groups Projects
Commit 66d90c1a authored by Paul McCarthy's avatar Paul McCarthy
Browse files

ImageList sets selectedImage to the last image in the list in

__init__. ImageListPanel correctly syncs ImageList.selectedImage with
elistbox.SetSelection. LocationPanel cleans its image list property
listeners up when destroyed. ImageDisplayPanel has a StaticText widget
which shows the current image file.
parent e3d05f56
No related branches found
No related tags found
No related merge requests found
...@@ -592,6 +592,10 @@ class ImageList(props.HasProperties): ...@@ -592,6 +592,10 @@ class ImageList(props.HasProperties):
# initialise image bounds # initialise image bounds
self._imageListChanged() self._imageListChanged()
# select the last image in the list
if len(images) > 0:
self.selectedImage = len(images) - 1
# initialise the location to be # initialise the location to be
# the centre of the image world # the centre of the image world
b = self.bounds b = self.bounds
......
...@@ -37,9 +37,20 @@ class ImageDisplayPanel(wx.Panel): ...@@ -37,9 +37,20 @@ class ImageDisplayPanel(wx.Panel):
# a dictionary containing {id(image) : panel} mappings # a dictionary containing {id(image) : panel} mappings
self._displayPanels = {} self._displayPanels = {}
self._sizer = wx.BoxSizer(wx.HORIZONTAL) self._label = wx.StaticText(self,
style=wx.ALIGN_CENTRE |
wx.ST_ELLIPSIZE_MIDDLE)
self._sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self._sizer) self.SetSizer(self._sizer)
self._sizer.Add(self._label, flag=wx.EXPAND)
font = self._label.GetFont()
font.SetPointSize(font.GetPointSize() - 2)
font.SetWeight(wx.FONTWEIGHT_LIGHT)
self._label.SetFont(font)
self._imageList.addListener( self._imageList.addListener(
'images', 'images',
self._name, self._name,
...@@ -119,7 +130,9 @@ class ImageDisplayPanel(wx.Panel): ...@@ -119,7 +130,9 @@ class ImageDisplayPanel(wx.Panel):
if i == idx: if i == idx:
log.debug('Showing display panel for ' log.debug('Showing display panel for '
'image {}'.format(image.name)) 'image {} ({})'.format(image.name, idx))
self._label.SetLabel('{}'.format(image.imageFile))
displayPanel.Show(i == idx) displayPanel.Show(i == idx)
......
...@@ -61,15 +61,32 @@ class ImageListPanel(wx.Panel): ...@@ -61,15 +61,32 @@ class ImageListPanel(wx.Panel):
self._name, self._name,
self._imageListChanged) self._imageListChanged)
self._imageList.addListener(
'selectedImage',
self._name,
self._selectedImageChanged)
# This flag is set by the listbox listeners (bound above), # This flag is set by the listbox listeners (bound above),
# and read by the _imageListChanged, to ensure that user # and read by the _imageListChanged, to ensure that user
# actions on the list box do not trigger a list box refresh. # actions on the list box do not trigger a list box refresh.
self._listBoxNeedsUpdate = True self._listBoxNeedsUpdate = True
self._imageListChanged() self._imageListChanged()
self._selectedImageChanged()
self.Layout() self.Layout()
def _selectedImageChanged(self, *a):
"""Called when the :attr:`~fsl.data.fslimage.ImageList.selectedImage`
property changes. Updates the selected item in the list box.
"""
if not self._listBoxNeedsUpdate:
return
self._listBox.SetSelection(self._imageList.selectedImage)
def _imageListChanged(self, *a): def _imageListChanged(self, *a):
"""Called when the :class:`~fsl.data.fslimage.ImageList.images` """Called when the :class:`~fsl.data.fslimage.ImageList.images`
...@@ -101,6 +118,7 @@ class ImageListPanel(wx.Panel): ...@@ -101,6 +118,7 @@ class ImageListPanel(wx.Panel):
""" """
self._listBoxNeedsUpdate = False self._listBoxNeedsUpdate = False
self._imageList.move(ev.oldIdx, ev.newIdx) self._imageList.move(ev.oldIdx, ev.newIdx)
self._imageList.selectedImage = ev.newIdx
self._listBoxNeedsUpdate = True self._listBoxNeedsUpdate = True
...@@ -109,7 +127,9 @@ class ImageListPanel(wx.Panel): ...@@ -109,7 +127,9 @@ class ImageListPanel(wx.Panel):
:class:`~pwidgets.elistbox.EditableListBox`. Sets the :class:`~pwidgets.elistbox.EditableListBox`. Sets the
:attr:`fsl.data.fslimage.ImageList.selectedImage property. :attr:`fsl.data.fslimage.ImageList.selectedImage property.
""" """
self._listBoxNeedsUpdate = False
self._imageList.selectedImage = ev.idx self._imageList.selectedImage = ev.idx
self._listBoxNeedsUpdate = True
def _lbAdd(self, ev): def _lbAdd(self, ev):
......
...@@ -99,6 +99,13 @@ class LocationPanel(wx.Panel, props.HasProperties): ...@@ -99,6 +99,13 @@ class LocationPanel(wx.Panel, props.HasProperties):
'{}_voxToWorld'.format(lName), '{}_voxToWorld'.format(lName),
self._voxelLocationChanged) self._voxelLocationChanged)
def onDestroy(ev):
self.imageList.removeListener('images', lName)
self.imageList.removeListener('selectedImage', lName)
self.imageList.removeListener('location', lName)
self.Bind(wx.EVT_WINDOW_DESTROY, onDestroy)
self._selectedImageChanged() self._selectedImageChanged()
self._worldLocationChanged() self._worldLocationChanged()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment