I just realized that there is something mysterious (at least for me) in how you can add vertex instructions to Kivy using the with Python statement. For example, the with method is used like this:
... some code class MyWidget(Widget) ... some code def some_method (self): with self.canvas: Rectangle(pos=self.pos, size=self.size)
At the beginning, I thought it was just a Python statement, which I used sometimes. But suddenly I understand that this is not so. Usually it looks more (an example is taken from here ):
with open('output.txt', 'w') as f: f.write('Hi there!')
After the instance, there is usually as and something like the alias of the object. In the Kivy example, we do not define an alias, which is still in order. But the part that puzzles me is that the Rectangle command is still related to self.canvas. After reading the with statement, I am pretty sure that the Kivy code should be written as follows:
class MyWidget(Widget) ... some code def some_method (self): with self.canvas as c: c.add (Rectangle(pos=self.pos, size=self.size))
I assume that inside the add method is the one that is being called. It is assumed that we can simply add rectangles using self.add (Rectangle(pos=self.pos, size=self.size))
Am I missing something in the with Python statement? or is it somehow implementing Qiwi?
source share