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.
Example of UI and classic Scene render loop?
-
I am working on a project to port a discrete event simulation program running under Tkinter to run on Pythonista. I have the actual animation working with the classic render loop. But now I want to port the user interface elements, like buttons and sliders as well. Of course, UI is the best tool for that. But I still can't work out to use Scene and UI in one program. Any help (preferably as an example program) is very welcome.
-
Split the screen into two Views... the larger can be a SceneView and the smaller being a normal ui.View.
-
Can the UI elements be on the Scene view?
Any simple sample code? -
import scene, ui class ChristmasScene(scene.Scene): def setup(self): scene.SpriteNode('emj:Christmas_Tree', anchor_point=(0, 0), parent=self) view = scene.SceneView() view.scene = ChristmasScene() view.add_subview(ui.Button(title='Oh, Christmas Tree', center=view.center)) view.present()
-
The other key, perhaps, is that your button actions need to change states that then get rendered during update-- since these are called outside of the render loop, you cannot use thm to draw to the scene. But, i believe you can add Actions, Nodes, etc.
-
Simple ui elements like buttons/sliders can be directly implemented in scene. Look at the following discussion to see how buttons could be implemented.
https://forum.omz-software.com/topic/3485/scene-module-touch-controls
-
See also the discussion.
https://forum.omz-software.com/topic/3203/graphing-ui-question/2Buttons are used for selecting a shape in a scene. In addition you can adjust fill color, stroke color, position, size etc. using sliders.
https://gist.github.com/balachandrana/255a25f19fffe8ec4f384c1bcdad9792