def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='', filters='', selectedfilter='', options=None): if options is None: options = QFileDialog.Options(0) try: from code_saturne.Base.QtCore import QString except ImportError: QString = None # analysis:ignore tuple_returned = True try: func = getattr(QFileDialog, attr + 'AndFilter') except AttributeError: func = getattr(QFileDialog, attr) if QString is not None: selectedfilter = QString() tuple_returned = False if sys.platform == "win32": # On Windows platforms: redirect standard outputs _temp1, _temp2 = sys.stdout, sys.stderr sys.stdout, sys.stderr = None, None try: result = func(parent, caption, basedir, filters, selectedfilter, options) except TypeError: result = func(parent, caption, basedir, filters, options) finally: if sys.platform == "win32": # On Windows platforms: restore standard outputs sys.stdout, sys.stderr = _temp1, _temp2 # Processing output if tuple_returned: output, selectedfilter = result else: output = result if QString is not None: # PyQt API #1: conversions needed from QString/QStringList selectedfilter = to_text_string(selectedfilter) if isinstance(output, QString): # Single filename output = to_text_string(output) else: # List of filenames output = [to_text_string(fname) for fname in output] # Always returns the tuple (output, selectedfilter) return output, selectedfilter
def keyPressEvent(target, event): if target.completer and target.completer.popup().isVisible(): if event.key() in ( Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab, Qt.Key_Backtab): event.ignore() return ## has ctrl-E been pressed?? isShortcut = (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_E) if (not target.completer or not isShortcut): QTextEdit.keyPressEvent(target, event) ## ctrl or shift key on it's own?? ctrlOrShift = event.modifiers() in (Qt.ControlModifier , Qt.ShiftModifier) if QT_API == "PYQT4" and has_qstring: if ctrlOrShift and event.text().isEmpty(): # ctrl or shift key on it's own return elif QT_API == "PYQT5" or has_qstring == False: if ctrlOrShift and len(event.text()) < 1: # ctrl or shift key on it's own return hasModifier = ((event.modifiers() != Qt.NoModifier) and not ctrlOrShift) completionPrefix = target.textUnderCursor() # EOW test and compatibily with PyQt4/PyQt5 if QT_API == "PYQT4" and has_qstring: eow = QString("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-=") #end of word if (not isShortcut and (hasModifier or event.text().isEmpty() or completionPrefix.length() < 2 or eow.contains(event.text().right(1)))): target.completer.popup().hide() return elif QT_API == "PYQT5" or has_qstring == False: eow = "~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-=" #end of word if (not isShortcut and (hasModifier or len(event.text()) < 1 or len(completionPrefix) < 2 or event.text()[-1] in eow)): target.completer.popup().hide() return if (completionPrefix != target.completer.completionPrefix()): target.completer.setCompletionPrefix(completionPrefix) popup = target.completer.popup() popup.setCurrentIndex( target.completer.completionModel().index(0,0)) cr = target.cursorRect() cr.setWidth(target.completer.popup().sizeHintForColumn(0) + target.completer.popup().verticalScrollBar().sizeHint().width()) target.completer.complete(cr) ## popup it up!