Expressive Stateful list api (putting ideas down for later discussion) #22
TG-Techie
started this conversation in
API/std-lib Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Idea
Add a way to have TG-Gui make a list of widgets
for eachitem in some source data in a list "automagically".The idea is that as some StatefulList object is modified some VList container will be informed and update a visual presentation of the represented data accordingly.
Timeline
Obviously, this is quite a way out as the current GUI is only suited to static layouts where the dynamic bits are pre-define. However once scrolling and some cross-platform functionality has been added this kind of feature would be fantastic!
General Proposed Syntax
First off, this specific code would be syntactic sugar for making a
VListthat is passed some object and links it to thecontactslist. Basically, it would be misusing the python generator protocol to make this code more expressive. A de-sugared version may look something like this:Where
StatefulListExpansion(or something like it) is a go-between that interprets changes incontactsand does things to theVSplit.Specific Proposed Syntax
I think there are two good options for the sytac:
IMO the first option makes more sense, though it would require that
ContactPreviewsubclasses some specific base class (let's sayModleView) that understands how to transform a model into a specific widget for it. However, I think this a requirement as theVListorStatefulListExpansionwill need access to either the model's ids and/or theModleView's id so it can figure out what to remove from the visual list of widgets.Possible implementation
In the below syntax,
ModleViewwould have some mechanism (probably in its__new__constructor) that would be able to take a partially initedStatefulListExpansionand tell it what class it should make.here are the possible steps that would happen in chronological order:
body = Vsplit(ContactPreview(contact) for contact in contacts)line runscontacts.__iter__()contacts.__iter__()returns a paritally intedStatefulListExpansion(called "the expansion") in a tuple ,(StatefulListExpansion(source=contacts, type=TBDFLAG),)VSplit(called "body" ) is constructed and passed the newly created generatora. body sees it was passed a generator and fetches the first item from the generator and keeps it
b. on generator fetch, the expansion is passed to the
ContactPreview.__new__method witch finishes initing the expansion by passing it theContactPreviewclass,c. the generator returns the execute
ContactPreview(contact)expression on fetch endd. body verifies the generator contained only that item
e. body checks and then links with the expansion via some protocol
later
The Expansion protocol will need to fleshed out but that is a separate discussion. This is just documenting the idea of how to make the VList over a stateful list clear to write and read for TG-Gui users
Some "Full" Pseudo Code
As an example here is what the ContactPreview and ContactModel might look like:
Beta Was this translation helpful? Give feedback.
All reactions