-
It seems to be tricky (for me) to access and update values of widgets from different parts of an app. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 6 replies
-
There's two answers to your question. The first is the pragmatic, "works right now" answer. The sibling relationship between widgets in a layout doesn't matter. All that matters is that you can get a reference to another widget. So - you create the text input as You can slightly decouple things by using the widget registry - instead of assigning the Your comments about "shared data source" hint in the direction of the longer term solution - but that solution doesn't currently exist. Toga does contain a ValueSource, which is the "single value" equivalent of TreeSource/ListSource - but, at present, you can't use a ValueSource for anything. Ideally, you would be able to use a ValueSource as the data behind a TextInput - so then, whenever the ValueSource is changed, the TextInput would change, and vice versa. However, that won't change the underlying issue that made the "pragmatic" solution possible. You need a reference to something to represent the data- and that will mean either assigning something to the app, or using some other "registry" (be that the app/window widget registry, or something else). If you want an example of this - Toga Tutorial 1 (The Fahrenheit to Celsius converter) in the examples folder of the Toga folder demonstrates this - you press a button, and the value of one text input is used to update another text input. |
Beta Was this translation helpful? Give feedback.
-
Thanks again for your insight. Very Helpful. But a few more questions. The programmatic change to a text value would seem to have a solution. I will test the proposed methods to identify the widgets. My aim is to have a settings summary in a table with a data source then separate Input widgets that can update row items in the table source. (and trigger a display update unless that would be auto magical) Cheers |
Beta Was this translation helpful? Give feedback.
-
I am getting my head around this.
Now looking at ListSource updates so making progress. |
Beta Was this translation helpful? Give feedback.
-
Continuing my Toga education. https://github.com/beeware/toga/blob/main/examples/table_source/table_source/app.py There is a table definition:
then later
Some questions.
Thanks - I am still learning!! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply and clarification. I only ask to gain understanding. In the example the table data is initiated with static data from outwith the class. Could this also be achieved when the source object is initialised. e.g. Read from a file or the REST API you suggest? In this case how would the table data initialisation occur. The object can notify any widget listening however in the movie example there are no listeners so the notifications just 'disappear into the wind'. Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. To answer your last question. This is the small step I am working on. The application has 'settings' that can change from time to time but should persist across each use. Ideal: A table to show 'settings' and 'values' these are used to customise the application and may have say a datatafile value, a database query to run on a selected database. The values can persist by being saved and loaded to and from an INI file. ( An INI text file so that if necessary values can be changed separately from the application.) { other persistence methods may be available.} I have been looking at: My previous questions arose as I tried to use a Custom Source solution using the Movie example as a starting point. Yes - this is a jump from playing with Python to building with Python!! |
Beta Was this translation helpful? Give feedback.
-
Thanks - lets say exploring the boundaries or the options. I suppose it depends on the definition of more complex in this context. The database processing comes in part two .... but that is a read only process running pre defined queries. Cheers |
Beta Was this translation helpful? Give feedback.
-
I have worked on the table widget reading data in from a file and also saving data to a file but found the table not updating the display.
I think a lot of my earlier challenges were caused by my GUI design with a table in a box in an opcontainer not acting as expected. For now I will see if I can redesign the GUI to avoid the table in opcontainer design. Should we close this and I can come back later if necessary as I have strayed away from the Discussion Title? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the pointer I now see how to use
I have opened an issue regarding the table in container bug |
Beta Was this translation helpful? Give feedback.
-
Thanks for clarifying that. I think I ended up using the 'wrong' approach because the changes I was trying to make were not reflected in the display. Lesson leaned. |
Beta Was this translation helpful? Give feedback.
Thanks for the pointer I now see how to use
__setattr__
I have opened an issue regarding the table in container bug
#3046
Thanks again
Ted