FileHandler
- class lib.gui.utils.file_handler.FileHandler(handle_type: Literal['open', 'save', 'filename', 'filename_multi', 'save_filename', 'context', 'dir'], file_type: Literal['default', 'alignments', 'config_project', 'config_task', 'config_all', 'csv', 'image', 'ini', 'json', 'state', 'log', 'video'] | None, title: str | None = None, initial_folder: str | None = None, initial_file: str | None = None, command: str | None = None, action: str | None = None, variable: str | None = None, parent: Frame | Frame | None = None)
Bases:
objectHandles all GUI File Dialog actions and tasks.
- Parameters:
handle_type (['open', 'save', 'filename', 'filename_multi', 'save_filename', 'context', 'dir']) – The type of file dialog to return. open and save will perform the open and save actions and return the file. filename returns the filename from an open dialog. filename_multi allows for multi-selection of files and returns a list of files selected. save_filename returns the filename from a save as dialog. context is a context sensitive parameter that returns a certain dialog based on the current options. dir asks for a folder location.
file_type ([‘default’, ‘alignments’, ‘config_project’, ‘config_task’, ‘config_all’, ‘csv’, ‘image’, ‘ini’, ‘state’, ‘log’, ‘video’] or
None) – The type of file that this dialog is for. default allows selection of any files. Other options limit the file type selectiontitle (str, optional) – The title to display on the file dialog. If None then the default title will be used. Default:
Noneinitial_folder (str, optional) – The folder to initially open with the file dialog. If None then tkinter will decide. Default:
Noneinitial_file (str, optional) – The filename to set with the file dialog. If None then tkinter no initial filename is. specified. Default:
Nonecommand (str, optional) – Required for context handling file dialog, otherwise unused. Default:
Noneaction (str, optional) – Required for context handling file dialog, otherwise unused. Default:
Nonevariable (str, optional) – Required for context handling file dialog, otherwise unused. The variable to associate with this file dialog. Default:
Noneparent (
tkinter.Frame|tkinter.ttk.Frame, optional) – The parent that is launching the file dialog.Nonesets this to root. Default:None
- return_file
The return value from the file dialog
- Type:
str or object
Example
>>> handler = FileHandler('filename', 'video', title='Select a video...') >>> video_file = handler.return_file >>> print(video_file) '/path/to/selected/video.mp4'