FileView

class lys.widgets.fileView.FileSystemView(path, model=<PyQt5.QtWidgets.QFileSystemModel object>, drop=False, filter=True, menu=True)[source]

Bases: QWidget

FileSystemView is a custom widget to see files, which is mainly used in main window.

Developers can get selected paths by selectedPaths() method. Context menu for specified type can be registered by registerFileMenu() method.

See selectedPaths() and registerFileMenu() for detail and examples

Parameters
  • path (str) – path to see files.

  • model (QFileSystemModel) – model used in this view

  • drop (bool) – Accept drag & drop or not.

  • filter (bool) – Enable filtering or not.

  • menu (bool) – Enable context menu or not.

registerFileMenu(ext, menu, add_default=True, **kwargs)[source]

register new context menu to filetype specified by ext

Parameters
  • ext (str) – extension of file type, e.g. “.txt”, “.csv”, etc…

  • menu (QMenu) – context menu to be added.

  • add_default – if True, default menus such as Cut, Copy is automatically added at the end of menu.

Example:

from lys import glb
from lys.Qt import QtWidgets

action = QtWidgets.QAction("Test", triggered = lambda: print("test"))
menu = QtWidgets.QMenu()
menu.addAction(action)

view = glb.mainWindow().fileView     # access global fileview in main window.
view.registerFileMenu(".txt", menu)  # By right clicking .txt file, you see 'test' menu.
selectedPath()[source]

Returns first selected path.

Returns

path selected

Return type

str

selectedPaths()[source]

Returns selected paths.

Returns

paths selected

Return type

list of str

Example:

from lys import glb
view = glb.mainWindow().fileView     # access global fileview in main window.
view.selectedPaths()                 # ["path selected", "path selected2, ..."]
selectionChanged

Emitted when the selected file is changed.

setPath(path)[source]

Set root directory of file system. :param path: root path :type path: str