fixed sliders, added switches

This commit is contained in:
aedh carrick 2022-11-24 14:44:54 -06:00
parent 20a7b6387a
commit c55773c127
3 changed files with 92 additions and 74 deletions

View File

@ -35,7 +35,7 @@
# -value
# -min
# -max
# -increment
# -step
# textinput
# -value
#
@ -58,55 +58,55 @@ webui_page:
value: !!int '1'
min: !!int '0'
max: !!int '10'
increment: !!int '1'
step: !!float '1.0'
default_border_radius:
display: slider
value: !!int '0'
min: !!int '1'
max: !!int '10'
increment: !!int '1'
step: !!float '1.0'
default_container_height:
display: slider
value: !!int '200'
min: !!int '20'
max: !!int '600'
increment: !!int '20'
step: !!float '20.0'
default_container_width:
display: slider
value: !!int '200'
min: !!int '20'
max: !!int '600'
increment: !!int '20'
step: !!float '20.0'
default_margin:
display: slider
value: !!int '1'
min: !!int '1'
max: !!int '10'
increment: !!int '1'
step: !!float '1.0'
default_opacity:
display: slider
value: !!float '1.0'
min: !!float '0.1'
min: !!float '0.0'
max: !!float '1.0'
increment: !!float '0.05'
step: !!float '0.1'
default_padding:
display: slider
value: !!int '0'
min: !!int '0'
max: !!int '10'
increment: !!int '1'
step: !!float '1.0'
default_scale:
display: slider
value: !!float '1'
min: !!float '0.5'
max: !!float '2.0'
increment: !!float '0.1'
step: !!float '0.1'
default_text_size:
display: slider
value: !!int '20'
min: !!int '10'
max: !!int '32'
increment: !!int '2'
step: !!float '2.0'
general_page:
huggingface_token:

View File

@ -90,21 +90,21 @@ def main(page: ft.Page):
page.update()
def update_settings_window():
# settings_window.content.content.tabs = get_settings_window_tabs()
settings_window.content.content.tabs = get_settings_window_tabs()
page.update()
def update_settings_window_tab(section):
try:
pprint(section)
for i, tab in enumerate(settings_window.content.content.tabs):
pprint(tab.text)
pprint(settings_window.content.content.tabs[i].text)
if section.startswith(tab.text):
settings_window.content.content.tabs[i] = get_settings_window_tab_page(section)
settings_window.content.content.tabs[i].content = get_settings_window_tab_page(section)
return
except:
print(f'"{section}" not found in tabs.')
def apply_settings(e):
update_settings_window()
def save_settings(e):
save_settings_to_config()
update_settings_window()
@ -115,24 +115,62 @@ def main(page: ft.Page):
def settings_window_tab_setting_changed(e):
settings = page.session.get('settings')
settings[e.control.data][e.control.label] = e.control.value
update_settings_window() #_tab(e.control.data)
settings[e.control.data][e.control.label]['value'] = e.control.value
update_settings_window_tab(e.control.data)
page.update()
def settings_window_tab_slider_changed(e):
settings = page.session.get('settings')
settings[e.control.data[0]][e.control.data[1]] = e.control.value
update_settings_window() #_tab(e.control.data[0])
parent = e.control.data
settings[parent.data[0]][parent.data[1]]['value'] = e.control.value
parent.controls[0].value = e.control.value
parent.controls[1].value = e.control.value
update_settings_window_tab(parent.data[0])
page.update()
def get_settings_window_tab_page_setting_slider(settings,section,setting):
setting_slider = []
label = ft.Text(
value = setting,
text_align = 'center',
)
row = ft.Row(
width = page.width * 0.25,
data = [section, setting],
controls = [],
)
slider = ft.Slider(
value = settings[setting]['value'],
label = "{value}",
min = settings[setting]['min'],
max = settings[setting]['max'],
divisions = int((settings[setting]['max'] - settings[setting]['min']) / settings[setting]['step']),
on_change = settings_window_tab_slider_changed,
data = row,
expand = 4,
)
value = ft.TextField(
value = settings[setting]['value'],
on_submit = settings_window_tab_slider_changed,
data = row,
content_padding = 10,
expand = 1,
)
row.controls.extend([slider,value])
setting_slider.extend([label,row])
return setting_slider
def get_settings_window_tab_settings(section):
settings = page.session.get('settings')
settings = settings[section]
section_settings = [ft.Divider(height=10, color='gray')]
for setting in settings:
try:
if 'value' not in settings[setting]:
continue
except:
pprint(setting)
pprint(settings)
display = None
display_type = settings[setting]['display']
if display_type == 'dropdown':
@ -151,38 +189,6 @@ def main(page: ft.Page):
content_padding = 10,
width = page.width * 0.25,
)
elif display_type == 'slider':
display = ft.Column(
controls = [
ft.Text(
value = setting,
text_align = 'center',
),
ft.Row(
width = page.width * 0.25,
controls = [
ft.Slider(
value = settings[setting]['value'],
label = "{value}",
min = settings[setting]['min'],
max = settings[setting]['max'],
#divisions = settings[setting]['increment'],
# ft.Slider doesn't accept float for increments.
on_change = settings_window_tab_slider_changed,
data = [section, setting],
expand = 4,
),
ft.TextField(
value = settings[setting]['value'],
on_submit = settings_window_tab_slider_changed,
data = [section, setting],
content_padding = 10,
expand = 1,
),
],
),
],
)
elif display_type == 'textinput':
display = ft.TextField(
label = setting,
@ -192,6 +198,18 @@ def main(page: ft.Page):
content_padding = 10,
width = page.width * 0.25,
)
elif display_type == 'bool':
display = ft.Switch(
label = setting,
value = settings[setting]['value'],
on_change = settings_window_tab_setting_changed,
data = section,
width = page.width * 0.25,
)
elif display_type == 'slider':
display = ft.Column(
controls = get_settings_window_tab_page_setting_slider(settings,section,setting),
)
else:
continue
new_row = ft.Row(