Python Kivy从ListView拖放

Python Kivy从ListView拖放,python,kivy,Python,Kivy,我正在尝试设置ListView,以便 1) 进行选择时,该选择将从ListView中删除 2) 创建一个散点,其中包含一个带有选定内容文本的标签 3) 使用相同的单击,分散在屏幕上拖动 4) 释放单击后,将删除散布 我是在tkinter做的,我正试着把它转换成Kivy。在大多数情况下,这相当简单,但我遇到了几个问题。我遇到的第一个问题是如何选择ListView。ListView的on\u touch\u down事件在ListView适配器的on\u selection\u change事件之前

我正在尝试设置ListView,以便

1) 进行选择时,该选择将从ListView中删除

2) 创建一个散点,其中包含一个带有选定内容文本的标签

3) 使用相同的单击,分散在屏幕上拖动

4) 释放单击后,将删除散布

我是在tkinter做的,我正试着把它转换成Kivy。在大多数情况下,这相当简单,但我遇到了几个问题。我遇到的第一个问题是如何选择ListView。ListView的
on\u touch\u down
事件在ListView适配器的
on\u selection\u change
事件之前被触发,因此如果我绑定到
on\u touch\u down
,我会得到上一个选择,而不是当前选择。第二个问题是拖动散布。目标是让用户在单击一次后,从ListView中进行选择,显示一个散点并在屏幕上拖动它,然后在释放单击时删除散点。我尝试在以下方法中使用
touch.grab()
,该方法绑定到列表视图的
on\u touch\u down

def onPress(self, view, touch):
    if view.collide_point(touch.x, touch.y):
        self.floatLayout.add_widget(self.scatter)
        touch.grab(self.scatter)
但是当我点击列表视图时,我得到了一个
TypeError:cannotcreateweakproxy'对象的弱引用
error,尽管在我的.kv文件中有
keyScatter:keyScatter.\uuuu self\uuuuu
,并且
keyScatter
self.scatter
的id


这两个问题都有很好的解决方案吗?

对于任何试图从列表视图进行拖放的人来说,有一个好消息:解决方案已经存在。为了解决这个问题,我使用了绑定到ListView适配器的
on\u-selection\u-change
、ListView的
on\u-touch\u-down
、用于拖放的散点的
on\u-touch\u-up
的方法,如下代码块所示

self.listview.bind(on_touch_down=self.press)
self.scatter.bind(on_touch_up=self.release)
self.adapter.bind(on_selection_change=self.selectionChange)

def selectionChange(self, adapter):
    if adapter.selection: #Sometimes the selection was [], so a check doesn't hurt 
        names = adapter.data
        self.scatter.children[0].text = adapter.selection[0].text #My scatter has a label as it's first and only child. Here, I'm changing the label's text
        for j in adapter.data:
            if j == adapter.selection[0].text:
                break
        names.pop(names.index(j))
        self.listview.adapter.data = names
        if(hasattr(self.listview, '_reset_spopulate')): #This is used to reset the ListView
            self.listview._reset_spopulate()

def press(self, view, touch):
    if view.collide_point(touch.x, touch.y) and not touch.is_mouse_scrolling:
        self.scatter.center = touch.pos
        self.floatLayout.add_widget(self.scatter) #The scatter appears on the click
        self.scatter.on_touch_down(touch) #Needs to be called to get the scatter to be dragged

def release(self, scatter, touch):
    if scatter.collide_point(touch.x, touch.y) and touch.grab_current: #Because Kivy's on_touch_up doesn't work like I think it does

        #Do whatever you want on the release of the scatter

        self.floatLayout.remove_widget(self.scatter) #Remove the scatter on release