Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Image from scene
-
Ok, turns out exact same post @ccc pointed to.
-
Ok, got it working. Turns out with a scene view, draw() is not automatically called in the main view every time it changes. I can't subclass a scene view, so automatic snapshots every time it updates won't work. Adding
while 1: view.take_snapshot().show()
leads to a crash pretty quickly, I'm assuming from large memory consumption. I was, however, able to capture this snapshot successfully:
If I want to compile a recording of the whole animation, I guess I'll use PIL to draw frames, as I have in previous animations. -
@Webmaster4o , I am not sure what you have done in the past. But rather than save them in a list, could you just write a method to save them to disk. If it's not fast enough realtime, maybe write to disk when your list has 60 or whatever items in it. Then flush it.
If you implemented an approach like that, maybe it would be better to create a list of a fixed length rather than calling append n the list everytime. I am not sure, but every cycle is going to count I guess. -
show() shows it in the console. IIRC that method returns a ui.Image... check the docs, there is a way to save, or else convert to a PIL image and save.
-
I know, what save does, and I know how to convert it to PIL. That code was just simple code for me to demonstrate that the snapshots were being captured. If you're wondering, you can convert to PIL like so:
from io import BytesIO from PIL import Image i = view.take_snapshot() pil_image = Image.open(BytesIO(i.to_png()))
-
I think it's sort of strange that
SceneView
doesn't inherit from ui.View* and can't be subclassed. Recently we've been able to add custom attributes to all ui.View children like buttons, but notSceneView
s. Would it be easy to change SceneView to fit into UI better? How is it recognized as something that can be added as a subview if it doesn't inherit?*I'm assuming it doesn't inherit, I think
scene
is missing from the Standard Library folder. -
SceneView
does inherit fromui.View
:>>> issubclass(scene.SceneView, ui.View) True
Adding custom attributes should also be possible; this was broken in one of the previous builds though.
-
Why can't I subclass it, then?
class myclass(scene.SceneView): def myfunc(self): pass
TypeError: Error when calling the metaclass bases type '_scene.SceneView' is not an acceptable base type
-
You can't subclass
ui.Button
either. Why would you want to do that? -
Oh. So I add attributes like
SceneView().arbitrary_attribute = 5