Пример #1
0
def _test_NumberDialog_create():

    sim   = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()

    testcases = [
        ({'real' : False, 'initial' :    999}, 'ok',        999),
        ({'real' : False, 'initial' :   -999}, 'ok',       -999),
        ({'real' : True,  'initial' : 0.3443}, 'ok',     0.3443),
        ({'real' : True,  'initial' :  -0.48}, 'ok',      -0.48),
        ({'real' : True,  'initial' : 0.3443}, 'cancel',   None),
    ]

    for kwargs, target, expected in testcases:
        dlg = numdlg.NumberDialog(
            frame,
            title='NumberDialog test',
            message='Enter a number',
            **kwargs)

        if target == 'ok': target = dlg.okButton
        else:              target = dlg.cancelButton

        dlg.Show()
        realYield()

        simclick(sim, target)
        assert dlg.GetValue() == expected
Пример #2
0
def _test_NumberDialog_limit():
    sim   = wx.UIActionSimulator()
    frame = wx.GetApp().GetTopWindow()

    # kwargs, input, needClick, expected
    testcases = [
        ({'real'     : False,
          'minValue' : 0,
          'maxValue' : 100}, '50', False, 50),
        ({'real'     : False,
          'minValue' : 0,
          'maxValue' : 100}, '0',  False,  0),
        ({'real'     : False,
          'minValue' : 0,
          'maxValue' : 100}, '-1', True,  0),
        ({'real'     : False,
          'minValue' : 0,
          'maxValue' : 100}, '100', False, 100),
        ({'real'     : False,
          'minValue' : 0,
          'maxValue' : 100}, '101', True, 100),

        ({'real'     : True,
          'minValue' : 0,
          'maxValue' : 1}, '0.745', False, 0.745),
        ({'real'     : True,
          'minValue' : 0,
          'maxValue' : 1}, '0.0', False, 0.0),
        ({'real'     : True,
          'minValue' : 0,
          'maxValue' : 1}, '-25.9', True, 0.0),
        ({'real'     : True,
          'minValue' : 0,
          'maxValue' : 1}, '25.9', True, 1.0),
        ({'real'     : True,
          'minValue' : 0,
          'maxValue' : 1}, '1.0', False, 1.0),
    ]

    for kwargs, text, needClick, expected in testcases:
        dlg = numdlg.NumberDialog(frame, **kwargs)

        dlg.Show()

        simtext(sim, dlg.floatSpinCtrl.textCtrl, text)
        if needClick:
            assert dlg.GetValue() is None
            simclick(sim, dlg.okButton)
        assert dlg.GetValue() == expected
Пример #3
0
    def __doImport(self):

        import wx

        frame = wx.GetApp().GetTopWindow()

        # Ask the user where to get the data
        msg = strings.messages[self, 'selectFile']
        fromDir = fslsettings.read('loadSaveOverlayDir', os.getcwd())
        dlg = wx.FileDialog(frame,
                            message=msg,
                            defaultDir=fromDir,
                            style=wx.FD_OPEN)

        if dlg.ShowModal() != wx.ID_OK:
            return

        filePath = dlg.GetPath()
        fileName = op.basename(filePath)

        # Load the file, show an
        # error if it fails
        try:

            # Assuming that the data series
            # to plot are stored as columns
            data = np.loadtxt(filePath, dtype=np.float).T

            # Make sure the data is 2D, to
            # make code below easier and
            # happier.
            if len(data.shape) == 1:
                data = data.reshape((1, -1))

        except Exception as e:
            title = strings.titles[self, 'error']
            msg = strings.messages[self, 'error'].format(
                filePath, '{}: {}'.format(type(e).__name__, str(e)))

            wx.MessageBox(msg, title, wx.ICON_ERROR | wx.OK)
            return

        fslsettings.write('loadSaveOverlayDir', filePath)

        # Ask the user the x axis scaling factor.
        # If the currently selected overlay is
        # Nifti and 4D, default to its pixdim[3]
        overlay = self.__displayCtx.getSelectedOverlay()

        if overlay is not None                 and \
           isinstance(overlay, fslimage.Nifti) and \
           len(overlay.shape) == 4             and \
           self.__plotPanel.usePixdim:
            xscale = overlay.pixdim[3]

        else:
            xscale = 1

        title = strings.titles[self, 'selectXScale']
        msg = strings.messages[self, 'selectXScale']

        # If the user pushes 'Ok', the entered value
        # is used as a fixed X axis interval. Otherwise,
        # it is assumed that the first column in the
        # file is the x axis data.
        dlg = numdlg.NumberDialog(frame,
                                  title=title,
                                  message=msg,
                                  initial=xscale,
                                  minValue=1e-5,
                                  cancelText=strings.labels[self,
                                                            'firstColumnIsX'])

        firstColumnIsX = dlg.ShowModal() != wx.ID_OK
        xscale = dlg.GetValue()

        # Add the data series
        series = []

        if firstColumnIsX:
            xdata = data[0, :]
            ydata = data[1:, :]
        else:
            xdata = np.arange(0,
                              data.shape[1] * xscale,
                              xscale,
                              dtype=np.float)
            ydata = data

        for i, ydata in enumerate(ydata):

            x = np.array(xdata)
            y = np.array(ydata)
            fin = np.isfinite(x) & np.isfinite(y)
            x = x[fin]
            y = y[fin]

            ds = plotting.DataSeries(None, self.__overlayList,
                                     self.__displayCtx, self.__plotPanel)
            ds.setData(x, y)

            # If we recognise the file name,
            # we can give it a useful label.
            label = strings.plotLabels.get('{}.{}'.format(fileName, i),
                                           '{} [{}]'.format(fileName, i))

            ds.label = label
            ds.lineWidth = 1
            ds.colour = fslcm.randomDarkColour()

            series.append(ds)

        self.__plotPanel.dataSeries.extend(series)