2

Python 3.6.4 - Kivy 1.11.1 - KivyMD 0.104.1

I'm fairly new with Kivy and kivyMD, and even more with threading and shared resources.

Today, I fill in the 3 MDGridlayouts (sbgridfamily, sbgridgender, sbgridspecies) sequentially with SmartTileWithLabels. It works fine, however the loading time is quite long (~5 sec.).

To optimize this loading, I tried

  1. to split the loads in different threads, without using a lock or a semaphore, some cells end up empty.

  2. to remove the MDGridlayouts from the structure and create them on the fly in one thread, then I get an assertion error as soon as I add the first tile to a MDGridlayout.

    _apply_rule assert(rule not in self.rulectx)
    AssertionError
    

So what would be the best approach to build the MDGridlayouts in parallel?

The screen has the here below structure:

<Screen>
BoxLayout:
    orientation:'vertical'

    MDToolbar:
        title: 'Titre'
        ...
    
    MDTabs:

        Tab:
            text: "Famille"

            ScrollView:
                id: sbgfscrollview
                do_scroll_x: False

                MDGridLayout:
                    id: sbgridfamily
                    ...
        Tab:
            text: "Genre"

            ScrollView:
                do_scroll_x: False

                MDGridLayout:
                    id: sbgridgender
                    cols: 3
                    ... 

        Tab:
            text: "Esp\u00E8ce"

            ScrollView:
                do_scroll_x: False

                MDGridLayout:
                    id: sbgridspecies
                    cols: 4
                    ...

    # Will always be at the bottom of the screen.
    BottomAppBar:

Screen with first tab and gridlayout

4

1 回答 1

1

Python 3.6.4 - Kivy 1.11.1 - KivyMD 0.104.1

我的问题是大约 300 个缩略图的创建和加载时间,如果它们从缓存中丢失,则可以即时调整图像大小。

为了在不使用线程的情况下进行优化,我将重定向我的下一个开发,在启动应用程序时使用 Clock.schedule_once 为每个选项卡(50 个缩略图)加载画廊至少一页,然后使用 on_scroll_start 和 on_scroll_move 按需逐页加载滚动视图事件。

经过快速尝试,使用这种方法,屏幕第一次出现不到一秒钟,然后立即出现。

于 2020-08-21T16:58:43.247 回答