Greetings.
I’m a newbie wxPython user and am struggling
a bit with the wx.Notebook control. If someone is able to help steer
me in the right direction, I’d appreciate the help.
As a starting point let’s say I am working
with ZetCode’s skeleton SpreadSheet
code:
http://www.zetcode.com/wxpython/skeletons/
- How do I determine which sheet in
wx.Notebook control currently has focus? And that sheet’s name/label?
As a contrived example, perhaps I have a
dialog with a simple wx.StaticText widget that displays the sheets name
(triggered via a menu selection).
import wx
class
ContrivedDialog(wx.Dialog):
def init(self, parent):
wx.Dialog.init(self, None, -1, title=“Where am I?”)
sizer = wx.BoxSizer(wx.VERTICAL)
whoHasFocus = INSERT_MAGIC_METHOD_HERE # who has focus?
lbl = wx.StaticText(self, -1, "Sheet Name: %s"
% whoHasFocus.GetSOMETHING(), size=(200,25))
btn = wx.Button(self, wx.ID_OK, "Close Me")
sizer.Add(lbl)
sizer.Add(btn)
self.SetSizer(sizer)
sizer.Fit(self)
self.Show()
- How do I set the focus to a different
sheet?
Sticking with my contrived example, here’s a
skeleton.
import
wx
def
init(self, parent):
wx.Dialog.__init__(self, None, -1, title="Where am I?")
sizer = wx.BoxSizer(wx.VERTICAL)
whoHasFocus = INSERT_MAGIC_METHOD1_HERE # who has focus?
newlyFocused = INSERT_MAGIC_METHOD2_HERE #
set focus to different sheet
lbl1 = wx.StaticText(self, -1, "Was on
Sheet Name: %s" % whoHasFocus.GetSOMETHING(), size=(200,25))
lbl2 = wx.StaticText(self, -1,
“Refocused to Sheet Name: %s” % newlyFocused .GetSOMETHING(),
size=(200,25))
btn = wx.Button(self, wx.ID_OK, "Close Me")
sizer.Add(lbl1)
sizer.Add(lbl2)
sizer.Add(btn)
self.SetSizer(sizer)
sizer.Fit(self)
self.Show()
In both examples, the GetSOMETHING() method outputs
the string label used when adding a widget to a sheet in a wx.Notebook
control via:
notebook.AddPage(sheet1,
‘Sheet1’)
So Sheet1 if Sheet1 has focus.
Cheers!
Rob