Organize widgets in forms, design the textual code #4564
UlrichGoebel
started this conversation in
General
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.
-
Hi,
I intend to build UIs for existing PostgreSQL databases with dozens of tables, each with 5 to 30 columns, some 1-n, n-1 and n-n relations.
The Concept
Roughly speaking each database table will get his own form, which collect the widgets needed. These forms will be displayed in nested
TabbedContentandTabPanewidgets. So the user can easyly navigate between the forms/tables.To handle relations, each form can have subforms. So let's say a form handles data from a person, a subform could handle data about roles of the person. The subform concept should work recursively, so even subforms can have subforms. (In practice, this should not be overdone.)
The Main Classes
For that I intend to build a
and two others
The
BaseFormshould do the main work, the two others differ more or less just in the attributes related to the form hierachy.We keep in mind an example, let's say a database table
tbl_personwith columns likeid,name,birthday,address,phone,emailand so on. Later on we have a form likeBaseFormshould be responsible for:form.addWidget(col_name='name', widget=Input(), type='text', label='Name')which ends up in an attribute
form.namepointing to theInputwidget. Of course there are other widgets allowed likeSelect,RadioSet,TextArea.Inputwidgets of typedatetime,date,timeget suitable validators. These validators are made from textualValidatorbut do much more: they try to interprete the user input and update the widget value in case of success. (I relized such validators using the pythondateparserwhich makes it possible to enter even "today"...)form.lbl_namepoints to. If given this label is made from the optional parameterlabelin theaddWidget, which can be a string or even a textualLabelwidget.typefor each widget. These types aretext,int,bool,float,decimal,datetime,date,time.typeof the widget.form.setValues(dict_of_values)ordict_of_values = form.getValues().SelectorRadioSetfrom a model which connect the app/form to a database table.How the Textual App could look like
A textual app then could look like:
Some remarks
buildFormscollect all the work to construct forms and widgets, including the form hierarchy.buildFormshas to be called after the app has initilized itself, therefore it is called at the very beginning ofcompose. (Thanks to daveps hint here.) An alternative place to callbuildFormscould be in an event handleron_load, but I don't see any benefit.composeI try to reduce the work on the UI structure.How going on
If anyone has any recommendations for me, I would be delighted. Otherwise I'm also happy to discuss the concept.
If anyone is interested in collaborating on the project, I am interested too. (The main problem could come from my poor english and the fact, that my code until now is written with mostly german identifiers and documentation.)
Best regards
Ulrich
Beta Was this translation helpful? Give feedback.
All reactions