我发现的wx.Wizard的示例使用了页面的显式名称。
在列表理解中使用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]
From: https://bytes.com/topic/python/insights/579232-wx-wizard-creates-pages-using-eval-list-comprehension