Close/destroy wx.Notebook

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Close/destroy wx.Notebook

floatingshed
I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

Tim Roberts
On Nov 20, 2017, at 10:48 PM, [hidden email] wrote:
>
> I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

The notebook is a parent of its pages.  You should be able to do something like self.GetParent().Close()

Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

floatingshed
Sorry no, that doesn't work, no effect and no error!


On Tuesday, November 21, 2017 at 8:04:30 AM UTC, Tim Roberts wrote:
On Nov 20, 2017, at 10:48 PM, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="X9tBBUXfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">floati...@... wrote:
>
> I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

The notebook is a parent of its pages.  You should be able to do something like self.GetParent().Close()

Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="X9tBBUXfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

Tim Roberts
[hidden email] wrote:
>
> Sorry no, that doesn't work, no effect and no error!

Perhaps you should show us your code.  It's unusual to want to close a
notebook by itself.  Is your notebook the sole window inside a frame,
and it's really the frame you want to close?

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

floatingshed
In reply to this post by floatingshed
OK, this is what my notebook is based upon, much simple and more readable, but exhibiting the same problem.


import wx
 
########################################################################
class TabPanel(wx.Panel):
   
#----------------------------------------------------------------------
   
def __init__(self, parent):
       
""""""
        wx
.Panel.__init__(self, parent=parent)
 
       
self.button = wx.Button(self, -1, "Close Notebook")
       
self.button.Bind(wx.EVT_BUTTON, self.onButton)
        sizer
= wx.BoxSizer(wx.VERTICAL)
        sizer
.Add(self.button, 0, wx.ALL, 10)
       
self.SetSizer(sizer)
       
       
       
       
   
def onButton(self,event):
       
self.Close()
 
########################################################################
class DemoFrame(wx.Frame):
   
"""
    Frame that holds all other widgets
    """

 
   
#----------------------------------------------------------------------
   
def __init__(self):
       
"""Constructor"""        
        wx
.Frame.__init__(self, None, wx.ID_ANY,
                         
"Notebook Tutorial",
                          size
=(600,400)
                         
)
        panel
= wx.Panel(self)
 
        notebook
= wx.Notebook(panel)
        tabOne
= TabPanel(notebook)
        notebook
.AddPage(tabOne, "Tab 1")
 
        tabTwo
= TabPanel(notebook)
        notebook
.AddPage(tabTwo, "Tab 2")
 
        sizer
= wx.BoxSizer(wx.VERTICAL)
        sizer
.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
        panel
.SetSizer(sizer)
       
self.Layout()
 
       
self.Show()
 
#----------------------------------------------------------------------
if __name__ == "__main__":
    app
= wx.App(False)
    frame
= DemoFrame()
    app
.MainLoop()



On Tuesday, November 21, 2017 at 6:48:59 AM UTC, [hidden email] wrote:
I have a five page notebook working fine. However on one page I need to close the entire notebook after an operation completes. self.Close() has no effect and self.Destroy() simply clears the current page. How do I close the whole thing, other than clicking the X top right? Thanks.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

floatingshed
In reply to this post by Tim Roberts
OK, here it is. Much simplified to make for easier reading! All I want is for the button to close the entire notebook.

import wx


class info(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
       
self.button1 = wx.Button(self,-1,"close")
       
self.button1.Bind(wx.EVT_BUTTON, self.onClose)
       
       
   
def onClose(self, event):
       
self.Close()  
       
       
class sched1(wx.Panel):
   
def __init__(self, parent):
        wx
.Frame.__init__(self, parent)
       
pass
       

   
def onClose(self, event):
       
self.Close()

       
class sched2(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass
       


class view(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass
       

class history(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
pass

       
       
###################################Main page##########################################            

class MainFrame(wx.Frame):
   
def __init__(self):
        wx
.Frame.__init__(self, None, title="notebook", size = (600,300))
        p
= wx.Panel(self)
       
self.nb = wx.Notebook(p)

       
self.nb.AddPage(info(self.nb), "Detail")
       
self.nb.AddPage(sched1(self.nb), "Scheduling 1")
       
self.nb.AddPage(sched2(self.nb), "Scheduling 2")
       
self.nb.AddPage(history(self.nb), "History")
       
self.nb.AddPage(view(self.nb), "Additional info")

        sizer
= wx.BoxSizer()
        sizer
.Add(self.nb, 1, wx.EXPAND)
        p
.SetSizer(sizer)


       
if __name__ == "__main__":
    app
= wx.App(True)
   
MainFrame().Show()
    app
.MainLoop()



Thanks.


On Tuesday, November 21, 2017 at 6:06:51 PM UTC, Tim Roberts wrote:
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="knwJlyMAAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">floati...@... wrote:
>
> Sorry no, that doesn't work, no effect and no error!

Perhaps you should show us your code.  It's unusual to want to close a
notebook by itself.  Is your notebook the sole window inside a frame,
and it's really the frame you want to close?

--
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="knwJlyMAAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

Tim Roberts
[hidden email] wrote:
>
> OK, here it is. Much simplified to make for easier reading! All I want
> is for the button to close the entire notebook.

Well, here's the issue.   I don't think that's really what  you want. 
This will do what you asked for:
      
    def onClose(self, event):
        self.GetParent().Destroy()

But that leaves an empty frame window.  To do what I expect you really
want, which is to close the frame window, do this:
      
    def onClose(self, event):
        self.GetTopLevelParent().Close()

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Close/destroy wx.Notebook

floatingshed
Tim. That is exactly what I needed. Many thanks.

On Tuesday, November 21, 2017 at 7:15:36 PM UTC, Tim Roberts wrote:
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="pCsWS4zhAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">floati...@... wrote:
>
> OK, here it is. Much simplified to make for easier reading! All I want
> is for the button to close the entire notebook.

Well, here's the issue.   I don't think that's really what  you want. 
This will do what you asked for:
      
    def onClose(self, event):
        self.GetParent().Destroy()

But that leaves an empty frame window.  To do what I expect you really
want, which is to close the frame window, do this:
      
    def onClose(self, event):
        self.GetTopLevelParent().Close()

--
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="pCsWS4zhAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.