Kivy Screenmanager和RecycleView的滞后

时间:2019-05-23 06:08:57

标签: python-3.x user-interface kivy raspberry-pi3

我正在使用Screenmanager向用户显示6个不同的屏幕。为了显示数据库值,我借助RecycleView创建了一个数据网格。网格看起来像这样:

enter image description here

不幸的是,当用户选择“测量”屏幕时,它需要几秒钟才能显示数据网格,或者滞后于显示网格。同样,当用户选择一行时,最多需要2秒钟才能显示后面的屏幕。如果用户单击包含许多内容的不同屏幕,则该GUI会流畅运行。 GUI在带有触摸屏的RaspberryPi 3上运行。如果应用程序正在运行,则Raspberry硬件并不真正繁忙,因此这不会成为硬件功能的问题。

kv文件:

<SelectableButtonGridMeasure>:
    # Draw a background to indicate selection
    canvas.before:
        Color:
            rgba: (0.19, 0.35, 0.45, 1) if self.selected else (0, 0, 0, 1)
        Rectangle:
            pos: self.pos
            size: self.size
    background_normal: ''
    background_down: 'icons/bkgrd-down-color.png'
    background_color: 0.25, 0.24, 0.33, 70
    on_press: app.root.ids.scr_mngr.current = 'screenmeasuringtask'


Wsrmescreenmeasure:

<Wsrmescreenmeasure>:
    id: wsrmescreen_measure_kv
    grid_measuring_task: grid_kvmeasuring_task

    padding: 30
    spacing: 10

    viewclass: 'SelectableButtonGridMeasure'
    SelectableRecycleGridLayoutMeasure:
        id: grid_kvmeasuring_task
        default_size: None, dp(35)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
        multiselect: False
        touch_multiselect: False
        cols: 5
        markup: True

将数据添加到网格:

    # Put data to datagrid in screenmeasure
    Wsrmescreenmeasure.data = temp_data

    # Update inserted data in data grid    
    Wsrmescreenmeasure.refresh_from_data(App.get_running_app().
            root.ids.screenmeasure_kv.grid_measuring_task.recycleview)

创建数据网格:

# Datagrid measure
class Wsrmescreenmeasure(RecycleView):
    def __init__(self, **kwargs):
        super(Wsrmescreenmeasure, self).__init__(**kwargs)
        # Design datagrid for measuring tasks
        self.data = w_logic.WsrmeLogic.get_data(self)

这种滞后的原因可能是什么?如果减少datagrid的内容(例如,从10行减少到5行),我会觉得它的速度要快一些。我测量了用装饰器填充数据等的时间,但是我没有发现任何线索。

0 个答案:

没有答案