Wxpython wxAuiNotebook-防止某些选项卡关闭
我正在试验wx.aui.AuiNotebook;有没有办法防止关闭特定选项卡?i、 e.我有一个应用程序,允许用户在一个AuiNotebook中创建多个选项卡,但前两个选项卡是系统管理的,我不希望它们被关闭Wxpython wxAuiNotebook-防止某些选项卡关闭,wxpython,Wxpython,我正在试验wx.aui.AuiNotebook;有没有办法防止关闭特定选项卡?i、 e.我有一个应用程序,允许用户在一个AuiNotebook中创建多个选项卡,但前两个选项卡是系统管理的,我不希望它们被关闭 此外,在关闭事件中,是否可以将窗口对象附加到正在关闭的选项卡?(从中提取数据)我遇到过类似的情况,我想阻止用户关闭最后一个选项卡。我所做的是绑定wx.aui.EVT\u AUINOTEBOOK\u PAGE\u CLOSE事件,然后在事件处理程序中检查打开的选项卡数量。如果选项卡的数量少于两
此外,在关闭事件中,是否可以将窗口对象附加到正在关闭的选项卡?(从中提取数据)我遇到过类似的情况,我想阻止用户关闭最后一个选项卡。我所做的是绑定
wx.aui.EVT\u AUINOTEBOOK\u PAGE\u CLOSE
事件,然后在事件处理程序中检查打开的选项卡数量。如果选项卡的数量少于两个,我会在活动选项卡上切换wx.aui.aui\u NB\u CLOSE\u
样式,以便最后一个选项卡没有关闭按钮
class MyAuiNotebook(wx.aui.AuiNotebook):
def __init__(self, *args, **kwargs):
kwargs['style'] = kwargs.get('style', wx.aui.AUI_NB_DEFAULT_STYLE) & \
~wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
super(MyAuiNotebook, self).__init__(*args, **kwargs)
self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.onClosePage)
def onClosePage(self, event):
event.Skip()
if self.GetPageCount() <= 2:
# Prevent last tab from being closed
self.ToggleWindowStyle(wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
def AddPage(self, *args, **kwargs):
super(MyAuiNotebook, self).AddPage(*args, **kwargs)
# Allow closing tabs when we have more than one tab:
if self.GetPageCount() > 1:
self.SetWindowStyle(self.GetWindowStyleFlag() | \
wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
类MyAuiNotebook(wx.aui.AuiNotebook):
定义初始化(self,*args,**kwargs):
kwargs['style']=kwargs.get('style',wx.aui.aui\u NB\u DEFAULT\u style)&\
~wx.aui.aui\u NB\u关闭活动选项卡上的\u
super(MyAuiNotebook,self)。\uuuu初始值(*args,**kwargs)
self.Bind(wx.aui.EVT\u AUINOTEBOOK\u PAGE\u CLOSE,self.onClosePage)
def onClosePage(自身、事件):
event.Skip()
如果self.GetPageCount()为1:
self.setWindowsStyle(self.getWindowsStyleFlag()|\
wx.aui.aui\u NB\u关闭(在活动选项卡上)
很晚了,我正在使用wx.lib.agw.aui
。但也许对其他人有用
import wx
import wx.lib.agw.aui as aui
class MyForm(wx.Frame):
def __init__(self):
super().__init__(None, wx.ID_ANY, "1 & 2 do not close")
self.reportDown = aui.auibook.AuiNotebook(
self,
agwStyle=aui.AUI_NB_TOP|aui.AUI_NB_TAB_SPLIT|aui.AUI_NB_TAB_MOVE|aui.AUI_NB_SCROLL_BUTTONS|aui.AUI_NB_CLOSE_ON_ALL_TABS|aui.AUI_NB_MIDDLE_CLICK_CLOSE|aui.AUI_NB_DRAW_DND_TAB,
)
self.reportDown.AddPage(wx.Panel(self.reportDown), '1, I do not close')
self.reportDown.AddPage(wx.Panel(self.reportDown), '2, I do not close')
self.reportDown.AddPage(wx.Panel(self.reportDown), '3, I do close')
#--> For this to work you must include aui.AUI_NB_CLOSE_ON_ALL_TABS
#--> in the agwStyle of the AuiNotebook
# Remove close button from first tab
self.reportDown.SetCloseButton(0, False)
# Remove close button from second tab
self.reportDown.SetCloseButton(1, False)
self._mgr = aui.AuiManager()
self._mgr.SetManagedWindow(self)
self._mgr.AddPane(
self.reportDown,
aui.AuiPaneInfo(
).Center(
).Caption(
'1 & 2 do not close'
).Floatable(
b=False
).CloseButton(
visible=False
).Movable(
b=False
),
)
self._mgr.Update()
#---
#---
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()