def _test_notebook_events(side, ornt):
    sim      = wx.UIActionSimulator()
    frame    = wx.GetApp().GetTopWindow()
    sizer    = wx.BoxSizer(wx.VERTICAL)
    notebook = nb.Notebook(frame, style=side | ornt)
    page1    = wx.Panel(notebook)
    page2    = wx.Panel(notebook)
    page3    = wx.Panel(notebook)

    notebook.AddPage(page1, 'page1')
    notebook.AddPage(page2, 'page2')
    notebook.AddPage(page3, 'page3')

    clicked = [None]

    def onbtn(ev):
        clicked[0] = ev.index

    notebook.Bind(nb.EVT_PAGE_CHANGE, onbtn)

    sizer.Add(notebook, flag=wx.EXPAND, proportion=1)
    frame.SetSizer(sizer)
    frame.Layout()
    realYield()

    btn1, btn2, btn3 = notebook.buttons

    notebook.SetSelection(2)

    simclick(sim, btn1)
    assert clicked[0] == 0
    simclick(sim, btn2)
    assert clicked[0] == 1
    simclick(sim, btn3)
    assert clicked[0] == 2
예제 #2
0
def _createNotebookGroup(parent, group, hasProps, propGui):
    """Creates a :class:`fsleyes_widgets.notebook.Notebook` object from the
    given :class:`.NotebookGroup` object.

    The children of the group object are also created via recursive calls to
    the :func:`_create` function.
    """

    if group.border:
        borderPanel, notebook = _makeGroupBorder(
            parent, group, nb.Notebook)
    else:
        notebook = nb.Notebook(parent)

    for i, child in enumerate(group.children):

        if child.label is None: pageLabel = '{}'.format(i)
        else:                   pageLabel = child.label

        if isinstance(child, parts.Group):
            child.border = False

        page = _create(notebook, child, hasProps, propGui)
        notebook.InsertPage(i, page, pageLabel)
        page._notebookIdx = i

    notebook.SetSelection(0)
    notebook.Layout()
    notebook.Fit()

    if group.border: return borderPanel
    else:            return notebook
def _test_add_remove(side, ornt):

    frame    = wx.GetApp().GetTopWindow()
    sizer    = wx.BoxSizer(wx.VERTICAL)
    notebook = nb.Notebook(frame, style=side | ornt)

    sizer.Add(notebook)
    frame.SetSizer(sizer)
    frame.Layout()

    # the notebook should reset the page parent
    page1 = wx.Panel(frame)
    page2 = wx.Panel(notebook)
    page3 = wx.Panel(notebook)

    with pytest.raises(IndexError):
        notebook.InsertPage(-1, page1, 'page1')
    with pytest.raises(IndexError):
        notebook.InsertPage(1,  page1, 'page1')

    assert notebook.PageCount() == 0
    notebook.InsertPage(0, page1, 'page1')
    assert notebook.PageCount() == 1
    notebook.AddPage(page3, 'page3')
    assert notebook.PageCount() == 2
    notebook.InsertPage(1, page2, 'page2')
    assert notebook.PageCount() == 3

    realYield()

    with pytest.raises(IndexError):
        notebook.RemovePage(-1)
    with pytest.raises(IndexError):
        notebook.RemovePage(3)

    assert notebook.pages[0] is page1
    assert notebook.pages[1] is page2
    assert notebook.pages[2] is page3

    assert notebook.FindPage(page1) == 0
    assert notebook.FindPage(page2) == 1
    assert notebook.FindPage(page3) == 2
    notebook.RemovePage(0)
    assert notebook.PageCount() == 2
    assert notebook.FindPage(page1) == wx.NOT_FOUND
    assert notebook.FindPage(page2) == 0
    assert notebook.FindPage(page3) == 1
    notebook.DeletePage(1)
    assert notebook.PageCount() == 1
    assert notebook.FindPage(page1) == wx.NOT_FOUND
    assert notebook.FindPage(page2) == 0
    assert notebook.FindPage(page3) == wx.NOT_FOUND
    notebook.RemovePage(0)
    assert notebook.PageCount() == 0
    assert notebook.FindPage(page1) == wx.NOT_FOUND
    assert notebook.FindPage(page2) == wx.NOT_FOUND
    assert notebook.FindPage(page3) == wx.NOT_FOUND

    realYield()
