Wx.向导在列表理解中使用val()创建页面

wx示例。我发现的向导使用了页面的显式名称。在列表理解中使用eval(),我能够按名称遍历导入的模块并调用create()以获得页面实例。我想这是一个妙招。。。

选择 | 换行 | 行号
  1. #Boa:Wizard:Wizard1
  2.  
  3. import wx
  4. import wx.wizard
  5.  
  6. import SetupWizardPage1
  7. import SetupWizardPage2
  8.  
  9. nSetupWizardPages = 2
  10.  
  11. def create(parent):
  12.     return Wizard1(parent)
  13.  
  14. [wxID_WIZARD1] = [wx.NewId() for _init_ctrls in range(1)]
  15.  
  16. class Wizard1(wx.wizard.Wizard):
  17.     def _init_ctrls(self, prnt):
  18.         # generated method, don't edit
  19.         wx.wizard.Wizard.__init__(self, bitmap=wx.NullBitmap, id=wxID_WIZARD1, parent=prnt,
  20.               pos=wx.Point(459, 285), title='HETAP Data Collection Setup')
  21.  
  22.     def __init__(self, parent):
  23.         self._init_ctrls(parent)
  24.  
  25.     ## the old way
  26. ##        page1 = SetupWizardPage1.ParkListPage(self)
  27. ##        self.page1 = page1
  28. ##        page2 = SetupWizardPage2.TrailListPage(self)
  29.  
  30.     ## I had to add create() to the SimpleWizardPage generated by Boa
  31.         self.pages = pages = [eval("SetupWizardPage%d.create(self)" %i)
  32.                               for i in range(1, nSetupWizardPages + 1)]
  33.  
  34.         self.FitToPage(pages[0])
  35.  
  36.     ## Once they're in a list, chaining becomes a snap
  37.         for i in range(nSetupWizardPages - 1):
  38.             # Use the convenience Chain function to connect the pages in a loop
  39.             wx.wizard.WizardPageSimple_Chain(pages[i], pages[i + 1])
  40.  
  41.  
  42.         self.GetPageAreaSizer().Add(pages[0])
  43.  
  44.     def GetFirstPage(self):
  45.         """I make the wizard responsible for creating the pages, so the caller must
  46.            be able to get the first page for the Wizard.Run() argument"""
  47.         return self.pages[0]

标签: python

评论已关闭