Package schrodinger :: Package ui :: Package qt :: Module filedialog :: Class OpenDirAsFileDialog
[hide private]
[frames] | no frames]

Class OpenDirAsFileDialog

       object --+                        
                |                        
sip.simplewrapper --+                    
                    |                    
          sip.wrapper --+                
                        |                
     PyQt5.QtCore.QObject --+            
                            |            
           object --+       |            
                    |       |            
    sip.simplewrapper --+   |            
                        |   |            
 PyQt5.QtGui.QPaintDevice --+            
                            |            
      PyQt5.QtWidgets.QWidget --+        
                                |        
          PyQt5.QtWidgets.QDialog --+    
                                    |    
          PyQt5.QtWidgets.QFileDialog --+
                                        |
                           object --+   |
                                    |   |
                   CustomSideBarMixin --+
                                        |
                                       OpenDirAsFileDialog
Known Subclasses:

A file dialog tailored to allow the user to "open" directories such as projects or phase databases as if they were files.

Differences from a typical Open File Dialog:

The dialog should first be created, then the getFilename method called. ie:

   dialog = OpenDirAsFileDialog()
   project_path = dialog.getFilename()
   if project_path:
       Do stuff

Because QFileDialogs normally cannot handle accepting either a directory OR a file, this uses a few tricks noted throughout the code to make the process of selecting either a special directory or a zip file invisible to the user.

This is the parent class and should be subclassed for use. The setMyIconProvider and setExtensionChecker methods need to be overwritten for this class to be used.

Nested Classes [hide private]

Inherited from PyQt5.QtWidgets.QFileDialog: AcceptMode, DialogLabel, FileMode, Option, Options, ViewMode

Inherited from PyQt5.QtWidgets.QDialog: DialogCode

Inherited from PyQt5.QtWidgets.QWidget: RenderFlag, RenderFlags

Inherited from PyQt5.QtGui.QPaintDevice: PaintDeviceMetric

Instance Methods [hide private]
 
__init__(self, parent=None, caption='Open Project', directory='.', accept='Open', filter='Projects (*.prj *.prjzip *.prj.zip)', label='Project:')
Create a OpenDirAsFileDialog instance
 
_finishIfSpecialFile(self, path)
Detect if the user has currently selected a special file/directory and either double-clicked on it or hit the accept button.
 
_selectionChanged(self, path)
Called when the user clicks on a new file name.
 
accept(self)
Overwrites the QFileDialog accept method to also accept directories if they are a special directory.
 
getFilename(self)
Open the dialog, allow the user to choose a special directory/file, and return the path to that directory/file.
 
setExtensionChecker(self)
Should be overwritten in subclasses to set a callable function that takes a path as input and returns True if that path is one of the "special" directories/files that this dialog treats as a "file".
 
setMyIconProvider(self)
Should be overwritten in subclasses to set a custom icon provider inherited from QtWidgets.QFileIconProvider.

Inherited from PyQt5.QtWidgets.QFileDialog: acceptMode, changeEvent, currentChanged, currentUrlChanged, defaultSuffix, directory, directoryEntered, directoryUrl, directoryUrlEntered, done, fileMode, fileSelected, filesSelected, filter, filterSelected, getExistingDirectory, getExistingDirectoryUrl, getOpenFileName, getOpenFileNames, getOpenFileUrl, getOpenFileUrls, getSaveFileName, getSaveFileUrl, history, iconProvider, itemDelegate, labelText, mimeTypeFilters, nameFilters, open, options, proxyModel, restoreState, saveState, selectFile, selectMimeTypeFilter, selectNameFilter, selectUrl, selectedFiles, selectedNameFilter, selectedUrls, setAcceptMode, setDefaultSuffix, setDirectory, setDirectoryUrl, setFileMode, setFilter, setHistory, setIconProvider, setItemDelegate, setLabelText, setMimeTypeFilters, setNameFilter, setNameFilters, setOption, setOptions, setProxyModel, setSidebarUrls, setSupportedSchemes, setViewMode, setVisible, sidebarUrls, supportedSchemes, testOption, urlSelected, urlsSelected, viewMode

Inherited from PyQt5.QtWidgets.QDialog: accepted, closeEvent, contextMenuEvent, eventFilter, exec_, finished, isSizeGripEnabled, keyPressEvent, minimumSizeHint, reject, rejected, resizeEvent, result, setModal, setResult, setSizeGripEnabled, showEvent, sizeHint

