如何找出事件发生在哪个AuiNotebook页面?
编辑:抱歉。这是一个代码示例。我如何找到笔记本页面 从女巫鼠标被点击?#!/usr/bin/python
#12_aui_notebook1.py
import wx
import wx.lib.inspection
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.nb = wx.aui.AuiNotebook(self)
self.new_panel('Pane 1')
self.new_panel('Pane 2')
self.new_panel('Pane 3')
def new_panel(self, nm):
pnl = wx.Panel(self)
self.nb.AddPage(pnl, nm)
self.sizer = wx.BoxSizer()
self.sizer.Add(self.nb, 1, wx.EXPAND)
self.SetSizer(self.sizer)
pnl.Bind(wx.EVT_LEFT_DOWN, self.click)
def click(self, event):
print 'Mouse click'
#How can I find out from witch page this click came from?
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, '12_aui_notebook1.py')
frame.Show()
self.SetTopWindow(frame)
return 1
if __name__ == "__main__":
app = MyApp(0)
# wx.lib.inspection.InspectionTool().Show()
app.MainLoop()
Oerjan Pettersen
答案 0 :(得分:1)
对于鼠标单击,您可以假设当前所选页面是获得点击的页面。我在你的代码中添加了几行代码。见评论
def new_panel(self, nm):
pnl = wx.Panel(self)
# just to debug, I added a string attribute to the panel
# don't you love dynamic languages? :)
pnl.identifierTag = nm
self.nb.AddPage(pnl, nm)
self.sizer = wx.BoxSizer()
self.sizer.Add(self.nb, 1, wx.EXPAND)
self.SetSizer(self.sizer)
pnl.Bind(wx.EVT_LEFT_DOWN, self.click)
def click(self, event):
print 'Mouse click'
# get the current selected page
page = self.nb.GetPage(self.nb.GetSelection())
# notice that it is the panel that you created in new_panel
print page.identifierTag