feat: added last opened folders list
This commit is contained in:
parent
85c89d5343
commit
07fd885448
49
main.py
49
main.py
@ -79,6 +79,9 @@ def main(page):
|
||||
output_text_container = ft.Ref[ft.Container]()
|
||||
output_text_col = ft.Ref[ft.Column]()
|
||||
|
||||
# last opened folders
|
||||
|
||||
|
||||
def transcribe(fileOrBytes: str | bytes):
|
||||
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
|
||||
else:
|
||||
path = e
|
||||
if path:
|
||||
print(f"path is {path}")
|
||||
try:
|
||||
@ -268,9 +274,20 @@ def main(page):
|
||||
)
|
||||
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()
|
||||
except e:
|
||||
print("didn't work aaa") # TODO: fix
|
||||
except Exception as e:
|
||||
print(f"An error occurred when building the file tree: {str(e)}")
|
||||
|
||||
|
||||
def mode_select():
|
||||
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'
|
||||
|
||||
# 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(
|
||||
ft.ResponsiveRow([
|
||||
ft.Container(
|
||||
ft.Column([
|
||||
ft.Row([
|
||||
ft.ElevatedButton("Add Folder", on_click=lambda _: file_picker.get_directory_path()),
|
||||
ft.PopupMenuButton(
|
||||
items=last_opened,
|
||||
),
|
||||
ft.Container(expand=True),
|
||||
ft.IconButton(ft.icons.RECORD_VOICE_OVER, ref=record_button,
|
||||
on_click=lambda _: toggle_recording()),
|
||||
|
Loading…
Reference in New Issue
Block a user