0

这是我在 Boa Constructor 中的第一个应用程序,也是我第一次使用 wxPython。

#Boa:Frame:Frame1

import wx

choiceList = ['DAR', 'Impex', 'Endon', 'Astro', 'Ansell', 'Other']

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTONSELECTDIR, wxID_FRAME1BUTTONSELECTFILE, 
 wxID_FRAME1CHOICESUPPLIER, 
] = [wx.NewId() for _init_ctrls in range(4)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(517, 20), size=wx.Size(400, 492),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(392, 458))

        self.choiceSupplier = wx.Choice(choices=choiceList, id=wxID_FRAME1CHOICESUPPLIER,
              name=u'choiceSupplier', parent=self, pos=wx.Point(48, 176),
              size=wx.Size(120, 21), style=0)
        self.choiceSupplier.Bind(wx.EVT_CHOICE, self.OnChoiceSupplierChoice,
              id=wxID_FRAME1CHOICESUPPLIER)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnChoiceSupplierChoice(self, event):
        supplier = choiceList[self.choiceSupplier.GetSelection()]
        print supplier

单击运行应用程序时,我的代码运行良好。但是,当我尝试在设计器中对其进行编辑时,出现错误:

16:17:06: Traceback (most recent call last): 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Models\wxPythonControllers.py", line 78, in OnDesigner     self.showDesigner() 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Models\wxPythonControllers.py", line 143, in showDesigner     designer.refreshCtrl() 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 399, in refreshCtrl     self.initObjectsAndCompanions(objCol.creators[1:], objCol, deps, depLnks) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\InspectableViews.py", line 127, in initObjectsAndCompanions     self.initObjCreator(constr) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 529, in initObjCreator     InspectableObjectView.initObjCreator(self, constrPrs) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\InspectableViews.py", line 155, in initObjCreator     constrPrs.comp_name, constrPrs.params) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 483, in loadControl     compClass=CtrlCompanion, evalDct=self.model.specialAttrs) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\Views\Designer.py", line 62, in setupArgs     args = InspectableObjectView.setupArgs(self, ctrlName, params, dontEval, evalDct=evalDct) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\View \InspectableViews.py", line 63, in setupArgs     evalDct) 
16:17:06:   File "C:\Python27\Lib\site-packages\boa-constructor\PaletteMapping.py", line 158, in evalCtrl     return eval(expr, globals(), localsDct) 
16:17:06:   File "<string>", line 1, in <module> 
16:17:06: NameError: name 'choiceList' is not defined 
4

1 回答 1

1

在寻找其他与 boa-constructor 相关的东西时偶然发现了这个问题,如果在这里回答有点死的帖子被认为是失礼,我很抱歉,我是新来的。

无论如何,我最好的猜测是你自己弄乱了 _init_ctrls 即使有“不要编辑”的评论。自己试过几次,蟒蛇处理得不太好。改变后

self.choiceSupplier = wx.Choice(choices=choiceList

self.choiceSupplier = wx.Choice(choices=''

您可以再次输入设计器,并且能够拥有并填充 wx.Choice 项目,我将列表移入init

#Boa:Frame:Frame1

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1CHOICESUPPLIER, 
] = [wx.NewId() for _init_ctrls in range(2)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(517, 20), size=wx.Size(408, 496),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(392, 458))

        self.choiceSupplier = wx.Choice(choices=self.choiceList,
              id=wxID_FRAME1CHOICESUPPLIER, name=u'choiceSupplier', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(392, 21), style=0)
        self.choiceSupplier.Bind(wx.EVT_CHOICE, self.OnChoiceSupplierChoice,
              id=wxID_FRAME1CHOICESUPPLIER)

    def __init__(self, parent):
        self.choiceList = ['DAR', 'Impex', 'Endon', 'Astro', 'Ansell', 'Other']
        self._init_ctrls(parent)

    def OnChoiceSupplierChoice(self, event):
        supplier = choiceList[self.choiceSupplier.GetSelection()]
        print supplier

if __name__ == '__main__':
    application = wx.PySimpleApp()
    someFrame = Frame1(None)
    someFrame.Show()
    application.MainLoop()

问题可能是设计器会话如何分析文件,错过了类外部的列表。

于 2014-01-16T00:32:31.753 回答