【发布时间】:2019-09-01 02:35:08
【问题描述】:
我正在尝试从Newline 附加RV 的数据。我看到refresh_view_attrs 有效,但屏幕上没有显示任何内容。我该怎么做?
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.gridlayout import GridLayout
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.clock import Clock
Builder.load_string('''
<SelectableLabel>:
# Draw a background to indicate selection
canvas.before:
Color:
rgba: (0, 0, 0, 1)
Rectangle:
pos: self.pos
size: self.size
pos: self.pos
size: self.size
Label:
id: id_label
<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
''')
class SelectableRecycleBoxLayout(LayoutSelectionBehavior,
RecycleBoxLayout):
''' Adds selection and focus behaviour to the view. '''
class SelectableLabel(RecycleDataViewBehavior, GridLayout):
''' Add selection support to the Label '''
def refresh_view_attrs(self, rv, index, data):
print('SelectableLabel', data)
self.ids['id_label'].text = data['label']
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = []
rv = RV()
class Newline(GridLayout):
def __init__(self, **kwargs):
Clock.schedule_once(self.add_line, 3)
def add_line(self, dt):
d = {'label': 'NEW LINE'}
rv.data.append(d)
Newline()
class TestApp(App):
def build(self):
return RV()
if __name__ == '__main__':
TestApp().run()
【问题讨论】:
标签: kivy