Inherited from PyQt5.QtWidgets.QWidget: acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, contentsMargins, contentsRect, contextMenuPolicy, create, createWindowContainer, cursor, customContextMenuRequested, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, ensurePolished, enterEvent, event, find, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grab, grabGesture, grabKeyboard, grabMouse, grabShortcut, graphicsEffect, graphicsProxyWidget, hasFocus, hasHeightForWidth, hasMouseTracking, height, heightForWidth, hide, hideEvent, initPainter, inputMethodEvent, inputMethodHints, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyReleaseEvent, keyboardGrabber, layout, layoutDirection, leaveEvent, locale, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, moveEvent, nativeEvent, nativeParentWidget, nextInFocusChain, normalGeometry, overrideWindowFlags, overrideWindowState, paintEngine, paintEvent, palette, parentWidget, pos, previousInFocusChain, raise_, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, repaint, resize, restoreGeometry, saveGeometry, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedWidth, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGraphicsEffect, setHidden, setInputMethodHints, setLayout, setLayoutDirection, setLocale, setMask, setMaximumHeight, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setShortcutAutoRepeat, setShortcutEnabled, setSizeIncrement, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setToolTipDuration, setUpdatesEnabled, setWhatsThis, setWindowFilePath, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowTitle, sharedPainter, show, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, toolTipDuration, underMouse, ungrabGesture, unsetCursor, unsetLayoutDirection, unsetLocale, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, winId, window, windowFilePath, windowFlags, windowHandle, windowIcon, windowIconChanged, windowIconText, windowIconTextChanged, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowTitleChanged, windowType, x, y

Inherited from PyQt5.QtCore.QObject: __getattr__, blockSignals, childEvent, children, connectNotify, customEvent, deleteLater, destroyed, disconnect, disconnectNotify, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, findChild, findChildren, inherits, installEventFilter, isSignalConnected, isWidgetType, isWindowType, killTimer, metaObject, moveToThread, objectName, objectNameChanged, parent, property, pyqtConfigure, receivers, removeEventFilter, sender, senderSignalIndex, setObjectName, setProperty, signalsBlocked, startTimer, thread, timerEvent, tr

Inherited from PyQt5.QtGui.QPaintDevice: colorCount, depth, devicePixelRatio, devicePixelRatioF, devicePixelRatioFScale, heightMM, logicalDpiX, logicalDpiY, paintingActive, physicalDpiX, physicalDpiY, widthMM

Inherited from sip.simplewrapper: __new__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from PyQt5.QtWidgets.QFileDialog: Accept, AcceptOpen, AcceptSave, AnyFile, Detail, Directory, DirectoryOnly, DontConfirmOverwrite, DontResolveSymlinks, DontUseCustomDirectoryIcons, DontUseNativeDialog, DontUseSheet, ExistingFile, ExistingFiles, FileName, FileType, HideNameFilterDetails, List, LookIn, ReadOnly, Reject, ShowDirsOnly

Inherited from PyQt5.QtWidgets.QDialog: Accepted, Rejected

Inherited from PyQt5.QtWidgets.QWidget: DrawChildren, DrawWindowBackground, IgnoreMask

Inherited from PyQt5.QtCore.QObject: staticMetaObject

Inherited from PyQt5.QtGui.QPaintDevice: PdmDepth, PdmDevicePixelRatio, PdmDevicePixelRatioScaled, PdmDpiX, PdmDpiY, PdmHeight, PdmHeightMM, PdmNumColors, PdmPhysicalDpiX, PdmPhysicalDpiY, PdmWidth, PdmWidthMM

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, parent=None, caption='Open Project', directory='.', accept='Open', filter='Projects (*.prj *.prjzip *.prj.zip)', label='Project:')
(Constructor)

 

Create a OpenDirAsFileDialog instance

Parameters:
  • parent (QWidget) - The parent widget for this dialog
  • caption (str) - The caption for this dialog
  • directory (str) - The directory this dialog starts in
  • accept (str) - The text that appears on the Open/Accept/Choose button that the user clicks to select a file and close the dialog
  • filter (str) - The file name filter used by the dialog
  • label (str) - The label in front of the selected file name edit
Overrides: object.__init__

_finishIfSpecialFile(self, path)

 

Detect if the user has currently selected a special file/directory and either double-clicked on it or hit the accept button. If so, close the dialog.

Parameters:
  • path (str) - If this was called via the accept method, path will be the first selected file. If this was called via the directoryEntered signal, path will be the directory that the user just double-clicked on.

_selectionChanged(self, path)

 

Called when the user clicks on a new file name. If that file name is a directory, PyQt won't put its name in the selected file box, because PyQt thinks this dialog only wants files (there is no PyQt file OR directory dialog). We have to manually put the name in the file box if this is a special file, but we have no Python-wrapped handle to do that. But this is a back door way to accomplish it.

accept(self)

 

Overwrites the QFileDialog accept method to also accept directories if they are a special directory. Normally, accept would only accept files.

Overrides: PyQt5.QtWidgets.QDialog.accept