Example #1
0
def _test_RangeSliderSpinPanel_logic():
    frame = wx.GetApp().GetTopWindow()
    panel = rangeslider.RangeSliderSpinPanel(frame,
                                             lowLabel='Low',
                                             highLabel='High')
    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(panel, flag=wx.EXPAND, proportion=1)
    frame.SetSizer(sizer)
    frame.Layout()
    _test_RangePanel_logic(panel)
Example #2
0
def _test_RangeSliderSpinPanel_onlimit():

    sim = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()
    panel = rangeslider.RangeSliderSpinPanel(frame,
                                             style=rangeslider.RSSP_SHOW_LIMITS
                                             | rangeslider.RSSP_EDIT_LIMITS)
    sizer = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(panel, flag=wx.EXPAND, proportion=1)
    frame.SetSizer(sizer)
    frame.Layout()

    panel.SetLimits(0, 100)
    panel.SetRange(0, 100)

    called = [False]

    def handler(ev):
        called[0] = True

    panel.Bind(rangeslider.EVT_RANGE_LIMIT, handler)

    numberdlg = mock.MagicMock()
    numberdlg.ShowModal.return_value = wx.ID_OK
    numberdlg.GetValue.return_value = 9

    minbtn = panel.minButton
    maxbtn = panel.maxButton

    # limbutton, value, expectedrange, shouldTriggerEvent
    testcases = [
        (minbtn, 50, (50, 100), True),
        (minbtn, 150, (50, 100), False),
        (minbtn, -100, (-100, 100), True),
        (maxbtn, 50, (-100, 50), True),
        (maxbtn, -200, (-100, 50), False),
        (maxbtn, 500, (-100, 500), True),
    ]

    with mock.patch('fsleyes_widgets.rangeslider.numberdialog.NumberDialog',
                    return_value=numberdlg):

        for btn, val, expected, shouldEv in testcases:

            called[0] = None

            numberdlg.GetValue.return_value = val

            simclick(sim, btn)
            assert tuple(panel.GetLimits()) == expected

            if shouldEv: assert called[0]
            else: assert not called[0]
Example #3
0
def _test_RangeSliderSpinPanel_onchange():

    sim = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()
    frame.SetSize((600, 600))
    panel = rangeslider.RangeSliderSpinPanel(frame,
                                             lowLabel='Low',
                                             highLabel='High',
                                             style=0)

    addall(frame, [panel])

    called = [False]

    def handler(ev):
        called[0] = True

    panel.Bind(rangeslider.EVT_LOW_RANGE, handler)
    panel.Bind(rangeslider.EVT_HIGH_RANGE, handler)
    panel.Bind(rangeslider.EVT_RANGE, handler)

    panel.SetRange(0, 100)
    panel.SetDistance(5)

    realYield()

    simtext(sim, panel.lowSpin.textCtrl, '75')
    assert np.all(np.isclose(panel.GetRange(), (75, 100)))
    assert np.isclose(panel.lowSpin.GetValue(), 75)
    assert np.isclose(panel.lowSlider.GetValue(), 75)
    assert called[0]

    called[0] = False
    simtext(sim, panel.highSpin.textCtrl, '60')
    assert np.all(np.isclose(panel.GetRange(), (55, 60)))
    assert np.isclose(panel.highSpin.GetValue(), 60)
    assert np.isclose(panel.highSlider.GetValue(), 60)
    assert called[0]

    called[0] = False
    simclick(sim, panel.lowSlider, pos=[0.25, 0.5])
    assert abs(panel.GetLow() - 25) < 5
    assert abs(panel.lowSpin.GetValue() - 25) < 5
    assert abs(panel.lowSlider.GetValue() - 25) < 5
    assert called[0]

    called[0] = False
    simclick(sim, panel.highSlider, pos=[0.90, 0.5])
    assert abs(panel.GetHigh() - 90) < 5
    assert abs(panel.highSpin.GetValue() - 90) < 5
    assert abs(panel.highSlider.GetValue() - 90) < 5
    assert called[0]
