wx.Wizard在列表推导中使用eval()创建页面

我发现的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值