pyworkflow.gui.browser module

In this module a simple ObjectBrowser is implemented. This class can be subclasses to extend its functionality. A concrete use of ObjectBrowser is FileBrowser, where the elements to inspect and preview are files.

class pyworkflow.gui.browser.BrowserWindow(title, master=None, **kwargs)[source]

Bases: pyworkflow.gui.gui.Window

Windows to hold a browser frame inside.

setBrowser(browser, row=0, column=0)[source]
class pyworkflow.gui.browser.FileBrowser(parent, initialDir='.', selectionType=1, selectionSingle=True, allowFilter=True, filterFunction=None, previewDim=144, showHidden=False, selectButton='Select', entryLabel=None, entryValue='', showInfo=None, shortCuts=None, onlyFolders=False)[source]

Bases: pyworkflow.gui.browser.ObjectBrowser

The FileBrowser is a particular class of ObjectBrowser where the “objects” are just files and directories.

getCurrentDir()[source]
getEntryValue()[source]
onClose()[source]
onSelect(obj)[source]
class pyworkflow.gui.browser.FileBrowserWindow(title, master=None, path=None, onSelect=None, shortCuts=None, **kwargs)[source]

Bases: pyworkflow.gui.browser.BrowserWindow

Windows to hold a file browser frame inside.

getCurrentDir()[source]
getEntryValue()[source]
registerHandlers()[source]
class pyworkflow.gui.browser.FileHandler[source]

Bases: object

This class will be used to get the icon, preview and info from the different types of objects. It should be used with FileTreeProvider, where different types of handlers can be registered.

getFileActions(objFile)[source]

Return actions that can be done with this object. Actions will be displayed in the context menu and the first one will be the default when double-click.

getFileIcon(objFile)[source]

Return the icon name for a given file.

getFilePreview(objFile)[source]

Return the preview image and description for the specific object.

class pyworkflow.gui.browser.FileInfo(path, filename)[source]

Bases: object

This class will store some information about a file. It will serve to display files items in the Tree.

getDate()[source]
getDateStr()[source]
getFileName()[source]
getPath()[source]
getSize()[source]
getSizeStr()[source]

Return a human readable string of the file size.

isDir()[source]
class pyworkflow.gui.browser.FileTreeProvider(currentDir=None, showHidden=False, onlyFolders=False)[source]

Bases: pyworkflow.gui.tree.TreeProvider

Populate a tree with files and folders of a given path

FILE_COLUMN = 'File'
SIZE_COLUMN = 'Size'
fileKey(f)[source]
getDir()[source]
getFileHandler(obj)[source]
getObjectActions(obj)[source]

Return a list of tuples (key, action) were keys are the string options that will be display in the context menu and the actions are the functions to call when the specific action is selected. The first action in the list will be taken as the default one when the element is double-clicked.

getObjectInfo(obj)[source]

This function will be called by the Tree with each object that will be inserted. A dictionary should be returned with the possible following entries: ‘key’: the key value to insert in the Tree ‘text’: text of the object to be displayed

(if not passed the ‘key’ will be used)

‘image’: image path to be displayed as icon (optional) ‘parent’: the object’s parent in which insert this object (optional) ‘tags’: list of tags names (optional)

getObjectPreview(obj)[source]

Should return a tuple (img, desc), where img is the preview image and desc the description string.

getObjects()[source]

Return the objects that will be inserted in the Tree

classmethod registerFileHandler(fileHandler, *extensions)[source]

Register a FileHandler for a given file extension. Params:

fileHandler: the FileHandler that will take care of extensions. *extensions: the extensions list that will be associated to this

FileHandler.
setDir(newPath)[source]
class pyworkflow.gui.browser.ObjectBrowser(parent, treeProvider, showPreview=True, showPreviewTop=True, **args)[source]

Bases: tkinter.Frame

This class will implement a simple object browser. Basically, it will display a list of elements at the left panel and can display a preview and description on the right panel for the selected element. An ObjectView will be used to grab information for each element such as: icon, preview and description. A TreeProvider will be used to populate the list (Tree).

getSelected()[source]

Return the selected object.

class pyworkflow.gui.browser.ShortCut(path, name, icon=None, toolTip='')[source]

Bases: object

Shortcuts to paths to be displayed in the file browser

static factory(path, name, icon=None, toolTip='')[source]

Factory method to create shortcuts

class pyworkflow.gui.browser.SqlFileHandler[source]

Bases: pyworkflow.gui.browser.FileHandler

getFileIcon(objFile)[source]

Return the icon name for a given file.

class pyworkflow.gui.browser.TextFileHandler(textIcon)[source]

Bases: pyworkflow.gui.browser.FileHandler

getFileIcon(objFile)[source]

Return the icon name for a given file.

pyworkflow.gui.browser.isStandardImage(filename)[source]

Check if a filename have an standard image extension.