Example #4
0
    def __init__(self, parent, overlayList, displayCtx, frame, ortho):
        """Create a ``CropImagePanel``.

        :arg parent:      The :mod:`wx` parent object.
        :arg overlayList: The :class:`.OverlayList` instance.
        :arg displayCtx:  The :class:`.DisplayContext` instance.
        :arg frame:       The :class:`.FSLeyesFrame` instance.
        :arg ortho:       The :class:`.OrthoPanel` instance.
        """
        ctrlpanel.ControlPanel.__init__(
            self, parent, overlayList, displayCtx, frame)

        profile = ortho.getCurrentProfile()

        self.__ortho   = ortho
        self.__profile = profile
        self.__overlay = None

        self.__cropBoxWidget = props.makeWidget(
            self,
            profile,
            'cropBox',
            showLimits=False,
            labels=['xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax'])

        self.__volumeWidget = rslider.RangeSliderSpinPanel(
            self,
            minValue=0,
            maxValue=1,
            minDistance=1,
            lowLabel='tmin',
            highLabel='tmax',
            style=rslider.RSSP_INTEGER)

        self.__dsWarning = dswarning.DisplaySpaceWarning(
            self,
            overlayList,
            displayCtx,
            frame,
            strings.messages[self, 'dsWarning'],
            'not like overlay',
            'overlay')

        self.__cropLabel       = wx.StaticText(self)
        self.__sizeLabel       = wx.StaticText(self)
        self.__cropButton      = wx.Button(    self, id=wx.ID_OK)
        self.__robustFovButton = wx.Button(    self)
        self.__loadButton      = wx.Button(    self)
        self.__saveButton      = wx.Button(    self)
        self.__cancelButton    = wx.Button(    self, id=wx.ID_CANCEL)

        self.__cropButton     .SetLabel(strings.labels[self, 'crop'])
        self.__robustFovButton.SetLabel(strings.labels[self, 'robustFov'])
        self.__loadButton     .SetLabel(strings.labels[self, 'load'])
        self.__saveButton     .SetLabel(strings.labels[self, 'save'])
        self.__cancelButton   .SetLabel(strings.labels[self, 'cancel'])

        self.__sizer    = wx.BoxSizer(wx.VERTICAL)
        self.__btnSizer = wx.BoxSizer(wx.HORIZONTAL)

        self.__sizer.Add((1, 10))
        self.__sizer.Add(self.__cropLabel,     flag=wx.CENTRE)
        self.__sizer.Add((1, 10))
        self.__sizer.Add(self.__dsWarning,     flag=wx.CENTRE)
        self.__sizer.Add((1, 10), proportion=1)
        self.__sizer.Add(self.__cropBoxWidget, flag=wx.EXPAND)
        self.__sizer.Add(self.__volumeWidget,  flag=wx.EXPAND)
        self.__sizer.Add((1, 10))
        self.__sizer.Add(self.__sizeLabel,     flag=wx.CENTRE, proportion=1)
        self.__sizer.Add((1, 10))
        self.__sizer.Add(self.__btnSizer,      flag=wx.CENTRE)
        self.__sizer.Add((1, 10))

        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND,
                            proportion=1)
        self.__btnSizer.Add(self.__cropButton,      flag=wx.EXPAND)
        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND)
        self.__btnSizer.Add(self.__robustFovButton, flag=wx.EXPAND)
        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND)
        self.__btnSizer.Add(self.__loadButton,      flag=wx.EXPAND)
        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND)
        self.__btnSizer.Add(self.__saveButton,      flag=wx.EXPAND)
        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND)
        self.__btnSizer.Add(self.__cancelButton,    flag=wx.EXPAND)
        self.__btnSizer.Add((10, 1),                flag=wx.EXPAND,
                            proportion=1)

        self.SetSizer(self.__sizer)
        self.SetMinSize(self.__sizer.GetMinSize())
        self.__cropButton.SetDefault()

        self.__cropButton  .Bind(wx.EVT_BUTTON,          self.__onCrop)
        self.__loadButton  .Bind(wx.EVT_BUTTON,          self.__onLoad)
        self.__saveButton  .Bind(wx.EVT_BUTTON,          self.__onSave)
        self.__cancelButton.Bind(wx.EVT_BUTTON,          self.__onCancel)
        self.__volumeWidget.Bind(rslider.EVT_RANGE,      self.__onVolume)
        self.__volumeWidget.Bind(rslider.EVT_LOW_RANGE,  self.__onVolume)
        self.__volumeWidget.Bind(rslider.EVT_HIGH_RANGE, self.__onVolume)

        profile.robustfov.bindToWidget(self,
                                       wx.EVT_BUTTON,
                                       self.__robustFovButton)

        displayCtx .addListener('selectedOverlay',
                                self.name,
                                self.__selectedOverlayChanged)
        overlayList.addListener('overlays',
                                self.name,
                                self.__selectedOverlayChanged)
        profile    .addListener('cropBox',
                                self.name,
                                self.__cropBoxChanged)

        self.__selectedOverlayChanged()
        self.__cropBoxChanged()
