在Python中检索现有实例

时间:2013-07-19 16:00:30

标签: python arcgis

我想将另一个类中的现有实例调用到Python中的其他类,但我不知道如何做到这一点,帮助!

class ButtonSelectRetire(object):

    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):        

        cbr = ButtontRetire()
        cbr.off()     

class ButtontRetire(object):

    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):
        pass

    def on (self):
        self.enabled = True

    def off (self):
        self.enabled = False

1 个答案:

答案 0 :(得分:0)

也许您可以将ButtonRetire的实例传递给ButtonSelectRetire的构造函数:

class ButtonSelectRetire(object):

  def __init__(self, button_retire):
    self.enabled = True
    self.checked = False
    self.button_retire = button_retire

  def onClick(self):        
    self.button_retire.off()


>>> buttonRetire = ButtonRetire()
>>> buttonSelectRetire = ButtonSelectRetire(buttonRetire)

事实上,据我所知,您希望将信号buttonSelectRetire.onClick与回调buttonRetire.off()相关联?

如果您使用的是PyQt4程序,可以轻松完成:

self.buttonSelectRetire.onClick.connect(self.buttonRetire.off)