Kivy:不推荐使用的功能的替代品 [英] Kivy: alternative to deprecated features

查看:88
本文介绍了Kivy:不推荐使用的功能的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改此代码,但我仍然是第一步不了解诸如 SelectableDataItem 适配器

I am trying adapt this code but I am still the first step as I don't understand most of the features called like like SelectableDataItem, Adapter, ListAdapter or SelectableView.

当我在kivy网站上查找它们时,我发现它们已被列为已弃用.我在Kivy网站上找不到这些功能的任何替代方法,并且我不想构建具有弃用功能的应用程序.

When I looked them up on the kivy website, I have seen that they are listed as deprecated. I don't find any alternatives to these features on the Kivy website and I don't want to build an app with deprecated features.

所以我的问题是:这四个功能的替代方案是什么?或者换句话说,我应该如何修改代码,以使其不调用不推荐使用的功能.

So my question is: what are the alternative to these four features or in other terms, how should I modify the code so that it doesn't call deprecated features.

推荐答案

看看

Take a look at RecycleView
I wrote an example of what you might want, with RecycleView

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.uix.recycleview.views import RecycleDataViewBehavior



items = [
    {"text": "white",    "selected": 'normal', "input_data": ["some","random","data"]},
    {"text": "lightblue","selected": 'normal', "input_data": [1,6,3]},
    {"text": "blue",     "selected": 'normal', "input_data": [64,16,9]},
    {"text": "gray",     "selected": 'normal', "input_data": [8766,13,6]},
    {"text": "orange",   "selected": 'normal', "input_data": [9,4,6]},
    {"text": "yellow",   "selected": 'normal', "input_data": [852,958,123]},
    {"text": "white",    "selected": 'normal', "input_data": ["some","random","data"]},
    {"text": "lightblue","selected": 'normal', "input_data": [1,6,3]},
    {"text": "blue",     "selected": 'normal', "input_data": [64,16,9]},
    {"text": "gray",     "selected": 'normal', "input_data": [8766,13,6]},
    {"text": "orange",   "selected": 'normal', "input_data": [9,4,6]},
    {"text": "yellow",   "selected": 'normal', "input_data": [852,958,123]}
]



class MyViewClass(RecycleDataViewBehavior, BoxLayout):

    text = StringProperty("")
    index = None

    def set_state(self,state,app):
        app.root.ids.rv.data[self.index]['selected'] = state

    def refresh_view_attrs(self, rv, index, data):
        self.index = index
        return super(MyViewClass, self).refresh_view_attrs(rv, index, data)



class MyRecycleView(RecycleView):

    data = items

    def print_data(self,data):
        print([item['input_data'] for item in data if item['selected'] == 'down'])



KV = '''

<MyViewClass>:
    orientation: 'horizontal'
    CheckBox:
        on_state: root.set_state(self.state,app)
    Label:
        text: root.text

BoxLayout:
    orientation: 'vertical'
    MyRecycleView:
        id: rv
        viewclass: 'MyViewClass'
        RecycleBoxLayout:
            orientation: 'vertical'
            default_size: None, dp(56)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
    Button:
        size_hint_y: 0.1
        text: "Print data"
        on_release: rv.print_data(rv.data)

'''



class Test(App):
    def build(self):
        root = Builder.load_string(KV)
        return root


Test().run()

这篇关于Kivy:不推荐使用的功能的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