-
Notifications
You must be signed in to change notification settings - Fork 0
Home
sandeep-gh edited this page Jan 26, 2021
·
8 revisions
#Under development
This repo provides a set of APIs to describe UI-template and generate UI-layout and associated code stubs.
Define a text element
text_gelem = Gelem(sg.Text, sty={"auto_size_text": 'False',
"size": (8, 4)
})
A template for two two side-by-side text elements
rowT = BlockLD([('lc_', text_gelem), ('rc_', text_gelem)])
Text for the tables
keys_values_set = [(('ak1', 'ak2', 'ak3'), ('av1', 'av2', 'av3')),
(('bk1', 'bk2', 'bk3'), ('bv1', 'bv2', 'bv3')),
(('ck1', 'ck2', 'ck3'), ('cv1', 'cv2', 'cv3')),
]
A checkbox generator
def cb_gen(tid): return BlockLI.bli_single(
[tid, Gelem(sg.Checkbox, {'text': 'tbl ' + tid})], (tid,))
Putting all together:
tli = ListNodeLI([TreeNodeLI(cb_gen(str(idx)),
BlockLI(rowT, [(k, v) for k, v in zip(
keys, values)], stacked='V', framed=True), stacked='V'
)
for idx, (keys, values) in enumerate(keys_values_set)])
The boilerplate/glue code to generate and view the layout:
lg.set_li_layout(tli)
the_layout = lg.compose_layout_li(tli)
print(the_layout)
layout = []
exit_button_row = [[
sg.Button('Exit')
]
]
layout = layout + [[the_layout]] + exit_button_row
window = sg.Window('PGAppAnalytics', layout)
while True:
event, values = window.read()
print("event pressed = ", event)
if event == 'Exit':
break
window.close()
To showcase we will create a layout that looks as follows:
The snippet below gives a flavor how the API looks-n-feels. It describes two button elements that are to be stacked horizontally and framed.
bld1 = BlockLD([
Gelem("button1", "button 1", sg.Button, sty={"auto_size_button": 'False',
"size": (8, 4)
}, ex_toggle_attrs=[('button_color', (
('white', 'green'), ('blue', 'black')))]),
Gelem("button2", "button 2", sg.Button, sty={"auto_size_button": 'False',
"size": (8, 4)
})
], stacked='H', framed=True
)
To create a layout fragment that contains two instantiation of the bld1 template:
bli1 = BlockLI(bld1, ['A', 'B'])
Lets create another similar template and an instance:
bld2 = BlockLD([
Gelem("text1", "text 1", sg.Text, sty={"auto_size_text": 'False',
"size": (8, 4)
}),
Gelem("text2", "text 2", sg.Text, sty={"auto_size_text": 'False',
"size": (8, 4)
})
], stacked='H', framed=False
)
bli2 = BlockLI(bld2, ['A', 'B'])
Now the two layouts can be composed as follows:
tnli = TreeNodeLI(bli1,
bli2, stacked='H', framed=True)