earwax.menus.file_menu module¶
Provides the FileMenu class.
-
class
earwax.menus.file_menu.
FileMenu
(game: Game, title: Union[str, TitleFunction], dismissible: bool = True, item_select_sound_path: Optional[pathlib.Path] = None, item_activate_sound_path: Optional[pathlib.Path] = None, position: int = -1, search_timeout: float = 0.5, search_time: float = 0.0, path: pathlib.Path = NOTHING, func: Callable[[Optional[pathlib.Path]], Optional[Generator[None, None, None]]] = <built-in function print>, root: Optional[pathlib.Path] = None, empty_label: Optional[str] = None, directory_label: Optional[str] = None, show_directories: bool = True, show_files: bool = True, up_label: str = '..')¶ Bases:
earwax.menus.menu.Menu
A menu for selecting a file.
File menus can be used as follows:
from pathlib import Path from earwax import Game, Level, FileMenu, tts from pyglet.window import key, Window w = Window(caption='Test Game') g = Game() l = Level(g) @l.action('Show file menu', symbol=key.F) def file_menu(): '''Show a file menu.''' def inner(p): tts.speak(str(p)) g.pop_level() f = FileMenu(g, 'File Menu', Path.cwd(), inner) g.push_level(f) g.push_level(l) g.run(w)
Variables: - path – The path this menu will start at.
- func – The function to run with the resulting file or directory.
- root – The root directory which this menu will be chrooted to.
- empty_label –
The label given to an entry which will allow this menu to return None as a result.
If this label is None (the default), then then no such option will be available.
- directory_label –
The label given to an entry which will allow a directory - in addition to files - to be selected.
If this argument is None (the default), then no such option will be available.
If you only want directories to be selected, then pass show_files=False to the constructor.
- show_directories – Whether or not to show directories in the list.
- show_files – Whether or not to include files in the list.
- up_label – The label given to the entry to go up in the directory tree.
-
navigate_to
(path: pathlib.Path) → Callable[[], None]¶ Navigate to a different path.
Instead of completely replacing the menu, just change the path, and re- use this instance.
-
rebuild_menu
() → None¶ Rebuild the menu.
This method will be called once after initialisation, and every time the directory is changed by the
navigate_to()
method.
-
select_item
(path: Optional[pathlib.Path]) → Callable[[], Optional[Generator[None, None, None]]]¶ Select an item.
Used as the menu handler in place of a lambda.
Parameters: path – The path that has been selected. Could be a file or a directory.