简体   繁体   English

wxPython:禁用笔记本选项卡?

[英]wxPython: Disable a notebook tab?

Is there anyway to disable a notebook tab?无论如何要禁用笔记本选项卡? Like you can with the Widgets themselves?就像您可以使用小部件本身一样? I have a long process I kick off, and while it should be pretty self-explanatory for those looking at it, I want to be able to prevent the user from mucking around in other tabs until the process it is running is complete.我开始了一个漫长的过程,虽然对于那些查看它的人来说应该是不言自明的,但我希望能够防止用户在其他选项卡中乱搞,直到它正在运行的过程完成。

I couldn't seem to find anything in wx.Notebook to help with this?我似乎在wx.Notebook中找不到任何帮助解决此问题的内容?

Code snippet:代码片段:

def __init__(self, parent):
    wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)

    self.AddPage(launchTab.LaunchPanel(self), "Launch")
    self.AddPage(scanTab.ScanPanel(self), "Scan")
    self.AddPage(extractTab.ExtractPanel(self), "Extract")
    self.AddPage(virtualsTab.VirtualsPanel(self), "Virtuals")

It si not doable with wx.Notebook . wx.Notebook无法做到这一点。 But you can use some of the more advanced widgets such as wx.lib.agw.aui.AuiNotebook :但是您可以使用一些更高级的小部件,例如wx.lib.agw.aui.AuiNotebook

import wx
import wx.lib.agw.aui as aui

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        style = aui.AUI_NB_DEFAULT_STYLE ^ aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
        self.notebook = aui.AuiNotebook(self, agwStyle=style)      

        self.panel1 = wx.Panel(self.notebook)
        self.panel2 = wx.Panel(self.notebook)
        self.panel3 = wx.Panel(self.notebook)

        self.notebook.AddPage(self.panel1, "First")
        self.notebook.AddPage(self.panel2, "Second")
        self.notebook.AddPage(self.panel3, "Third")

        self.notebook.EnableTab(1, False)

        self.Show()


app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

Technically, wx.Notebook doesn't have a way to disable a tab.从技术上讲,wx.Notebook 没有办法禁用选项卡。 However, you can do the same thing by checking which tab is clicked on and if it is "disabled", veto the EVT_NOTEBOOK_PAGE_CHANGING or EVT_NOTEBOOK_PAGE_CHANGED event.但是,您可以通过检查单击哪个选项卡来执行相同的操作,如果它被“禁用”,则否决 EVT_NOTEBOOK_PAGE_CHANGING 或 EVT_NOTEBOOK_PAGE_CHANGED 事件。 Alternately, you can use the AUI notebook as mentioned above.或者,您可以使用上面提到的 AUI 笔记本。 Note that that is the one from the agw lib, NOT from the wx.aui one.请注意,这是来自 agw 库的那个,而不是来自 wx.aui 的那个。 The FlatNotebook also provides the ability to disable tabs. FlatNotebook 还提供禁用选项卡的功能。 See the wxPython demo for an example.有关示例,请参见 wxPython 演示。

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        p = wx.Panel(self)
        self.nb = wx.Notebook(p)
        ......

        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)

    def OnPageChanged(self, event):
        if wx.IsBusy():
            self.Unbind(wx.EVT_NOTEBOOK_PAGE_CHANGED)
            self.nb.SetSelection(event.GetOldSelection())
            self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)

The active tab can be set by Notebook.SetSelection().活动选项卡可以通过 Notebook.SetSelection() 设置。 But the event should be unbinded/disable and bind/enable around it to avoid in infinite looping.但是事件应该是未绑定/禁用和绑定/启用,以避免无限循环。 There should be wx.BeginBusyCursor(), wx.EndBusyCursor() in panel codes.面板代码中应该有 wx.BeginBusyCursor()、wx.EndBusyCursor()。 Then The tab changing is "disabled" when app is busy.然后当应用程序繁忙时,选项卡更改被“禁用”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM