wx.aui.notebook Avoid repeat addpage

Hello,

Im using wxPython 2.8.12.1 and my application have a trecontrol and wx.aui.notebook, when I click in one item of the treecontrol it launch the associated window.

The problem is: user can click in the same tree item many times and load the same window many times, I want to avoid it, I want only 1 window for each tree item selected, is there any way to do that?

···

--

Saludos / Best regards

Mario Lacunza
Email:: mlacunza@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Mascotas Perdidas:: http://mascotas-perdidas.com/
Google Talk / Y! messenger / Skype: mlacunzav
MSN: mlacunzav@hotmail.com

Hi,

···

On 5 August 2014 18:01, Mario Lacunza wrote:

Hello,

Im using wxPython 2.8.12.1 and my application have a trecontrol and wx.aui.notebook, when I click in one item of the treecontrol it launch the associated window.

The problem is: user can click in the same tree item many times and load the same window many times, I want to avoid it, I want only 1 window for each tree item selected, is there any way to do that?

What I usually do in these situations is:

  1. Move away from wx.TreeCtrl and use wx.lib.agw.customtreectrl, the reason behind it being the unreasonable way wx.TreeCtrl always re-generates new wx.TreeItemId for an item, even if it hasn’t changed.

  2. When adding a new page to a notebook, I would pass the CustomTreeCtrl tree item to the page itself (let’s say, a panel) as an input parameter and store it as an attribute for that page, i.e.:

my_page = MyCoolPanel(notebook, tree_item)

notebook.AddPage(my_page)

  1. If I have to check that a page has already been added, I’d something along these lines (self is the notebook):

def AddNewPage(self, tree_item):

for i in xrange(notebook.GetPageCount()):

page = notebook.GetPage(ii)

if page.tree_item == tree_item:

notebook.SetSelection(ii)

return

my_page = MyCoolPanel(notebook, tree_item)

notebook.AddPage(my_page)

You may have to adapt this approach to your needs, of course, but it works well for me.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://www.infinity77.net

-------------------------------------------------------------

def ask_mailing_list_support(email):

if mention_platform_and_version() and include_sample_app():

    send_message(email)
else:
    install_malware()
    erase_hard_drives()

-------------------------------------------------------------

Without code it is hard to say, but you can have a click handler where you launch your window, and simply add the tree text to a dictionary as the key, and if this key exists in the dict already, don’t show the window… then maybe in your window OnClose for the new window, remove that dict key.

···

On Tuesday, August 5, 2014 9:02:03 AM UTC-7, Mario Lacunza wrote:

Hello,

Im using wxPython 2.8.12.1 and my application have a trecontrol and
wx.aui.notebook, when I click in one item of the treecontrol it launch
the associated window.

The problem is: user can click in the same tree item many times and load
the same window many times, I want to avoid it, I want only 1 window for
each tree item selected, is there any way to do that?

Saludos / Best regards

Mario Lacunza

Email:: mlac...@gmail.com

Personal Website:: http://www.lacunza.biz/

Hosting:: http://mlv-host.com/

Mascotas Perdidas:: http://mascotas-perdidas.com/

Google Talk / Y! messenger / Skype: mlacunzav

MSN: mlac...@hotmail.com

Hi,
Thanks Nathan and Andrea for the help. I have now a clear idea.

For close the circle I need detect the page close event, so I found an old post about it here: Redirecting to Google Groups

Saludos / Best regards

Mario Lacunza
Email:: mlacunza@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Mascotas Perdidas:: http://mascotas-perdidas.com/
Google Talk / Y! messenger / Skype: mlacunzav
MSN: mlacunzav@hotmail.com

···

El 05/08/14 a las #4, Andrea Gavana escribió:

Hi,

On 5 August 2014 18:01, Mario Lacunza wrote:

    Hello,

    Im using wxPython 2.8.12.1 and my application have a trecontrol
    and wx.aui.notebook, when I click in one item of the treecontrol
    it launch the associated window.

    The problem is: user can click in the same tree item many times
    and load the same window many times, I want to avoid it, I want
    only 1 window for each tree item selected, is there any way to do
    that?

What I usually do in these situations is:

1. Move away from wx.TreeCtrl and use wx.lib.agw.customtreectrl, the reason behind it being the unreasonable way wx.TreeCtrl always re-generates new wx.TreeItemId for an item, even if it hasn't changed.

2. When adding a new page to a notebook, I would pass the CustomTreeCtrl tree item to the page itself (let's say, a panel) as an input parameter and store it as an attribute for that page, i.e.:

my_page = MyCoolPanel(notebook, tree_item)
notebook.AddPage(my_page)

3. If I have to check that a page has already been added, I'd something along these lines (self is the notebook):

def AddNewPage(self, tree_item):

    for i in xrange(notebook.GetPageCount()):
        page = notebook.GetPage(ii)
        if page.tree_item == tree_item:
            notebook.SetSelection(ii)
            return

    my_page = MyCoolPanel(notebook, tree_item)
    notebook.AddPage(my_page)

You may have to adapt this approach to your needs, of course, but it works well for me.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com <mailto:wxpython-users+unsubscribe@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.