wxPython:禁用笔记本选项卡?

发布于 2024-11-29 16:37:19 字数 534 浏览 1 评论 0原文

有没有办法禁用笔记本选项卡?就像您可以使用小部件本身一样吗?我启动了一个很长的流程,虽然对于那些查看它的人来说应该是不言自明的,但我希望能够防止用户在其他选项卡中乱搞,直到它正在运行的流程完成为止。

我似乎在 wx.Notebook 中找不到任何可以帮助解决此问题的内容?

代码片段:

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")

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?

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")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

欢你一世 2024-12-06 16:37:19

它不能用 wx.Notebook 实现。但是您可以使用一些更高级的小部件,例如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()

It si not doable with wx.Notebook. But you can use some of the more advanced widgets such as 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()
恍梦境° 2024-12-06 16:37:19

从技术上讲,wx.Notebook 没有办法禁用选项卡。但是,您可以通过检查单击了哪个选项卡来执行相同的操作,如果它被“禁用”,则否决 EVT_NOTEBOOK_PAGE_CHANGING 或 EVT_NOTEBOOK_PAGE_CHANGED 事件。或者,您可以使用上面提到的 AUI 笔记本。请注意,这是来自 agw lib 的库,而不是来自 wx.aui 的库。 FlatNotebook 还提供禁用选项卡的功能。有关示例,请参阅 wxPython 演示。

Technically, wx.Notebook doesn't have a way to disable a tab. 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. Alternately, you can use the AUI notebook as mentioned above. Note that that is the one from the agw lib, NOT from the wx.aui one. The FlatNotebook also provides the ability to disable tabs. See the wxPython demo for an example.

梦巷 2024-12-06 16:37:19
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)

活动选项卡可以通过 Notebook.SetSelection() 设置。但事件应该解除绑定/禁用并在其周围绑定/启用,以避免无限循环。面板代码中应该有wx.BeginBusyCursor()、wx.EndBusyCursor()。然后,当应用程序繁忙时,选项卡更改将“禁用”。

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(). 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. Then The tab changing is "disabled" when app is busy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文