Re: Curious: TreeCtrl.GetNextVisible() vs CustomTreeCtrl.GetNextVisible()
Andrea Gavana <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <CAEf70bzaNcX2XiKo_z89OjG46WaktY8KMZa9S2GmWdEddU+nqA@mail.gmail.com> |
Hi, On Wed, 28 Jun 2023 at 20.31, [email protected] <[email protected]> wrote: > The docs for both are clear and correct: > > TreeCtrl: > GetNextVisible(*self*, *item*) > <#m_-7195478226309837869_wx.TreeCtrl.GetNextVisible> > > Returns the next visible item *or an invalid item* if this item is the > last visible one. > > ----------- > > CustomTreeCtrl > > GetNextVisible(*self*, *item*) > <#m_-7195478226309837869_wx.lib.agw.customtreectrl.CustomTreeCtrl.GetNextVisible> > > Returns the next visible item. > > An instance of GenericTreeItem > <http://wx.lib.agw.customtreectrl.GenericTreeItem.html#wx.lib.agw.customtreectrl.GenericTreeItem> > *or None* if there are no next visible items. > > > Migrating code from TreeCtrl to a CustomTreeCtrl -- it's so close to a > drop-in replacement but this tripped me up: was expecting an invalid tree > item but got an unexpected None. Why the difference? Couldn't the Python > CustomTreeCtrl code just as easily have returned a nascent GenericTreeItem, > analogous to what the treectlg.cpp wxWidgets code does for the TreeCtrl ? > > Again, not a bug, and the difference is easily worked around -- but why > the difference? Why *not* try to keep the same behavior? > > -ck > CustomTreeCtrl was written 17 years ago, and at that time generating an “invalid” GenericTreeItem (and thus instantiating a whole class) just for its IsOk() method to return False seemed a very wasteful approach to me. 17 years later I haven’t changed my opinion. It’s a phenomenal waste of cycles - at least in Python - and returning None is a cheap alternative. That said, it would probably take about 10 minutes to subclass and monkey-patch GenericTreeItem to make it do what you want. Andrea. > -- > Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. > --- > You received this message because you are subscribed to the Google Groups > "wx-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/wx-users/dd3cec65-fc6c-4ac0-acd5-a7d24f06f8f8n%40googlegroups.com > <https://groups.google.com/d/msgid/wx-users/dd3cec65-fc6c-4ac0-acd5-a7d24f06f8f8n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Please read https://www.wxwidgets.org/support/mlhowto.htm before posting. --- You received this message because you are subscribed to the Google Groups "wx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/CAEf70bzaNcX2XiKo_z89OjG46WaktY8KMZa9S2GmWdEddU%2BnqA%40mail.gmail.com.