diff --git a/fsl/fslview/layouts.py b/fsl/fslview/layouts.py index 6446760de536b0506ebaec9ae72381a8d8ef3621..c5bb09e63822d568c1857d3efa5c7c18f6ffbdf1 100644 --- a/fsl/fslview/layouts.py +++ b/fsl/fslview/layouts.py @@ -53,8 +53,10 @@ OrthoEditProfileActionLayout = props.HGroup( wrap=True, showLabels=False) + CanvasPanelActionLayout = props.HGroup( - (props.Widget('profile', label=strings.labels[CanvasPanel, 'profile']), + (props.Widget('profile', label=strings.labels[CanvasPanel, 'profile'], + visibleWhen=lambda i: len(i.getProp('profile').getChoices(i)) > 1), props.Button('screenshot', text=strings.labels[CanvasPanel, 'screenshot'], callback=CanvasPanel.screenshot), props.Button('toggleColourBar', text=strings.labels[CanvasPanel, 'toggleColourBar'], callback=CanvasPanel.toggleColourBar), props.Button('toggleImageList', text=strings.labels[CanvasPanel, 'toggleImageList'], callback=CanvasPanel.toggleImageList), diff --git a/fsl/fslview/profilemap.py b/fsl/fslview/profilemap.py index d5613f84f8e22950bb1102fa889c19646d979075..26ff95e664f749fdcd5e0ebecd7b8a48393c6e09 100644 --- a/fsl/fslview/profilemap.py +++ b/fsl/fslview/profilemap.py @@ -27,8 +27,17 @@ from fsl.fslview.profiles.orthoviewprofile import OrthoViewProfile from fsl.fslview.profiles.orthoeditprofile import OrthoEditProfile from fsl.fslview.profiles.lightboxviewprofile import LightBoxViewProfile +profiles = { + OrthoPanel : ['view', 'edit'], + LightBoxPanel : ['view'] +} +"""This dictionary is used by the :class:`~fsl.fslview.profiles.ProfileManager` +to figure out which profiles are available for each +:class:`~fsl.fslview.views.canvaspanel.CanvasPanel`. +""" -profiles = { + +profileHandlers = { (OrthoPanel, 'view') : OrthoViewProfile, (OrthoPanel, 'edit') : OrthoEditProfile, (LightBoxPanel, 'view') : LightBoxViewProfile @@ -110,5 +119,8 @@ altHandlerMap = { (('selint', 'RightMouseDown'), ('desel', 'LeftMouseDown')), (('selint', 'RightMouseDrag'), ('desel', 'LeftMouseDrag')), - (('selint', 'RightMouseUp'), ('desel', 'LeftMouseUp')))) + (('selint', 'RightMouseUp'), ('desel', 'LeftMouseUp')))), + + LightBoxViewProfile : OrderedDict(( + ((None, 'LeftMouseDown'), (None, 'LeftMouseDrag')), )) } diff --git a/fsl/fslview/profiles/__init__.py b/fsl/fslview/profiles/__init__.py index 6fce5f5b99745e15f7a5b9949d816e82269ac53f..fcc81194e4878ce0f323b0abb47969284dcff228 100644 --- a/fsl/fslview/profiles/__init__.py +++ b/fsl/fslview/profiles/__init__.py @@ -341,7 +341,8 @@ class Profile(actions.ActionProvider): else: handlerName = '_{}{}'.format(evType[0].lower(), evType[1:]) - handler = getattr(self, handlerName, None) + + handler = getattr(self, handlerName, None) if handler is not None: log.debug('Handler found for mode {}, event {}'.format(mode, @@ -540,12 +541,25 @@ class ProfileManager(object): instance which defines how images are being displayed. """ + import fsl.fslview.profilemap as profilemap + import fsl.fslview.strings as strings + self._canvasPanel = canvasPanel self._canvasCls = canvasPanel.__class__ self._imageList = imageList self._displayCtx = displayCtx self._currentProfile = None + profileProp = canvasPanel.getProp('profile') + profilez = profilemap.profiles[canvasPanel.__class__] + + for profile in profilez: + profileProp.addChoice( + profile, + strings.labels[canvasPanel, 'profile', profile], + canvasPanel) + canvasPanel.profile = profilez[0] + def getCurrentProfile(self): """Returns the :class:`Profile` instance currently in use.""" @@ -559,7 +573,7 @@ class ProfileManager(object): import fsl.fslview.profilemap as profilemap - profileCls = profilemap.profiles[self._canvasCls, profile] + profileCls = profilemap.profileHandlers[self._canvasCls, profile] # the current profile is the requested profile if (self._currentProfile is not None) and \ diff --git a/fsl/fslview/strings.py b/fsl/fslview/strings.py index 36eecb891bbd65f1aa7816ef37b724f26d147701..7e5fdda3c355e4c598c4b2ef36453364a969083b 100644 --- a/fsl/fslview/strings.py +++ b/fsl/fslview/strings.py @@ -29,6 +29,8 @@ labels = td.TypeDict({ 'OpenStandardAction' : 'Add standard', 'LoadColourMapAction' : 'Load custom colour map', + ('CanvasPanel', 'profile', 'view') : 'View', + ('OrthoPanel', 'profile', 'edit') : 'Edit', ('CanvasPanel', 'screenshot') : 'Take screenshot', ('CanvasPanel', 'toggleColourBar') : 'Show/hide colour bar', diff --git a/fsl/fslview/views/canvaspanel.py b/fsl/fslview/views/canvaspanel.py index ce76df1ec536ae6879a59289c5a3950853b338fd..7d7c4821b910d3597466b0bb3845e72891cec0f7 100644 --- a/fsl/fslview/views/canvaspanel.py +++ b/fsl/fslview/views/canvaspanel.py @@ -19,13 +19,11 @@ log = logging.getLogger(__name__) import subprocess -from collections import OrderedDict - import wx import props -import fsl.fslview.panel as fslpanel +import fsl.fslview.panel as fslpanel import fsl.fslview.profiles as profiles import fsl.fslview.displaycontext as displayctx import fsl.fslview.controls.imagelistpanel as imagelistpanel @@ -158,20 +156,11 @@ class CanvasPanel(fslpanel.FSLViewPanel): syncImageOrder = displayctx.DisplayContext.getSyncProperty('imageOrder') syncVolume = displayctx.DisplayContext.getSyncProperty('volume') - profile = props.Choice( - OrderedDict([('view', 'View'), - ('edit', 'Edit')]), - default='view') + profile = props.Choice() zoom = props.Percentage(minval=10, maxval=1000, default=100, clamped=True) - colourBarLocation = props.Choice({ - 'top' : 'Top', - 'bottom' : 'Bottom', - 'left' : 'Left', - 'right' : 'Right'}) - - + colourBarLocation = props.Choice(('top', 'bottom', 'left', 'right')) colourBarLabelSide = colourbarpanel.ColourBarPanel.labelSide