Python Forum
[WxPython] how to reopen a closed tab of wx.aui.Notebook? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [WxPython] how to reopen a closed tab of wx.aui.Notebook? (/thread-16169.html)



how to reopen a closed tab of wx.aui.Notebook? - royer14 - Feb-17-2019

Hello Group, I have a design that I had created in wxformbuilder but I have a difficulty when I close a tab and by a menubar return it open

import wx
import wx.xrc
import wx.aui

###########################################################################
## Class MyFrame2
###########################################################################

class MyFrame2 ( wx.Frame ):

	def __init__( self, parent ):
		wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

		self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
		self.m_mgr = wx.aui.AuiManager()
		self.m_mgr.SetManagedWindow( self )
		self.m_mgr.SetFlags(wx.aui.AUI_MGR_DEFAULT)

		self.m_menubar2 = wx.MenuBar( 0 )
		self.m_menu4 = wx.Menu()
		self.m_menuItem8 = wx.MenuItem( self.m_menu4, wx.ID_ANY, u"Close", wx.EmptyString, wx.ITEM_NORMAL )
		self.m_menu4.Append( self.m_menuItem8 )

		self.m_menu4.AppendSeparator()

		self.m_menuItem9 = wx.MenuItem( self.m_menu4, wx.ID_ANY, u"Open tab", wx.EmptyString, wx.ITEM_NORMAL )
		self.m_menu4.Append( self.m_menuItem9 )

		self.m_menubar2.Append( self.m_menu4, u"Inicio" )

		self.SetMenuBar( self.m_menubar2 )

		self.m_statusBar2 = self.CreateStatusBar( 1, wx.STB_SIZEGRIP, wx.ID_ANY )
		self.m_auinotebook3 = wx.aui.AuiNotebook( self, wx.ID_ANY, wx.DefaultPosition, wx.Size( 240,-1 ), wx.aui.AUI_NB_DEFAULT_STYLE )
		self.m_mgr.AddPane( self.m_auinotebook3, wx.aui.AuiPaneInfo() .Left() .PinButton( True ).Dock().Resizable().FloatingSize( wx.DefaultSize ) )

		self.m_panel4 = wx.Panel( self.m_auinotebook3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
		self.m_auinotebook3.AddPage( self.m_panel4, u"a page", False, wx.NullBitmap )


		self.m_mgr.Update()
		self.Centre( wx.BOTH )

		# Connect Events
		self.Bind( wx.EVT_MENU, self.CloseUi, id = self.m_menuItem8.GetId() )
		self.Bind( wx.EVT_MENU, self.Open_Tab, id = self.m_menuItem9.GetId() )

	def __del__( self ):
		self.m_mgr.UnInit()



	# Virtual event handlers, overide them in your derived class
	def CloseUi( self, event ):
		event.Skip()

	def Open_Tab( self, event ):
		event.Skip()

if __name__ == "__main__":
		app = wx.App(False)
		frame = MyFrame2(None)
		frame.Show()
		app.MainLoop()
this event is responsible for opening the tab that had closed
def Open_Tab( self, event ):
		event.Skip()
Could you please help me? I would appreciate it for your time Pray


RE: how to reopen a closed tab of wx.aui.Notebook? - Yoriz - Feb-17-2019

When you close a tab it is destroyed, you cant re-open it, in the open_tab event, code will have to be added to create a new tab.


RE: how to reopen a closed tab of wx.aui.Notebook? - royer14 - Feb-18-2019

(Feb-17-2019, 05:04 PM)Yoriz Wrote: When you close a tab it is destroyed, you cant re-open it, in the open_tab event, code will have to be added to create a new tab.
But how could I do it?, since I only have this information
Documentation
of this more I have been struck by the following
EVT_AUINOTEBOOK_PAGE_CLOSE: --> A page is about to be closed. Processes a wxEVT_AUINOTEBOOK_PAGE_CLOSE event.
EVT_AUINOTEBOOK_PAGE_CLOSED(winid, fn): --> A page has been closed. Processes a wxEVT_AUINOTEBOOK_PAGE_CLOSED event.
I plan to use the following
RemovePage
but this only closes the tab but not its content and then I use the following to open the tab
AddPage