Reputation: 1846
I have a Notebook
in wxpython:
self.book = wx.Notebook(self, -1, style=0)
self.book.AddPage(self.book_a,_("a"))
self.book.AddPage(self.book_b,_("b"))
This code works fine. Evrything is as it should.
The thing is that I have later a condition if x==1:
that if it's true I need to hide/disable book_b
page (preferbly disable).
i wrote this code:
if x==1:
self.book_a.Hide()
but nothing happend. Then I tried:
if x==1:
self.book_a.Disable()
but also nothing happend.
If I do:
print self.book_a.Hide()
print self.book_a.Disable()
it returns
False
False
I know it means the operation faild and that why I don't see any change but I couldn't find in google or elsewhere when Hide()
or Disable()
return False.
Does anyone know what is the problem or in what cases Hide()
or Disable()
return false?
Upvotes: 1
Views: 821
Reputation: 33071
The wx.Notebook
widget doesn't support disabling pages. The only workaround would be to check which tab is being clicked on and if it is "disabled", veto the event (EVT_NOTEBOOK_PAGE_CHANGING or EVT_NOTEBOOK_PAGE_CHANGED).
There is an alternative though. You can use the FlatNotebook widget or the AUI Notebook from wx.lib.agw (wx.aui's Notebook does not support this that I know of). They both support the the ability to disable a tab. There are examples of both of these widgets in the wxPython demo.
I have some examples of these controls here as well:
See also:
UPDATE - I just tried disabling a page. While it doesn't stop the user from clicking on the tab, it DOES disable all the controls on that page:
import wx
########################################################################
class TabPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
text = wx.TextCtrl(self)
########################################################################
class MainPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
notebook = wx.Notebook(self)
tab_one = TabPanel(notebook)
notebook.AddPage(tab_one, "Tab One")
tab_two = TabPanel(notebook)
tab_two.Disable()
notebook.AddPage(tab_two, "Tab Two")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Notebooks")
panel = MainPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
Upvotes: 1