Exemplo n.º 1
0
def test_idleTimeout():
    idle.idleReset()
    default = idle.getIdleTimeout()
    idle.setIdleTimeout(999)
    assert idle.getIdleTimeout() == 999
    idle.setIdleTimeout()
    assert idle.getIdleTimeout() == default
Exemplo n.º 2
0
def test_embed():

    gc.collect()
    idle.idleReset()

    app = wx.App()
    frame = [wx.Frame(None)]
    panel = wx.Panel(frame[0])
    btn = wx.Button(panel)
    btn.SetLabel('Click to open FSLeyes')
    fsizer = wx.BoxSizer(wx.VERTICAL)
    frame[0].SetSizer(fsizer)
    fsizer.Add(panel, flag=wx.EXPAND)

    psizer = wx.BoxSizer(wx.VERTICAL)
    panel.SetSizer(psizer)
    psizer.Add(btn, flag=wx.EXPAND)

    sim = wx.UIActionSimulator()
    ncalls = [0]

    def finish():
        frame[0].Close()
        app.ExitMainLoop()

    def embedded(overlayList, displayCtx, fframe):

        print('Embedded call', ncalls[0])

        img = fslimage.Image(op.join(datadir, '3d'))
        fframe.addOrthoPanel()
        overlayList.append(img)
        fframe.Show()
        ncalls[0] += 1

        wx.CallLater(1500, fframe.Close)
        fframe = None
        if ncalls[0] < 4:
            wx.CallLater(2500, simclick, sim, btn)
        else:
            print('Done - closing')
            wx.CallLater(1500, finish)

    def open_fsleyes(ev):
        fslmain.embed(frame[0], callback=embedded, menu=False, save=False)

    btn.Bind(wx.EVT_BUTTON, open_fsleyes)

    wx.CallLater(1000, simclick, sim, btn)

    frame[0].Show()
    app.MainLoop()

    assert ncalls[0] == 4
Exemplo n.º 3
0
def _run_with_wx(func, *args, **kwargs):

    gc.collect()

    propagateRaise = kwargs.pop('propagateRaise', True)
    startingDelay = kwargs.pop('startingDelay', 500)
    finishingDelay = kwargs.pop('finishingDelay', 500)
    callAfterApp = kwargs.pop('callAfterApp', None)

    import wx

    result = [None]
    raised = [None]
    app = [wx.App()]
    frame = wx.Frame(None)

    if callAfterApp is not None:
        callAfterApp()

    def wrap():

        try:
            if func is not None:
                result[0] = func(*args, **kwargs)

        except Exception as e:
            print(e)
            raised[0] = e

        finally:

            def finish():
                frame.Destroy()
                app[0].ExitMainLoop()

            wx.CallLater(finishingDelay, finish)

    frame.Show()

    wx.CallLater(startingDelay, wrap)

    app[0].MainLoop()

    time.sleep(1)

    idle.idleReset()

    if raised[0] and propagateRaise:
        raise raised[0]

    del app[0]

    return result[0]
Exemplo n.º 4
0
def run_with_fsleyes(func, *args, **kwargs):
    """Create a ``FSLeyesFrame`` and run the given function. """

    logging.getLogger().setLevel(logging.WARNING)

    gc.collect()
    idle.idleReset()

    propagateRaise = kwargs.pop('propagateRaise', True)
    startingDelay  = kwargs.pop('startingDelay',  500)
    finishingDelay = kwargs.pop('finishingDelay', 5)
    callAfterApp   = kwargs.pop('callAfterApp',   None)

    result = [None]
    raised = [None]
    frame  = [None]
    app    = [None]

    def init():
        fsleyes.initialise()
        props.initGUI()
        colourmaps.init()
        initialised[0] = True
        fslgl.bootstrap((2, 1))
        wx.CallAfter(run)

    def finish():
        frame[0].Close(askUnsaved=False, askLayout=False)
        app[0].ExitMainLoop()

    def run():

        overlayList = fsloverlay.OverlayList()
        displayCtx  = dc.DisplayContext(overlayList)
        lockGroup   = dc.OverlayGroup(displayCtx, overlayList)

        displayCtx.overlayGroups.append(lockGroup)

        frame[0]    = fslframe.FSLeyesFrame(None,
                                            overlayList,
                                            displayCtx)

        app[0].SetOverlayListAndDisplayContext(overlayList, displayCtx)
        app[0].SetTopWindow(frame[0])

        frame[0].Show()

        try:
            if func is not None:
                result[0] = func(frame[0],
                                 overlayList,
                                 displayCtx,
                                 *args,
                                 **kwargs)

        except Exception as e:
            traceback.print_exc()
            raised[0] = e

        finally:
            wx.CallLater(finishingDelay, finish)

    app[0] = fslmain.FSLeyesApp()
    dummy  = wx.Frame(None)
    panel  = wx.Panel(dummy)
    sizer  = wx.BoxSizer(wx.HORIZONTAL)
    sizer.Add(panel, flag=wx.EXPAND, proportion=1)
    dummy.SetSizer(sizer)

    if callAfterApp is not None:
        callAfterApp()

    dummy.SetSize((100, 100))
    dummy.Layout()
    dummy.Show()

    if not initialised[0]:
        wx.CallLater(startingDelay,
                     fslgl.getGLContext,
                     parent=panel,
                     ready=init)
    else:
        wx.CallLater(startingDelay, run)

    app[0].MainLoop()
    dummy.Close()

    time.sleep(1)

    if raised[0] and propagateRaise:
        raise raised[0]

    return result[0]