xdev.desktop_interaction module¶
Functions related to interacting with data via an OS Desktop GUI.
- xdev.desktop_interaction._coerce_editable_fpath(target)[source]¶
Rules for coercing inputs to
editfile
into a path.- Parameters:
target (str | PathLike | ModuleType | ClassType | FunctionType) – something coercable to a path or module path
- Returns:
ub.Path
- xdev.desktop_interaction.editfile(fpath, verbose=True)[source]¶
Opens a file or code corresponding to a live python object in your preferred visual editor. This function is mainly useful in an interactive IPython session.
The visual editor is determined by the
VISUAL
environment variable. If this is not specified it defaults to gvim.- Parameters:
fpath (PathLike | ModuleType | str) – a file path or python module / function. If the input is a string it will interpret it either as a Path or a module name. Ambiguity is resolved by choosing a path if the string resolves to an existing path, and then checking if the string corresponds to a module name.
verbose (int) – verbosity
Example
>>> # xdoctest: +SKIP >>> # This test interacts with a GUI frontend, not sure how to test. >>> import xdev >>> ub.editfile(xdev.misc.__file__) >>> ub.editfile(xdev) >>> ub.editfile(xdev.editfile)
- xdev.desktop_interaction.view_directory(dpath=None, verbose=False)[source]¶
View a directory in the operating system file browser. Currently supports windows explorer, mac open, and linux nautlius.
- Parameters:
dpath (PathLike | None) – directory name
verbose (bool) – verbosity
- xdev.desktop_interaction.startfile(fpath, verbose=True)[source]¶
Uses default program defined by the system to open a file. This is done via os.startfile on windows, open on mac, and xdg-open on linux.
- Parameters:
fpath (PathLike) – a file to open using the program associated with the files extension type.
verbose (int) – verbosity
References
http://stackoverflow.com/questions/2692873/quote-posix
Example
>>> # xdoctest: +SKIP >>> # This test interacts with a GUI frontend, not sure how to test. >>> import ubelt as ub >>> base = ub.ensure_app_cache_dir('ubelt') >>> fpath1 = join(base, 'test_open.txt') >>> ub.touch(fpath1) >>> proc = ub.startfile(fpath1)