wxNotebook

OK, I'm stumped: re the second, "wxString text" argument to the AddPage
method, in which (sub-)attribute of the added page does said argument get
stored? Also, does the user have to keep track of the added pages, or are
there some (would-be) useful "FindPageBy" methods I'm not seeing? Thanks!

OlyDLG

OlyDLG wrote:

OK, I'm stumped: re the second, "wxString text" argument to the AddPage
method, in which (sub-)attribute of the added page does said argument get
stored?

theNotebook.GetPageText()

Also, does the user have to keep track of the added pages, or are
there some (would-be) useful "FindPageBy" methods I'm not seeing? Thanks!

There is the GetChildren method inherited from wx.Window, and the GetPage method inherited from wx.BookCtrlBase.

···

--
Robin Dunn
Software Craftsman

Robin Dunn <robin <at> alldunn.com> writes:

OlyDLG wrote:
> OK, I'm stumped: re the second, "wxString text" argument to the AddPage
> method, in which (sub-)attribute of the added page does said argument get
> stored?

theNotebook.GetPageText()

Excellent, thanks!

> Also, does the user have to keep track of the added pages, or are
> there some (would-be) useful "FindPageBy" methods I'm not seeing? Thanks!

There is the GetChildren method inherited from wx.Window, and the
GetPage method inherited from wx.BookCtrlBase.

The former just returns a list of windows (the pages' contents), and the
latter requires that you know the number of the page you want, so you either
have to maintain a map between page numbers and (some key to) their
contents, or you have to implement your own search algorithm. (I was hoping
the latter might already exist, e.g., a FindPageByText method strikes me as
a rather natural thing for this object to have...) Do you guys use the
"pull-request" model for requesting feature additions?

DG

OlyDLG <d_l_goldsmith <at> yahoo.com> writes:

Robin Dunn <robin <at> alldunn.com> writes:

> OlyDLG wrote:
> > OK, I'm stumped: re the second, "wxString text" argument to the AddPage
> > method, in which (sub-)attribute of the added page does said argument get
> > stored?
>
> theNotebook.GetPageText()

Excellent, thanks!

> > Also, does the user have to keep track of the added pages, or are
> > there some (would-be) useful "FindPageBy" methods I'm not seeing? Thanks!
>
> There is the GetChildren method inherited from wx.Window, and the
> GetPage method inherited from wx.BookCtrlBase.

The former just returns a list of windows (the pages' contents), and the
latter requires that you know the number of the page you want, so you either
have to maintain a map between page numbers and (some key to) their
contents, or you have to implement your own search algorithm. (I was hoping
the latter might already exist, e.g., a FindPageByText method strikes me as
a rather natural thing for this object to have...) Do you guys use the
"pull-request" model for requesting feature additions?

DG

Here's a version if anyone wants to add it:

    def FindPageByText(self, text):
        N = self.GetPageCount()
        i = 0
        while i < N:
            if self.GetPageText(i).strip() == text.strip():
                return self.GetPage(i)
            else:
                i += 1
        return None

YW,
DG

OlyDLG <d_l_goldsmith <at> yahoo.com> writes:

OlyDLG <d_l_goldsmith <at> yahoo.com> writes:

>
> Robin Dunn <robin <at> alldunn.com> writes:
>
> > OlyDLG wrote:
> > > OK, I'm stumped: re the second, "wxString text" argument to the AddPage
> > > method, in which (sub-)attribute of the added page does said

argument get

> > > stored?
> >
> > theNotebook.GetPageText()
>
> Excellent, thanks!
>
> > > Also, does the user have to keep track of the added pages, or are
> > > there some (would-be) useful "FindPageBy" methods I'm not seeing?

Thanks!

> >
> > There is the GetChildren method inherited from wx.Window, and the
> > GetPage method inherited from wx.BookCtrlBase.
>
> The former just returns a list of windows (the pages' contents), and the
> latter requires that you know the number of the page you want, so you either
> have to maintain a map between page numbers and (some key to) their
> contents, or you have to implement your own search algorithm. (I was hoping
> the latter might already exist, e.g., a FindPageByText method strikes me as
> a rather natural thing for this object to have...) Do you guys use the
> "pull-request" model for requesting feature additions?
>
> DG
>
Here's a version if anyone wants to add it:

    def FindPageByText(self, text):
        N = self.GetPageCount()
        i = 0
        while i < N:
            if self.GetPageText(i).strip() == text.strip():
                return self.GetPage(i)
            else:
                i += 1
        return None

YW,
DG

Ooops, forgot to check text input for the strip attribute:

    def FindPageByText(self, text):
        if hasattr(text, 'strip'):
            N = self.GetPageCount()
            i = 0
            while i < N:
                if self.GetPageText(i).strip() == text.strip():
                    return self.GetPage(i)
                else:
                    i += 1
        return None

Sorry 'bout that.

DG