访问模块外部的类静态变量

时间:2014-04-23 09:41:54

标签: python

我有一个班级:

class WidgetCheckbox(Widget,ObjectValue,ObjectEvents,ObjectModifiers):
    dialogarguments = (True,False,False)
    def __init__(self,hitdata, name,value):
        Widget.__init__(self,hitdata, name)
        ObjectValue.__init__(self,value,True,False,False)
        ObjectEvents.__init__(self,"change")
        ObjectModifiers.__init__(self)

我在另一个模块中有一个类,它试图获取对话框参数的值:

def createWidget(self,blank,title,dialog_panel,insert_function,widget_class):
    dialog = AddDialog(self,title,dialog_panel,self.hitdata,*widget_class.dialogarguments)
    if dialog.ShowModal() == wx.ID_ADD:
        self.addReplace(blank,insert_function,widget_class,*dialog.getAdd())
    dialog.Destroy()

我遇到的问题是,当它运行时,我收到错误:

AttributeError: type object 'WidgetCheckbox' has no attribute 'dialogarguments'

有谁知道为什么会这样?

我得到的追溯是

Traceback (most recent call last):
  File "/Users/jack/PycharmProjects/HIT/gui/widgets.py", line 82, in onBlankClick
    self.createWidget(blank,*self.tools[tool])
  File "/Users/jack/PycharmProjects/HIT/gui/widgets.py", line 86, in createWidget
    dialog = AddDialog(self,title,dialog_panel,self.hitdata,*widget_class.dialogarguments)
AttributeError: type object 'WidgetCheckbox' has no attribute 'dialogarguments'

其中self.tools

self.tools = {
            data.tools.BUTTON: ("Add Button",PropertiesTextPanel,self.table.insertButton,WidgetButton)
            ,data.tools.CHECKBOX: ("Add Checkbox",PropertiesValuePanel,self.table.insertCheckbox,WidgetCheckbox)
            ,data.tools.LABEL: ("Add Label",PropertiesTextPanel,self.table.insertLabel,WidgetLabel)
            ,data.tools.COMBOBOX: ("Add Combobox",PropertiesValuePanel,self.table.insertCombobox,WidgetCombobox)
            ,data.tools.TABLE: ("Add Table",PropertiesGridPanel,self.table.insertTable,WidgetTable)
            ,data.tools.GRAPH: ("Add Graph",PropertiesValuePanel,self.table.insertGraph,WidgetGraph)
            ,data.tools.MODELABEL: ("Add Mode Label",PropertiesValuePanel,self.table.insertModeLabel,WidgetModeLabel)
            ,data.tools.NUMBERLABEL: ("Add Number Label",PropertiesValuePanel,self.table.insertNumberLabel,WidgetNumberLabel)
            ,data.tools.NUMBER: ("Add Number",PropertiesValuePanel,self.table.insertNumber,WidgetNumber)
            ,data.tools.RADIO: ("Add Radio",PropertiesValuePanel,self.table.insertRadio,WidgetRadio)
            ,data.tools.TOGGLE: ("Add Toggle",PropertiesValuePanel,self.table.insertToggle,WidgetToggle)
        }

0 个答案:

没有答案