有谁知道是什么原因引起的?我的Kivy RecycleView在可编辑的后面有一个奇怪的静态版本 - 无法以任何方式选择或更改它。这让我觉得我可能有我所有Kivy小部件的重复版本?我犹豫是否要粘贴我的所有代码,因为它到达api并且在应用程序本身中具有凭据信息以及许多个人信息。
DoubledRecycleView
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中的数据,但这可能是因为这个问题?我可能有两个不同的小部件运行实例,但我不确定这是怎么可能的..
double是由于按文件名约定加载kv文件并使用Builder
。
例如:使用Builder.load_file('gui.kv')
,您的kv文件名是gui.kv
。
class GuiApp(App):
...
def build(self):
self.pickers = Factory.AnotherScreen()
presentation = Builder.load_file("gui.kv")
return presentation
该问题有两种解决方案。
将app类从GuiApp()
重命名为TestApp()
只要存在根规则,就不需要在App类中返回任何内容,例如qzxswpoi在kv文件中。
删除以下内容:
BoxLayout:
presentation = Builder.load_file("gui.kv")
return presentation
有两种方法可以将Kv代码加载到您的应用程序中:
按名称惯例:
Kivy以小写形式查找与App类同名的Kv文件,如果以“App”结尾,则减去“App”,例如:
Kv language » How to load KV如果此文件定义了Root Widget,它将附加到App的root属性,并用作应用程序窗口小部件树的基础。
按生成器惯例:
您可以告诉Kivy直接加载字符串或文件。如果此字符串或文件定义了根窗口小部件,则该方法将返回该窗口小部件:
MyApp -> my.kv
要么:
Builder.load_file('path/to/file.kv')
Builder.load_string(kv_string)
from kivy.app import App
class GuiApp(App):
def build(self):
self.pickers = None
if __name__ == "__main__":
GuiApp().run()
#:kivy 1.11.0
Button:
text: 'Hello Kivy'
font_size: 50