Example #5
0
def _Bounds(parent,
            hasProps,
            propObj,
            propVal,
            slider=True,
            spin=True,
            showLimits=True,
            editLimits=True,
            mousewheel=False,
            labels=None,
            spinWidth=None,
            **kwargs):
    """Creates and returns a panel containing sliders/spinboxes which
    allow the user to edit the low/high values along each dimension of the
    given :class:`.Bounds` property value.


    If both the ``slider`` and ``spin`` arguments are ``True``, a
    :class:`.RangeSliderSpinPanel` widget is returned; otherwise
    a :class:`.RangePanel` is returned.


    If both ``slider`` and ``spin`` are ``False``, a :exc:`ValueError` is
    raised.


    :arg slider:     Display slider widgets allowing the user to control the
                     bound values.

    :arg spin:       Display spin control widgets allowing the user to control
                     the bound values.

    :arg showLimits: Show the bound limits.

    :arg editLimits: Add buttons allowing the user to edit the bound limits.

    :arg mousewheel: If ``True``, mouse wheel events over the slider/spin
                     controls will change the bounds values.

    :arg labels:     A list of strings of length ``2 * ndims``, where ``ndims``
                     is the number of dimensions on the ``Bounds`` property;
                     the strings are used as labels on the widget.

    :arg spinWidth:  Desired spin control width. See the
                     :class:`.FloatSpinCtrl` class.

    See the :func:`.widgets._String` documentation for details on the other
    parameters.
    """

    ndims   = propObj._ndims
    real    = propObj._real
    clamped = propObj.getListType().getAttribute(None, 'clamped')

    panel = wx.Panel(parent)
    sizer = wx.BoxSizer(wx.VERTICAL)
    panel.SetSizer(sizer)

    if labels is None:
        labels = [None] * 2 * ndims

    for i in range(ndims):
        minDistance = propObj.getAttribute(hasProps, 'minDistance')
        minval      = propVal.getMin(i)
        maxval      = propVal.getMax(i)
        loval       = propVal.getLo(i)
        hival       = propVal.getHi(i)

        if minDistance is None: minDistance = 0
        if minval      is None: minval      = loval
        if maxval      is None: maxval      = hival

        if slider and spin:

            style = 0

            if mousewheel:  style |= rangeslider.RSSP_MOUSEWHEEL
            if not real:    style |= rangeslider.RSSP_INTEGER
            if showLimits:  style |= rangeslider.RSSP_SHOW_LIMITS
            if editLimits:  style |= rangeslider.RSSP_EDIT_LIMITS
            if not clamped: style |= rangeslider.RSSP_NO_LIMIT

            slider = rangeslider.RangeSliderSpinPanel(
                panel,
                minValue=minval,
                maxValue=maxval,
                lowValue=loval,
                highValue=hival,
                lowLabel=labels[i * 2],
                highLabel=labels[i * 2 + 1],
                minDistance=minDistance,
                spinWidth=spinWidth,
                style=style)

        elif slider or spin:

            style = 0

            if mousewheel:  style |= rangeslider.RP_MOUSEWHEEL
            if slider:      style |= rangeslider.RP_SLIDER
            if not real:    style |= rangeslider.RP_INTEGER
            if not clamped: style |= rangeslider.RP_NO_LIMIT

            slider = rangeslider.RangePanel(
                panel,
                minValue=minval,
                maxValue=maxval,
                lowValue=loval,
                highValue=hival,
                lowLabel=labels[i * 2],
                highLabel=labels[i * 2 + 1],
                minDistance=minDistance,
                spinWidth=spinWidth,
                style=style)

        else:
            raise ValueError('One of slider or spin must be True')

        _boundBind(hasProps, propObj, slider, propVal, i, editLimits)

        sizer.Add(slider, flag=wx.EXPAND)

    return panel