gpt4 book ai didi

wxpython - wxAuiNotebook - 防止某些选项卡关闭

转载 作者:行者123 更新时间:2023-12-04 14:44:58 24 4
gpt4 key购买 nike

我正在试验 wx.aui.AuiNotebook;有什么办法可以防止关闭特定的标签页吗?即我有一个允许用户在 AuiNotebook 中创建多个选项卡的应用程序,但前 2 个选项卡是系统管理的,我不希望它们被关闭。

此外,在关闭事件中,我能否获取附加到正在关闭的选项卡的窗口对象? (从中提取数据)

最佳答案

我有过类似的情况,我想阻止用户关闭最后一个选项卡。我所做的是绑定(bind) wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE 事件,然后在事件处理程序中检查打开的选项卡数量。如果选项卡的数量少于两个,我将切换 wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB 样式,以便最后一个选项卡没有关闭按钮。

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)

关于wxpython - wxAuiNotebook - 防止某些选项卡关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com