PathPicker UI element

This is an UI element that allows the app’s user to navigate the local filesystem and pick files or directories.

Picking a file:

from ui import PathPicker
...
# If initial_path is a directory, PathPicker will start in that directory
# If initial_path is a file, PathPicker will start in its base directory and move to that file
path = PathPicker(initial_path, i, o, name="My app's PathPicker for picking a file").activate()
if path: # User might exit PathPicker at any time and it will return None
    purge_file_from_existence(path) # Do something with that file

Picking a directory, i.e. to read files from or to store files in:

from ui import PathPicker
...
path = PathPicker(initial_path, i, o, dirs_only=True, name="My app's PathPicker for picking a directory").activate()
if path:
    purge_dir_from_existence(path)
class ui.PathPicker(path, i, o, callback=None, name=None, file=None, display_hidden=False, dirs_only=False, append_current_dir=True, current_dot=False, prev_dot=True, scrolling=True, **kwargs)[source]

Bases: ui.menu.Menu

__init__(path, i, o, callback=None, name=None, file=None, display_hidden=False, dirs_only=False, append_current_dir=True, current_dot=False, prev_dot=True, scrolling=True, **kwargs)[source]

Initialises the PathPicker object.

Args:

  • path: a path to start from. If path to a file is passed, will start from that file (unless overridden with file keyword argument).
  • i, o: input&output device objects.

Kwargs:

  • callback: if set, PathPicker will call the callback with path as first argument upon selecting path, instead of exiting the activate()
  • file: if set, PathPicker will locate the file in the path passed and move its pointer to that file (provided it is found).
  • dirs_only: if True, PathPicker will only show directories
  • append_current_dir: if False, PathPicker won’t add “Dir: %/current/dir%” first entry when dirs_only is enabled
  • current_dot: if True, PathPicker will show ‘.’ path
  • prev_dot: if True, PathPicker will show ‘..’ path
  • display_hidden: if True, PathPicker will display hidden files
activate()

A method which is called when the UI element needs to start operating. Is blocking, sets up input&output devices, refreshes the UI element, then calls the idle_loop method while the UI element is active. self.in_foreground is True, while callbacks are executed from the input device thread.

deactivate()

Deactivates the UI element, exiting it.