feat: added last opened folders list

This commit is contained in:
Yandrik 2023-12-19 01:24:58 +01:00
parent 85c89d5343
commit 07fd885448

49
main.py
View File

@ -79,6 +79,9 @@ def main(page):
output_text_container = ft.Ref[ft.Container]() output_text_container = ft.Ref[ft.Container]()
output_text_col = ft.Ref[ft.Column]() output_text_col = ft.Ref[ft.Column]()
# last opened folders
def transcribe(fileOrBytes: str | bytes): def transcribe(fileOrBytes: str | bytes):
print(f"DEBUG: trying to transcribe audio {fileOrBytes if isinstance(fileOrBytes, str) else f'with len {len(fileOrBytes)}'}") print(f"DEBUG: trying to transcribe audio {fileOrBytes if isinstance(fileOrBytes, str) else f'with len {len(fileOrBytes)}'}")
@ -253,8 +256,11 @@ def main(page):
] ]
) )
def on_dialog_result(e: ft.FilePickerResultEvent): def on_dialog_result(e: ft.FilePickerResultEvent | str):
if isinstance(e, ft.FilePickerResultEvent):
path = e.path path = e.path
else:
path = e
if path: if path:
print(f"path is {path}") print(f"path is {path}")
try: try:
@ -268,9 +274,20 @@ def main(page):
) )
file_tree_empty_text.current.visible = False file_tree_empty_text.current.visible = False
# add to last opened folders
last_opened_folders = page.client_storage.get('last_opened_folders') if page.client_storage.contains_key(
'last_opened_folders') else []
if path not in last_opened_folders:
last_opened_folders.append(path)
last_opened_folders = last_opened_folders[-10:]
page.client_storage.set('last_opened_folders', last_opened_folders)
page.update() page.update()
except e: except Exception as e:
print("didn't work aaa") # TODO: fix print(f"An error occurred when building the file tree: {str(e)}")
def mode_select(): def mode_select():
global transcribe_ready global transcribe_ready
@ -504,12 +521,38 @@ def main(page):
mode = page.client_storage.get('selected_mode') if page.client_storage.contains_key('selected_mode') else 'local' mode = page.client_storage.get('selected_mode') if page.client_storage.contains_key('selected_mode') else 'local'
# last opened folders
# build controls list
last_opened_folders = page.client_storage.get('last_opened_folders') if page.client_storage.contains_key(
'last_opened_folders') else []
if not (isinstance(last_opened_folders, list) and all(isinstance(item, str) for item in last_opened_folders)):
last_opened_folders = []
# TODO: rebuild when last_opened_folders changes
last_opened = [
ft.PopupMenuItem(
on_click=lambda _, folder_name=folder_name: on_dialog_result( folder_name ),
content=ft.Row([
ft.Icon(ft.icons.FOLDER, color=ft.colors.BLUE),
ft.Text(folder_name, size=14, weight=ft.FontWeight.BOLD),
])
)
for folder_name in last_opened_folders
]
page.add( page.add(
ft.ResponsiveRow([ ft.ResponsiveRow([
ft.Container( ft.Container(
ft.Column([ ft.Column([
ft.Row([ ft.Row([
ft.ElevatedButton("Add Folder", on_click=lambda _: file_picker.get_directory_path()), ft.ElevatedButton("Add Folder", on_click=lambda _: file_picker.get_directory_path()),
ft.PopupMenuButton(
items=last_opened,
),
ft.Container(expand=True), ft.Container(expand=True),
ft.IconButton(ft.icons.RECORD_VOICE_OVER, ref=record_button, ft.IconButton(ft.icons.RECORD_VOICE_OVER, ref=record_button,
on_click=lambda _: toggle_recording()), on_click=lambda _: toggle_recording()),