Wx.向导在列表理解中使用val()创建页面
wx示例。我发现的向导使用了页面的显式名称。在列表理解中使用eval(),我能够按名称遍历导入的模块并调用create()以获得页面实例。我想这是一个妙招。。。
选择 | 换行 | 行号
- #Boa:Wizard:Wizard1
- import wx
- import wx.wizard
- import SetupWizardPage1
- import SetupWizardPage2
- nSetupWizardPages = 2
- def create(parent):
- return Wizard1(parent)
- [wxID_WIZARD1] = [wx.NewId() for _init_ctrls in range(1)]
- class Wizard1(wx.wizard.Wizard):
- def _init_ctrls(self, prnt):
- # generated method, don't edit
- wx.wizard.Wizard.__init__(self, bitmap=wx.NullBitmap, id=wxID_WIZARD1, parent=prnt,
- pos=wx.Point(459, 285), title='HETAP Data Collection Setup')
- def __init__(self, parent):
- self._init_ctrls(parent)
- ## the old way
- ## page1 = SetupWizardPage1.ParkListPage(self)
- ## self.page1 = page1
- ## page2 = SetupWizardPage2.TrailListPage(self)
- ## I had to add create() to the SimpleWizardPage generated by Boa
- self.pages = pages = [eval("SetupWizardPage%d.create(self)" %i)
- for i in range(1, nSetupWizardPages + 1)]
- self.FitToPage(pages[0])
- ## Once they're in a list, chaining becomes a snap
- for i in range(nSetupWizardPages - 1):
- # Use the convenience Chain function to connect the pages in a loop
- wx.wizard.WizardPageSimple_Chain(pages[i], pages[i + 1])
- self.GetPageAreaSizer().Add(pages[0])
- def GetFirstPage(self):
- """I make the wizard responsible for creating the pages, so the caller must
- be able to get the first page for the Wizard.Run() argument"""
- return self.pages[0]
评论已关闭