A file and folder browser for Panda3D using DirectGUI
This is a simple fullscreen file and folder browser with a basic featureset. Currently implemented are:
- Browsing files and folders
- Display content as symbols or in a detailed list
- Show/Hide hidden files (using unix like leading dot)
- Create new folders
- Filter by file extension
- Resizes with window size changes
- Makes use of the Tooltip class
Install the DirectFolderBrowser via pip
pip install DirectFolderBrowser
To add a browser instance to your running Panda3D application, just instantiate it like shown here:
from DirectFolderBrowser.DirectFolderBrowser import DirectFolderBrowser
# this command will be called by the browser
def callbackCommand(ok):
if ok == 1:
print("User Clicked OK")
# print the selected file
print(browser.get())
browser.hide()
# Destroy the browser if it's not needed anymore
#browser.destroy()
elif ok == 0:
print("User Clicked Cancel")
browser.hide()
browser.destroy()
# show the browser as file browser
browser = DirectFolderBrowser(callbackCommand, fileBrowser=True)
The DirectFolderBrowser accepts a few arguments.
- command: The command that will be called on closing the browser
- fileBrowser: If set to True the browser will show files, otherwise it will only show folders
- defaultPath: The initial path the browser will be set to show
- defaultFilename: The filename that will be set by default, only usefull if fileBrowser is True
- fileExtensions: A list of extensions. Only files with those extensions will be shown. Only usefull if fileBrowser is True
- tooltip: An instance of the Tooltip class to display tooltips for certain parts of the editor
- iconDir: A directory path that contains replacement images. It must contain all required images which are:
File.png
Folder.png
FolderNew.png
FolderShowHidden.png
FolderUp.png
Reload.png - parent: Another DirectGUI element which has pixel2d as root parent.
The browser frame is placed centered so a frame for example should have equal sizes in horizontal and vertical directions
e.g. frameSize=(-250,250,-200,200) - askForOverwrite: If an existing file is selected, a dialog will pop up ask the user if the file should be overwritten.
- oneClickNavigate: If true, navigating into folders is done with a single click rather than double. Also configurable via the boolean "DirectFolderBrowser-one-click-navigate" configuration variable.
- usePathBar: Determines if selected files should be set in the path bar or in a dedicated selected file bar.
- title: If a title is given it will create a title bar at the top of the browser frame displaying the title text, if title is an empty string, the title bar will be collapsed.
- fileFilters: A dictionary containing a display text as key and a list of file extension strings that should be used when selected. NOTE: This will overwrite the fileExtensions parameter!