Closed egakupi closed 4 years ago
Yeah - we need to do that on a regular basis in the widgets sub-package. If you look at the contact list example, you'll see that it uses a separate data model class to do that (otherwise you end up with all sorts of problems when the screen resizes).
Thanks for the quick response. I checked example with contact list. Class for sending string is not what I wanted, but have to.
Also I was reading documentation, but I didn't find how I should to reset a scene and to draw all layouts on it after each raising this scene?
The model is up to you. You just need to create your own version of the Scene class (or indeed Effects) that is aware of the model object that you want to pass in (like Frames handle the model parameter). A more detailed explanation of the logic is available here: https://asciimatics.readthedocs.io/en/stable/widgets.html#model-view-design
Not sure what you're asking in the second part... A Layout is part of a Frame, which is just one Effect in a Scene. To display all the Effects in a Scene, you just need to transition to it. This is done by raising a NextScene exception - as covered here: https://asciimatics.readthedocs.io/en/stable/widgets.html#exceptions. Under the covers asciimatics will exit()
the current scene, reset()
the new one and clear()
the Screen (if requested by the new Scene).
Maybe I did not clearly ask it. For example, I have 3 scenes: main-sc0-sc1. In main I raise sc0, in sc1 – sc1, after it returns the main scene. After this road if I raise sc0 in main, sc0 will be in the same condition it was before. At sc0 I check available devices and I want re-do every time. But sc0 shows devices which was find before. I need the thing like reset scene or something like that. Thanks
Erm... But that's what already happens. When you move to the new Scene, asciimatics will call Scene.reset()
which will call reset()
on each Effect in the Scene. If you have some existing data that isn't being correctly cleaned up, it is because you need extra logic in the reset for your Scene or associated Effects.
The contact list sample code achieves this by updating the reset methods as needed. For example, look at https://github.com/peterbrittain/asciimatics/blob/master/samples/contact_list.py#L157-L160
Thank you very much for your patience and time. Have a good day!
No problems. I think the fact that you needed to ask these questions means that the docs aren't quite sufficient yet. I'll have a think about what needs adding and update them accordingly.
In the documentation you say:
Note that you don’t have to be this heavy-weight with the data storage; a simple class to wrap a list of dictionaries would also suffice
I really think actually showing a quick example of this would be very valuable for a lot of users.
Ok. Given further questions on the topic, I agree. Got any particular demo in mind?
I am trying to make a simple example that has 2 scenes. One has a ListBox, the other has a scene that just displays the selection. I think using python's shelve module is a good simple use case.
Hi,
Is it possible to transfer information between two scenes? What is the best practice for it? I have some scenes and I need to raise next scene with data from previous scene.
Thanks for your time, Dmitriy