예제 #4
0
    def __init__(self,
                 parent,
                 overlayList,
                 displayCtx,
                 frame,
                 showHistory=False):
        """Creat a ``LocationPanel``.

        :arg parent:      The :mod:`wx` parent object, assumed to be a
                          :class:`.CanvasPanel`.

        :arg overlayList: The :class:`.OverlayList` instance.

        :arg displayCtx:  The :class:`.DisplayContext` instance.

        :arg frame:       The :class:`.FSLeyesFrame` instance.

        :arg showHistory: Defaults to ``False``. If ``True``, create and
                          display a :class:`LocationHistoryPanel`.
        """
        ctrlpanel.ControlPanel.__init__(
            self, parent, overlayList, displayCtx, frame)

        # only use a notebook if showing history panel
        if showHistory:
            self.__notebook = notebook.Notebook(self,
                                                style=wx.LEFT | wx.VERTICAL,
                                                border=0)
            subparent       = self.__notebook
        else:
            subparent       = self
            self.__notebook = None

        # We always create an info panel
        self.__info = LocationInfoPanel(
            subparent, overlayList, displayCtx, frame)

        # We don't always create a history panel
        if showHistory:
            self.__history = LocationHistoryPanel(
                subparent, overlayList, displayCtx, frame, parent)
            self.__notebook.AddPage(self.__info,
                                    strings.labels[self, 'info'])
            self.__notebook.AddPage(self.__history,
                                    strings.labels[self, 'history'])
        else:
            self.__history = None

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

        if showHistory:
            self.__sizer.Add(self.__notebook, flag=wx.EXPAND, proportion=1)
        else:
            self.__sizer.Add(self.__info, flag=wx.EXPAND, proportion=1)

        self.SetSizer(self.__sizer)
        self.Layout()
예제 #5
0
    def __init__(self, parent, overlayList, displayCtx, frame):
        """Create an ``AtlasPanel``.

        :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.
        """

        ctrlpanel.ControlPanel.__init__(self, parent, overlayList, displayCtx,
                                        frame)

        # Make sure the atlas
        # registry is up to date
        atlases.rescanAtlases()

        # See the enableAtlasPanel method
        # for info about this attribute.
        self.__atlasPanelEnableStack = 0

        # Cache of loaded atlases
        # and enabled atlas overlays.
        self.__enabledOverlays = {}
        self.__loadedAtlases = {}

        self.__notebook = notebook.Notebook(self)

        self.__sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.__sizer.Add(self.__notebook, flag=wx.EXPAND, proportion=1)

        self.SetSizer(self.__sizer)

        self.__infoPanel = atlasinfopanel.AtlasInfoPanel(
            self.__notebook, overlayList, displayCtx, frame, self)

        # Overlay panel, containing a list of regions,
        # allowing the user to add/remove overlays
        self.__overlayPanel = atlasoverlaypanel.AtlasOverlayPanel(
            self.__notebook, overlayList, displayCtx, frame, self)

        self.__managePanel = atlasmanagementpanel.AtlasManagementPanel(
            self.__notebook, overlayList, displayCtx, frame, self)

        self.__notebook.AddPage(self.__infoPanel,
                                strings.titles[self.__infoPanel])
        self.__notebook.AddPage(self.__overlayPanel,
                                strings.titles[self.__overlayPanel])
        self.__notebook.AddPage(self.__managePanel,
                                strings.titles[self.__managePanel])

        self.overlayList.addListener('overlays', self.name,
                                     self.__overlayListChanged)

        self.Layout()
        self.SetMinSize(self.__sizer.GetMinSize())
def _test_setColours():
    frame    = wx.GetApp().GetTopWindow()
    notebook = nb.Notebook(frame)

    page1 = wx.Panel(notebook)
    notebook.AddPage(page1, 'page1')

    notebook.SetButtonColours(text='#ffffff',
                              disabledText='#d0d0d0',
                              default='#000000',
                              selected='#0000ff')
def _test_enable_disable_show_hide(side, ornt):
    frame    = wx.GetApp().GetTopWindow()
    sizer    = wx.BoxSizer(wx.VERTICAL)
    notebook = nb.Notebook(frame, style=side | ornt)
    page1    = wx.Panel(notebook)
    page2    = wx.Panel(notebook)
    page3    = wx.Panel(notebook)

    notebook.AddPage(page1, 'page1')
    notebook.AddPage(page2, 'page2')
    notebook.AddPage(page3, 'page3')

    assert notebook.GetSelection() == 0
    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 1
    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 2
    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 0
    notebook.AdvanceSelection(False)
    assert notebook.GetSelection() == 2
    notebook.SetSelection(0)
    notebook.DisablePage(1)
    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 2
    notebook.AdvanceSelection(False)
    assert notebook.GetSelection() == 0
    notebook.EnablePage(1)

    notebook.SetSelection(1)
    notebook.HidePage(1)
    assert notebook.GetSelection() == 2
    notebook.AdvanceSelection(False)
    assert notebook.GetSelection() == 0
    notebook.ShowPage(1)
    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 1
