pythonkivy-languagedynamic-class-creation

Dynamic Class has no effect - Ellipse


I am starting out with kivy and I have already hit a roadblock that I cannot solve. All I want is to create a dynamic Ellipse class in kv file and then project that on the canvas of a widget.

What I see is that it is recognized as an Ellipse, but none of the attributes are taken over (most notably size).

I have given my code below and a screenshot of what I see. Please note the extra size in one Ellipse was made for your viewing pleasure to make the problem more visual. without it, I see three very large circles.

I am doing this on ubuntu 16.04. in case that is important

Thanks so much in advance for helping me out :)

main.py

#!usr/bin/python3

from kivy.app import App
from kivy.uix.widget import Widget


class SchemeEditor(Widget):
    def __init__(self,**kwargs):
        super(SchemeEditor, self).__init__(**kwargs)


class SchemeApp(App):
    def build(self):
        self.load_kv('scheme.kv')
        return SchemeEditor()


if __name__ == '__main__':
    SchemeApp().run()

scheme.kv

#:kivy 1.9.1

<Dot@Ellipse>:
    size: 10, 10
    color: 10, 0, 0

<SchemeEditor>:
    canvas:
        Dot:
            id: 1
            pos: root.width / 2, (root.width / 3) * 2
            size: 10, 10

        Dot:
            id: 2
            pos: root.width / 3, root.height / 3

        Dot:
            id: 3
            pos: (root.width / 3) * 2, root.height / 3

screenshot screenshot


Solution

  • Ellipse is not a Widget, or even an EventDispatcher. I'm surprised that dynamically classing it works at all (this seems like a bug, we should be able to detect that situation and refuse to try), but whatever is actually going on probably comes down to the Ellipse properties not actually being Kivy properties that will work correctly with the kv language.