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: Window

Windows to hold a browser frame inside.

Create a Tk window. title: string to use as title for the windows. master: if not provided, the windows create will be the principal one weight: if true, the first col and row will be configured with weight=1 minsize: a minimum size for height and width icon: if not None, set the windows icon

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: ObjectBrowser

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

Parameters
  • parent – Parent tkinter window.

  • initialDir – Folder to show when loading the dialog.

  • selectionType – Any of SELECT_NONE, SELECT_FILE, SELECT_FOLDER, SELECT_PATH.

  • showHidden – Pass True to show hidden files.

  • selectButton – text for the select button. Defaults to Select.

  • entryLabel – text for the entry widget. Default None. There will be no entry.

  • entryValue – default value for the entry. Needs entryLabel.

  • showInfo – callback to show a string message, otherwise _showInfo will be used.

  • shortCuts – list of extra ShortCut

  • onlyFolders – Pass True to show only folders.

getCurrentDir()[source]
getEntryValue()[source]
onClose()[source]

This onClose is replaced at init time in the FileBrowserWindow with its own callback

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

Bases: BrowserWindow

Windows to hold a file browser frame inside.

Create a Tk window. title: string to use as title for the windows. master: if not provided, the windows create will be the principal one weight: if true, the first col and row will be configured with weight=1 minsize: a minimum size for height and width icon: if not None, set the windows icon

getCurrentDir()[source]
getEntryValue()[source]
getLastSelection()[source]
lastValue = None
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: TreeProvider

Populate a tree with files and folders of a given path

FILE_COLUMN = 'File'
SIZE_COLUMN = 'Size'
fileKey(f)[source]
getDir()[source]
getFileHandlers(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: 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).

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

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: FileHandler

getFileIcon(objFile)[source]

Return the icon name for a given file.

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

Bases: 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.