When do you use a custom data source? #3759
-
|
I just finished reading https://toga.readthedocs.io/en/stable/topics/data-sources.html . It has the following paragraph:
OK, but then widgets that use a
That seems to be in conflict with each other if you're encouraged to leave off methods you don't need but which the widgets say are needed consistently across the widgets based on using the built-in data source classes as protocols. I'm sure I'm misunderstanding something here (I haven't done much GUI programming and I'm still reading the Toga docs). Maybe custom data sources are meant to be for listening to the built-in ones provided as per:
? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The widget using a source only views the information that the source contains. If a row is added to the source, the widget is notified that a row has been added so that it can be displayed (if necessary); but the widget won't ever call Some GUI action (including an action on the tree) might lead to new data being created. In that case, the handler for that GUI action might call Strictly, the only thing that a Source should need to implement is the However, the fact that I can't point you at a clear documentation page (or even Protocol specification) for this, or to a clear definition of the "listener" methods that might be invoked on Source, indicates there's a gap in our documentation. I'll open a ticket to highlight the need to clarify this topic.
The The source for the table on the right doesn't actually store any data - it's implemented as a listener on the first table's source. When a row is added to the first table's source, the second table's source is notified, and the second table's source makes a decision as to whether the new entry should be part of the second table source's data. If it is, it passes on the notification to the second table; if it isn't, the second table does nothing. This is, admittedly, an artificial example. The idea it's trying to highlight is the separation between a source of data, and a widget displaying that data. The widget should be thought of a view over some collection of data; but that "view" doesn't necessarily mean that it's a concrete store of a list/tree - it could be an abstraction over another source of data (including one that isn't even stored in the app itself - like a filesystem, or a network service API) |
Beta Was this translation helpful? Give feedback.
The widget using a source only views the information that the source contains. If a row is added to the source, the widget is notified that a row has been added so that it can be displayed (if necessary); but the widget won't ever call
insert()on a source directly, because the Tree widget does…