def _test_selection(side, ornt):
    frame    = wx.GetApp().GetTopWindow()
    notebook = nb.Notebook(frame, style=side | ornt)
    page1 = wx.Panel(notebook)
    page2 = wx.Panel(notebook)
    page3 = wx.Panel(notebook)

    notebook.AddPage(page1, 'page1')
    notebook.AddPage(page2, 'page2')
    notebook.AddPage(page3, 'page3')

    assert notebook.GetSelection() == 0
    notebook.SetSelection(1)
    assert notebook.GetSelection() == 1
    notebook.SetSelection(2)
    assert notebook.GetSelection() == 2
    notebook.SetSelection(0)
    assert notebook.GetSelection() == 0

    notebook.AdvanceSelection()
    assert notebook.GetSelection() == 1
    notebook.AdvanceSelection(False)
    assert notebook.GetSelection() == 0

    with pytest.raises(IndexError):
        notebook.SetSelection(-1)
    with pytest.raises(IndexError):
        notebook.SetSelection(3)

    notebook.DeletePage(0)
    assert notebook.GetSelection() == 0
    notebook.SetSelection(1)
    notebook.DeletePage(0)
    assert notebook.GetSelection() == 0
    notebook.DeletePage(0)
    assert notebook.GetSelection() is None
예제 #9
0
    def __init__(self, parent, overlayList, displayCtx, frame, canvasPanel):
        """Create a ``MelodicClassificationPanel``.

        :arg parent:      The :mod:`wx` parent object.

        :arg overlayList: The :class:`.OverlayList`.

        :arg displayCtx:  The :class:`.DisplayContext` instance.

        :arg canvasPanel: The :class:`.CanvasPanel` that owns this
                          classification panel.
        """
        ctrlpanel.ControlPanel.__init__(
            self, parent, overlayList, displayCtx, frame)

        self.__disabledText = wx.StaticText(
            self,
            style=(wx.ALIGN_CENTRE_HORIZONTAL |
                   wx.ALIGN_CENTRE_VERTICAL))

        self.__overlay       = None
        self.__canvasPanel   = canvasPanel
        self.__lut           = fslcm.getLookupTable('melodic-classes')

        # If this classification panel has been
        # added to a LightBoxPanel, we add a text
        # annotation to said lightbox panel, to
        # display the labels associated with the
        # currently displayed component.
        self.__textAnnotation = None
        from fsleyes.views.lightboxpanel import LightBoxPanel

        if isinstance(canvasPanel, LightBoxPanel):
            annot = canvasPanel.getCanvas().getAnnotations()
            self.__textAnnotation = annot.text(
                '',
                0.5, 1.0,
                fontSize=30,
                halign='centre',
                valign='top',
                hold=True)

        self.__notebook      = notebook.Notebook(self)
        self.__componentGrid = componentgrid.ComponentGrid(
            self.__notebook,
            overlayList,
            displayCtx,
            frame,
            self.__lut)

        self.__labelGrid     = labelgrid.LabelGrid(
            self.__notebook,
            overlayList,
            displayCtx,
            frame,
            self.__lut)

        self.__loadButton  = wx.Button(self)
        self.__saveButton  = wx.Button(self)
        self.__clearButton = wx.Button(self)

        self.__notebook.AddPage(self.__componentGrid,
                                strings.labels[self, 'componentTab'])
        self.__notebook.AddPage(self.__labelGrid,
                                strings.labels[self, 'labelTab'])

        self.__loadButton .SetLabel(strings.labels[self, 'loadButton'])
        self.__saveButton .SetLabel(strings.labels[self, 'saveButton'])
        self.__clearButton.SetLabel(strings.labels[self, 'clearButton'])

        # Things which you don't want shown when
        # a melodic image is not selected should
        # be added to __mainSizer. Things which
        # you always want displayed should be
        # added to __sizer (but need to be laid
        # out w.r.t. __disabledText/__mainSizer)

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

        self.__btnSizer .Add(self.__loadButton,   flag=wx.EXPAND, proportion=1)
        self.__btnSizer .Add(self.__saveButton,   flag=wx.EXPAND, proportion=1)
        self.__btnSizer .Add(self.__clearButton,  flag=wx.EXPAND, proportion=1)

        self.__mainSizer.Add(self.__notebook,     flag=wx.EXPAND, proportion=1)

        self.__sizer    .Add(self.__disabledText, flag=wx.EXPAND, proportion=1)
        self.__sizer    .Add(self.__mainSizer,    flag=wx.EXPAND, proportion=1)
        self.__sizer    .Add(self.__btnSizer,     flag=wx.EXPAND)

        self.SetSizer(self.__sizer)

        self.__loadButton .Bind(wx.EVT_BUTTON, self.__onLoadButton)
        self.__saveButton .Bind(wx.EVT_BUTTON, self.__onSaveButton)
        self.__clearButton.Bind(wx.EVT_BUTTON, self.__onClearButton)

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

        self.__selectedOverlayChanged()

        self.SetMinSize((400, 100))