FileDialog
- class pygamelib.gfx.ui.FileDialog(path: Path = None, width: int = 20, height: int = 10, title: str = 'File dialog', show_hidden_files: bool = False, filter: str = '*', config: UiConfig = None)
Bases:
Dialog
The FileDialog is a file selection dialog: it allow the user to select a file on disk in a relatively easy way. File can then be use for any purpose by the program, like for “save as” or “open” features.
The show() method returns the path selected by the user.
Key mapping:
ESC: set the path to None and exit from the
show()
method.ENTER: Exit from the
show()
method. Returns the currently selected path.BACKSPACE / DELETE: delete a character (both keys have the same result).
UP / DOWN: Navigate between the files.
LEFT / RIGHT: Navigate between the directories.
All other keys input characters in the input field.
In all cases, when the dialog is closed, a path is returned. It can be a file name entered by the user or an existing file. The returned value can also be None if the user pressed ESC. There is no guarantee that the returned path is correct. Please, check it before doing anything with it.
Like all dialogs, it is automatically destroyed on exit of the
show()
method. It is also deleted from the screen buffer.- __init__(path: Path = None, width: int = 20, height: int = 10, title: str = 'File dialog', show_hidden_files: bool = False, filter: str = '*', config: UiConfig = None) None
- Parameters:
path (
pathlib.Path
) – The path to start in. This path is made absolute by the constructor.width (int) – The width of the file dialog widget (in number of screen cells).
height (int) – The height of the file dialog widget (in number of screen cells).
title (str) – The title of the dialog (written in the upper border).
show_hidden_files (bool) – Does the file dialog needs to show the hidden files or not.
filter (str) – A string that will be used to filter the files shown to the user. For example “*.spr”.
config (
UiConfig
) – The configuration object.
Example:
file_dialog = FileDialog( Path("."), 30, 10, "Open file", False, conf) screen.place(file_dialog, 10, 10) file = file_dialog.show()
Methods
__init__
([path, width, height, title, ...])- param path:
The path to start in. This path is made absolute by the
render_to_buffer
(buffer, row, column, ...)Render the object from the display buffer to the frame buffer.
show
()Show the dialog and execute the event loop.
Attributes
Get and set the config object (
UiConfig
).Get/set the current file filter.
Get/set the current path.
Get/set the property, if True the file dialog is going to show hidden files, and , if False, it won't.
Facility to store and retrieve the user input.
- property filter
Get/set the current file filter.
- Returns:
The dialog’s current filter.
- Return type:
str
- property path
Get/set the current path.
- Returns:
The dialog’s current path.
- Return type:
pathlib.Path
- render_to_buffer(buffer, row: int, column: int, buffer_height: int, buffer_width: int) None
Render the object from the display buffer to the frame buffer.
This method is automatically called by
pygamelib.engine.Screen.render()
.- Parameters:
buffer (numpy.array) – A screen buffer to render the item into.
row (int) – The row to render in.
column (int) – The column to render in.
height (int) – The total height of the display buffer.
width (int) – The total width of the display buffer.
- show() Path
Show the dialog and execute the event loop. Until this method returns, all keyboards event are processed by the local event loop. This is also true if called from the main event loop.
This event loop returns a
pathlib.Path
object or None if the user pressed the ESC key. The path can point to an existing file or not.Example:
fields = multi_input.show()
Get/set the property, if True the file dialog is going to show hidden files, and , if False, it won’t.
- Returns:
The dialog’s current show_hidden_files value.
- Return type:
bool
- property user_input
Facility to store and retrieve the user input.