Kivy属性不可调用错误

时间:2015-10-18 09:45:51

标签: python user-interface properties kivy typeerror

我正在尝试在Kivy中实现一个图表工具,但是当我尝试实例化FlowChartNode类的一个实例时,我看到了以下错误:

Traceback (most recent call last):
   File "FlowChartExample.py", line 193, in <module>
     FlowChartExampleApp().run()
   File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 798, in run
     root = self.build()
   File "FlowChartExample.py", line 189, in build
     root = FlowChartExampleWidget()
   File "FlowChartExample.py", line 184, in __init__
     begin_node = FlowChartNode()
   File "FlowChartExample.py", line 116, in __init__
     super(FlowChartNode, self).__init__(**kwargs)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors.py", line 105, in __init__
     super(ButtonBehavior, self).__init__(**kwargs)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/label.py", line 187, in __init__
     super(Label, self).__init__(**kwargs)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 261, in __init__
     super(Widget, self).__init__(**kwargs)
   File "_event.pyx", line 252, in kivy._event.EventDispatcher.__init__ (kivy/_event.c:4505)
   File "_event.pyx", line 777, in kivy._event.EventDispatcher.properties (kivy/_event.c:7967)
 TypeError: 'ObservableList' object is not callable

这里是FlowChartNode类:

class FlowChartNode(Button):

    #Exposes the event on_properties to allow for binding to expose
    #properties panel in app on triple-press
    properties = ListProperty([0, 0])

    #Properties to set the backgrounds of the node
    background_draggable = StringProperty('img/drag_node_small.png')
    background_pressable = StringProperty('img/press_node_small.png')
    background_dragged = StringProperty('img/drag_node_down_small.png')
    background_pressed = StringProperty('img/press_node_down_small.png')

    #The components of the node
    front = ObjectProperty(None)
    back = ListProperty([])
    connect = ListProperty([])

    #The sparse grid being added to
    sparse_grid = ObjectProperty(None)

    #The assigned cell in the sparse grid
    cell = ObjectProperty(None)

    #Boolean state for draggable or pressable
    is_draggable = BooleanProperty(False)

    def __init__(self, **kwargs):
        super(FlowChartNode, self).__init__(**kwargs)
        if self.is_draggable:
            self.background_normal = self.background_draggable
        else:
            self.background_normal = self.background_pressable
        self.bind(pos=self.set_front)

    def on_touch_down(self, touch):
        if touch.is_triple_tap:
            self.properties = touch.pos
        elif touch.is_double_tap:
            if self.is_draggable:
                self.is_draggable=False
                self.background_normal = self.background_pressable
            else:
                self.is_draggable=True
                self.background_normal = self.background_draggable
        else:
            if self.is_draggable:
                self.background_normal = self.background_pressed
                touch.grab(self)
            else:
                self.background_normal = self.background_dragged
                #Add the connected node
                back_node = FlowChartNode(is_draggable=True)
                connector = FlowConnector()
                back_node.bind(pos=self.set_back)
                self.back.append(back_node)
                self.connect.append(connector)
                self.connect[len(connect) - 1].front = self.front.center
                self.cell.add_widget(connector)
                self.cell.add_widget(back_node)

        return super(FlowChartNode, self).on_touch_down(touch, *args)

    def on_touch_move(self, touch):
        if touch.grab_current == self:
            if self.collide_point(touch.pos):
                for cel in self.sparse_grid.cells:
                    if cel.collide_point(touch.pos):
                        #Snap the grabbed node to the cell
                        self.cell.clear_widgets()
                        self.cell = cel
                        cel.add_widget(self)
        return super(FlowChartNode, self).on_touch_move(touch, *args)

    def on_touch_up(self, touch):
        return super(FlowChartNode, self).on_touch_up(touch, *args)
        if self.is_draggable:
            self.background_normal = self.background_draggable
        else:
            self.background_normal = self.background_pressable

    def set_front(self, *args):
        for con in self.connect:
            con.front = self.center_node.center

    def set_back(self, *args):
        i=0
        for con in self.connect:
            con.back = self.options[i].center
            i+=1

大多数代码来自可以找到here的工作窗口小部件,以及其他成功的测试和工作窗口小部件。我已经审核了我与之交互的所有Kivy属性,但它们似乎得到了正确处理。我在这里做错了什么?

提前感谢您的帮助!

亚历

1 个答案:

答案 0 :(得分:0)

我最后以不同的方式重写了这些类,如果您有兴趣,可以找到完整的代码here