Пример #1
0
def test_reportError():
    class MockWX(object):

        ICON_ERROR = 0
        OK = 2

        def MessageBox(self, msg, title, flags):
            self.msg = msg
            self.title = title

    class MyException(Exception):
        def __str__(self):
            return 'MyException'

    wx = MockWX()
    exc = MyException()

    with mock.patch.dict('sys.modules', {'wx': wx}):
        status.reportError('Error title', 'Error message', exc)

    assert wx.title == 'Error title'
    assert wx.msg.startswith('Error message')
    assert wx.msg.endswith(str(exc))

    with mock.patch.dict('sys.modules', {'wx' : None}), \
         mock.patch('fsleyes_widgets.utils.status.log.error') as log:
        status.reportError('Error title', 'Error message', exc)
        log.assert_called_once()
Пример #2
0
    def postScan(completed):

        # did the user cancel the progress dialog?
        if not completed:
            return

        # did an error occur in the scan step above?
        if isinstance(series[0], Exception):
            errTitle = strings.titles['loadDicom.scanError']
            errMsg = strings.messages['loadDicom.scanError']
            status.reportError(errTitle, errMsg, series[0])
            return

        dlg = BrowseDicomDialog(parent, series)
        dlg.CentreOnParent()

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

        # load the selected series - this is
        # done asynchronously via another
        # call to runWithBounce.
        for i in reversed(list(range(len(series)))):
            if not dlg.IsSelected(i):
                series.pop(i)

        title = strings.titles['loadDicom.loading']
        msg = strings.messages['loadDicom.loading']
        progress.runWithBounce(load, title, msg, callback=postLoad)
Пример #3
0
    def postLoad(completed):

        # Did the user cancel the progress dialog?
        if not completed:
            return

        # Did an error occur in the load step above?
        if isinstance(images[0], Exception):
            errTitle = strings.titles['loadDicom.loadError']
            errMsg = strings.messages['loadDicom.loadError']
            status.reportError(errTitle, errMsg, images[0])
            return

        fslsettings.write('loadSaveOverlayDir',
                          op.dirname(dcmdir.rstrip(op.sep)))

        if callback is not None:
            callback(images)
Пример #4
0
 def defaultErrorFunc(s, e):
     status.reportError(strings.titles['loadOverlays.error'],
                        strings.messages['loadOverlays.error'].format(s), e)
Пример #5
0
 def failure():
     if showError:
         status.reportError(
             LABELS['connect.error.title'],
             LABELS['connect.error.message'].format(host),
             error[0])