Cleaned up the look of ui.display and the modal for submitting a verse. There was an issue with the way python looks at for loops and a frontend ui, but thankfully the devs had answered a question on stack overflow. See here: https://stackoverflow.com/questions/76726671/im-populating-some-cards-using-for-loop-in-nicegui-each-has-a-label-and-a-butto. Set it to refresh as well so complete/incomplete shows the correct color as expected. Need to account for duplicates with a utility func.

This commit is contained in:
Norm Rasmussen
2024-10-05 16:39:30 -04:00
parent d36add7f35
commit c33157ec78

51
main.py
View File

@ -11,12 +11,14 @@ cur = db.cursor()
APIKEY = "Token f562cf2d890151d682065696dacdc0f86938a18e" APIKEY = "Token f562cf2d890151d682065696dacdc0f86938a18e"
HEADERS = { 'Authorization': APIKEY} HEADERS = { 'Authorization': APIKEY}
card = "card"
@ui.page('/') @ui.page('/')
def index_page() -> None: def index_page() -> None:
with theme.frame('Homepage'): with theme.frame('Homepage'):
pass with ui.dialog().props('persistent') as addverse:
pass
with ui.grid(columns=1).classes('self-center justify-items-center content-center p-2 m-2'): with ui.grid(columns=1).classes('self-center justify-items-center content-center p-2 m-2 rounded-xl'):
toggle = ui.toggle(["Hannah", "Fiona", "Liam"], clearable=True, on_change=lambda: show_person(toggle)) toggle = ui.toggle(["Hannah", "Fiona", "Liam"], clearable=True, on_change=lambda: show_person(toggle))
with ui.row().classes('absolute bottom-0 left-0 p-2 m-2'): with ui.row().classes('absolute bottom-0 left-0 p-2 m-2'):
with ui.element('q-fab').props('icon=navigation color=green'): with ui.element('q-fab').props('icon=navigation color=green'):
@ -25,18 +27,12 @@ def index_page() -> None:
with ui.row().style('justify-content: center') as showperson: with ui.row().style('justify-content: center') as showperson:
pass pass
with ui.grid(columns=1).classes('grid gap-4 place-items-stretch') as showoptions:
optionstoggle = ui.toggle(["Completed", "Pin Verse"], clearable=True)
with ui.card().style('border: orange solid 3px').classes('flex self-center justify-self-auto') as addverse:
pass
showperson.set_visibility(False) showperson.set_visibility(False)
showoptions.set_visibility(False)
addverse.set_visibility(False)
@ui.refreshable @ui.refreshable
def show_person(person): def show_person(person):
showperson.clear()
if person.value is not None: if person.value is not None:
res = cur.execute(f"select verse,verse_passage,status from tasks where person='{person.value.lower()}'") res = cur.execute(f"select verse,verse_passage,status from tasks where person='{person.value.lower()}'")
dbinfo = res.fetchall() dbinfo = res.fetchall()
@ -45,38 +41,45 @@ def index_page() -> None:
ui.notify(f"{person.value} doesn't have any verses saved under her name! Start adding some by clicking the green arrow in the bottom left.") ui.notify(f"{person.value} doesn't have any verses saved under her name! Start adding some by clicking the green arrow in the bottom left.")
else: else:
showperson.set_visibility(True) #False if showperson.visible else True) showperson.set_visibility(True) #False if showperson.visible else True)
showoptions.set_visibility(True) # showoptions.set_visibility(True)
with showperson: with showperson.classes('border-8'):
with ui.grid(columns=3): with ui.grid(columns=5).classes('rounded-md items-center border-8'):
for item in dbinfo: for item in dbinfo:
ui.chip(item[0], icon='ads_click', on_click=lambda: ui.notify(item[1])) label_verse = ui.label(text=item[0]).classes('hidden')
ui.label(item[1].title()).classes('text-wrap') label_passage = ui.label(text=item[1]).classes('hidden')
if item[2] == 0: label_status = ui.label(text=item[2]).classes('hidden')
ui.chip("Incomplete", selectable=True, icon="add", color="orange", on_selection_change=lambda: toggle_completion(item[0], person, status=1)) ui.chip(label_verse.text, icon='ads_click', on_click=lambda: ui.notify(label_passage.text))
ui.label(label_passage.text).classes('text-wrap')
if label_status.text == '0':
ui.chip("Incomplete", selectable=True, icon="add", color="orange", on_selection_change=lambda: toggle_completion(label_verse.text, person, status=1))
else: else:
ui.chip("Complete", selectable=True, icon="add", color="green", on_selection_change=lambda: toggle_completion(item[0], person, status=0)).props('dark') ui.chip("Complete", selectable=True, icon="add", color="green", on_selection_change=lambda: toggle_completion(label_verse.text, person, status=0))
ui.checkbox('Pin Verse')#.bind_visibility_from(card, 'value')
ui.checkbox('Mark as Completed')#.bind_value(item[2])
else: else:
showperson.clear() showperson.clear()
def toggle_completion(verse, person, status): def toggle_completion(verse, person, status):
ins = cur.execute(f"update tasks set status = '{status}' where person = '{person.value.lower()}' and verse = '{verse}'") ins = cur.execute(f"update tasks set status = '{status}' where person = '{person.value.lower()}' and verse = '{verse}'")
# values('{person.value.lower()}', '{result.value}', '{zpassage}', 'incomplete', 'incomplete', 'none');") print(f"update tasks set status = '{status}' where person = '{person.value.lower()}' and verse = '{verse}'")
db.commit() db.commit()
# show_person(person) show_person.refresh
show_person(person)
def add_verse(person): def add_verse(person):
if person.value is None: if person.value is None:
ui.notify("Oops! You haven't selected a person") ui.notify("Oops! You haven't selected a person")
else: else:
addverse.set_visibility(True) addverse.open()
with addverse: with addverse:
result = ui.input(label="Add Verse Here") with ui.card().classes('flex-wrap items-center'):
ui.button().props('icon=book color=grey-5').on('click', lambda: submit_verse(result, person)) result = ui.input(label="Add Verse Here")
with ui.row().classes('justify-content-center'):
ui.button().props('push glossy icon=add_circle color=indigo-5').on('click', lambda: submit_verse(result, person))
ui.button().props('push glossy icon=cancel color=orange-3').on('click', lambda: addverse.close())
def submit_verse(result, person): def submit_verse(result, person):
# addverse.set_visibility(False)
print(result)
# Verify the format of a Bible Verse # Verify the format of a Bible Verse
if not re.match(r'((^\d\s\w{1,}\s|^\w{1,}\s)(\d{1,2}:)(\d{1,2}-\d{1,2}|\d{1,2}))', result.value): if not re.match(r'((^\d\s\w{1,}\s|^\w{1,}\s)(\d{1,2}:)(\d{1,2}-\d{1,2}|\d{1,2}))', result.value):
ui.notify("Verse was input incorrectly.") ui.notify("Verse was input incorrectly.")