@omz, look really, I think your documentation is really good. However the examples could be better. I would say a lot of the examples are not easy for a beginner to understand. I understand it's a balancing act. I have still been having problems with ui.ImageContext. I wanted to draw to the screen but sometimes I wanted to get an image of what was being drawn to the screen. Drawing to the screen is documented as well as creating a image is documented. But I really struggled how to do both. For a seasoned Python programmer, I guess this is so trivial it's not funny. But for me it wasn't, I can't be the only one that struggles with examples given in a very small context. Yes Blah blah blah...😱
I am coming to a point....
I don't think the documentation should be changed. I think as you get better and better you appreciate the concise way it's written and layed out.
But one idea, a new chapter of examples. Better still if there was a link from the topic in the main help file. These examples could be user submitted. I know there are sources to get the info. But it can be tedious to find what you are looking for. In the long run, I am sure this would save you a lot of questions also. Simple code samples for a working table with a datasource and delegate, defining custom ui.Views. I know it's there, but it's sort of there. You need to connect quite a few dots as a beginner to get it.
Look it's just a idea or beginning of a idea. I was so frustrated I could not work out how to draw to the screen and then if I wanted to get the same image as a image and display it as an image or save it. In my infinite wisdom I was trying to conditionally create a ImageContext with in the draw method. Huge Fail. Just have to remember, what comes naturally to you and others that know Python so well does not immediately come to all of us.
My example is below. Not sure I have done it right or not. I think I have. I separated the draw cmds into a separate method. So I didn't have to do something like ui.set_needs_display to get it to render. But if what I have done is semi correct, you can see a big disconnect from the examples in the documentation to what would be considered functional.
import ui
class DrawSomething(ui.View):
rect = (0, 0, 200, 200)
def draw(self):
self.my_draw()
def my_draw(self):
with ui.GState():
ui.set_color('deeppink')
shape = ui.Path.rect(*self.rect)
shape.fill()
def image_get(self):
with ui.ImageContext(self.rect[2], self.rect[3]) as ctx:
self.my_draw()
img = ctx.get_image()
img.show()
return img
def image_save(self, path):
img = self.image_get()
with open(path, 'wb') as file:
file.write(img.to_png())
if __name__ == '__main__':
ds = DrawSomething()
ds.present('sheet')
ds.image_get()
ds.image_save('test2.png')