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
-
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
TabbedContent
andTabPane
widgets. 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
BaseForm
should 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_person
with columns likeid
,name
,birthday
,address
,phone
,email
and so on. Later on we have a form likeBaseForm
should be responsible for:form.addWidget(col_name='name', widget=Input(), type='text', label='Name')
which ends up in an attribute
form.name
pointing to theInput
widget. Of course there are other widgets allowed likeSelect
,RadioSet
,TextArea
.Input
widgets of typedatetime
,date
,time
get suitable validators. These validators are made from textualValidator
but 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 pythondateparser
which makes it possible to enter even "today"...)form.lbl_name
points to. If given this label is made from the optional parameterlabel
in theaddWidget
, which can be a string or even a textualLabel
widget.type
for each widget. These types aretext
,int
,bool
,float
,decimal
,datetime
,date
,time
.type
of the widget.form.setValues(dict_of_values)
ordict_of_values = form.getValues()
.Select
orRadioSet
from 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
buildForms
collect all the work to construct forms and widgets, including the form hierarchy.buildForms
has 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 callbuildForms
could be in an event handleron_load
, but I don't see any benefit.compose
I 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