为什么以及由谁在 kivy 中调用这种方法

Why and by whom is this method called in kivy

我用 kivy 迈出了第一步,并尝试绘制通过 matplotlib 或 pygal 在 TextInput 中输入的函数。只要我将图像保存在磁盘上,两者都可以正常工作。为了加快程序速度,我不想将图像写入磁盘或从磁盘读取图像。我在 mornie.org 上找到了以下解决方案:

class MemoryImage(Image):
    """Display an image already loaded in memory."""
    memory_data = ObjectProperty(None)

    def __init__(self, memory_data, **kwargs):
            super(MemoryImage, self).__init__(**kwargs)

            self.memory_data = memory_data

    def on_memory_data(self, *args):
            """Load image from memory."""
            data = StringIO.StringIO(self.memory_data)
            with self.canvas:
                    self.texture = ImageLoaderPygame(data).texture

通过随机更改单词直到它在 python3 下运行我找到了这个解决方案:

class MemoryImage(Image):
    """Quelle: https://mornie.org/blog/2013/11/06/how-load-image-memory-kivy/"""
    memory_data = ObjectProperty(None)
    def __init__(self,memory_data,**kwargs):
            """Display an image already loaded in memory."""
            super(MemoryImage, self).__init__(**kwargs)
            self.memory_data = memory_data

    def on_memory_data(self, *args):
            """Load image from memory."""
            data = BytesIO(self.memory_data)
            with self.canvas:
                    self.texture = ImageLoaderPygame(filename="test.png",rawdata=data, ext="png", inline=True).texture

只要我不尝试更新图像,此解决方案就可以正常工作。不幸的是,这是我的意图。所以我试着去理解这个class。但我不能 - 前面我是 OOP 的新兵 - 找到一个调用此 on_memory_data 方法的点。首先,我搜索了这个 class 的父级,然后我搜索了 kivy,最后搜索了我的整个 /usr 文件夹,寻找包含 'on_memory' 的 python 个文件,但什么也没有。

如果有人能给我提示,为什么调用这个方法,我将不胜感激!

on_memory_datamemory_data ObjectProperty 更改时调用(即,当它引用的对象被替换时,它不知道对象的内部更改)。这是 kivy 属性的自动行为。