0
我想實現在Kivy圖的工具,但我看到下面的錯誤,當我嘗試實例化FlowChartNode類的一個實例:Kivy屬性不可調用的錯誤
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屬性,並且它們看起來是正確處理的。我在這裏做錯了什麼?
在此先感謝您的幫助!
亞歷