【发布时间】:2019-04-05 04:19:17
【问题描述】:
有人知道是什么原因造成的吗?我的 Kivy RecycleView 在可编辑的后面有一个奇怪的静态版本 - 它不能以任何方式选择或更改。这让我觉得我可能有所有 Kivy 小部件的重复版本?我不愿意粘贴我的所有代码,因为它可以访问一个 api,并且在应用程序本身中有凭据信息以及大量个人信息。
双循环视图
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
RecycleBoxLayout):
''' Adds selection and focus behaviour to the view. '''
class SelectableLabel(RecycleDataViewBehavior, Label):
''' Add selection support to the Label '''
index = None
selected = BooleanProperty(False)
selectable = BooleanProperty(True)
def refresh_view_attrs(self, rv, index, data):
''' Catch and handle the view changes '''
self.index = index
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
def on_touch_down(self, touch):
''' Add selection on touch down '''
if super(SelectableLabel, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos) and self.selectable:
return self.parent.select_with_touch(self.index, touch)
def apply_selection(self, rv, index, is_selected):
''' Respond to the selection of items in the view. '''
self.selected = is_selected
if is_selected:
print("selection changed to {0}".format(rv.data[index]))
else:
print("selection removed for {0}".format(rv.data[index]))
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = [{'text': str(x)} for x in range(10)]
class GuiApp(App):
theme_cls = ThemeManager()
theme_cls.theme_style = 'Dark'
previous_date = ''
previous_date2 = ''
StartDate = ObjectProperty("Start Date")
EndDate = ObjectProperty("End Date")
def build(self):
self.pickers = Factory.AnotherScreen()
presentation = Builder.load_file("gui.kv")
return presentation
这是我的 Kivy:
RV:
id: rv
viewclass: 'SelectableLabel'
SelectableRecycleBoxLayout:
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
multiselect: True
touch_multiselect: True
<SelectableLabel>:
# Draw a background to indicate selection
canvas.before:
Color:
rgba: (.4, 0.4, .4, .3) if self.selected else (.2, .2, .2, 1)
Rectangle:
pos: self.pos
size: self.size
我希望这是足够的信息,至少可以让我知道在哪里查看。我也在努力更新 RecycleView 中的数据,但这可能是因为这个问题?我可能有两个不同的小部件实例正在运行,但我不确定这怎么可能..
【问题讨论】: