本文整理汇总了Python中PyQt5.QtWidgets.QCompleter类的典型用法代码示例。如果您正苦于以下问题:Python QCompleter类的具体用法?Python QCompleter怎么用?Python QCompleter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QCompleter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileSystemOpener
class FileSystemOpener(QWidget):
requestHide = pyqtSignal()
def __init__(self):
super(FileSystemOpener, self).__init__()
hbox = QHBoxLayout(self)
hbox.setContentsMargins(0, 0, 0, 0)
self.btnClose = QPushButton(
self.style().standardIcon(QStyle.SP_DialogCloseButton), '')
self.completer = QCompleter(self)
self.pathLine = ui_tools.LineEditTabCompleter(self.completer)
fileModel = QFileSystemModel(self.completer)
fileModel.setRootPath("")
self.completer.setModel(fileModel)
self.pathLine.setCompleter(self.completer)
self.btnOpen = QPushButton(
self.style().standardIcon(QStyle.SP_ArrowRight), 'Open!')
hbox.addWidget(self.btnClose)
hbox.addWidget(QLabel(_translate("FileSystemOpener", "Path:")))
hbox.addWidget(self.pathLine)
hbox.addWidget(self.btnOpen)
self.pathLine.returnPressed.connect(self._open_file)
self.btnOpen.clicked['bool'].connect(self._open_file)
def _open_file(self):
path = self.pathLine.text()
main_container.MainContainer().open_file(path)
self.requestHide.emit()
def showEvent(self, event):
super(FileSystemOpener, self).showEvent(event)
self.pathLine.selectAll()
示例2: set_auto_completion
def set_auto_completion(self, string_list):
completer = QCompleter()
model = QStringListModel()
model.setStringList(string_list)
completer.setModel(model)
completer.activated.connect(self.search, type=Qt.QueuedConnection)
self.combobox_search.setCompleter(completer)
示例3: _make_expression_completer
def _make_expression_completer(owner, data_type):
model = QStringListModel()
comp = QCompleter(owner)
comp.setCaseSensitivity(Qt.CaseSensitive)
if isinstance(data_type, str):
data_type = uavcan.TYPENAMES[data_type]
# TODO: implement proper completion, requires Python lexer
# TODO: IPython/Jupyter solves the same task splendidly, might make sense to take a closer look at their code
def make_suggestions(t):
"""Builds a flat list of fields in a given data type"""
if t.category == t.CATEGORY_COMPOUND:
out = []
for a in t.fields + t.constants:
if (a.type.category != a.type.CATEGORY_COMPOUND) and \
(a.type.category != a.type.CATEGORY_VOID) and \
(a.type.category != a.type.CATEGORY_ARRAY or
a.type.value_type.category == a.type.value_type.CATEGORY_PRIMITIVE):
out.append(a.name)
out += [(a.name + x) for x in make_suggestions(a.type)]
return [('.' + x) for x in out]
elif t.category == t.CATEGORY_ARRAY:
base = '[0]'
if t.value_type.category == t.CATEGORY_COMPOUND:
return [(base + x) for x in make_suggestions(t.value_type)]
else:
return [base]
return []
suggestions = [(EXPRESSION_VARIABLE_FOR_MESSAGE + x) for x in make_suggestions(data_type)]
model.setStringList(suggestions)
comp.setModel(model)
return comp
示例4: Completer
class Completer(QGraphicsProxyWidget, object):
''' Class for handling text autocompletion in the SDL scene '''
def __init__(self, parent):
''' Create an autocompletion list popup '''
widget = QListWidget()
super(Completer, self).__init__(parent)
self.setWidget(widget)
self.string_list = QStringListModel()
self._completer = QCompleter()
self.parent = parent
self._completer.setCaseSensitivity(Qt.CaseInsensitive)
# For some reason the default minimum size is (61,61)
# Set it to 0 so that the size of the box is not taken
# into account when it is hidden.
self.setMinimumSize(0, 0)
self.prepareGeometryChange()
self.resize(0, 0)
self.hide()
def set_completer_list(self):
''' Set list of items for the autocompleter popup '''
compl = [item.replace('-', '_') for item in
self.parent.parentItem().completion_list]
self.string_list.setStringList(compl)
self._completer.setModel(self.string_list)
def set_completion_prefix(self, completion_prefix):
'''
Set the current completion prefix (user-entered text)
and set the corresponding list of words in the popup widget
'''
self._completer.setCompletionPrefix(completion_prefix)
self.widget().clear()
count = self._completer.completionCount()
for i in xrange(count):
self._completer.setCurrentRow(i)
self.widget().addItem(self._completer.currentCompletion())
self.prepareGeometryChange()
if count:
self.resize(self.widget().sizeHintForColumn(0) + 40, 70)
else:
self.resize(0, 0)
return count
# pylint: disable=C0103
def keyPressEvent(self, e):
super(Completer, self).keyPressEvent(e)
if e.key() == Qt.Key_Escape:
self.parentItem().setFocus()
# Consume the event so that it is not repeated at EditableText level
e.accept()
# pylint: disable=C0103
def focusOutEvent(self, event):
''' When the user leaves the popup, return focus to parent '''
super(Completer, self).focusOutEvent(event)
self.hide()
self.resize(0, 0)
self.parentItem().setFocus()
示例5: ManualInstallWidget
class ManualInstallWidget(QWidget):
"""Manually Installed plugins widget"""
def __init__(self, parent):
super(ManualInstallWidget, self).__init__()
self._parent = parent
vbox = QVBoxLayout(self)
form = QFormLayout()
self._txtName = QLineEdit()
self._txtName.setPlaceholderText('my_plugin')
self._txtVersion = QLineEdit()
self._txtVersion.setPlaceholderText('0.1')
form.addRow(translations.TR_PROJECT_NAME, self._txtName)
form.addRow(translations.TR_VERSION, self._txtVersion)
vbox.addLayout(form)
hPath = QHBoxLayout()
self._txtFilePath = QLineEdit()
self._txtFilePath.setPlaceholderText(os.path.join(
os.path.expanduser('~'), 'full', 'path', 'to', 'plugin.zip'))
self._btnFilePath = QPushButton(QIcon(":img/open"), '')
self.completer, self.dirs = QCompleter(self), QDirModel(self)
self.dirs.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot)
self.completer.setModel(self.dirs)
self._txtFilePath.setCompleter(self.completer)
hPath.addWidget(QLabel(translations.TR_FILENAME))
hPath.addWidget(self._txtFilePath)
hPath.addWidget(self._btnFilePath)
vbox.addLayout(hPath)
vbox.addSpacerItem(QSpacerItem(0, 1, QSizePolicy.Expanding,
QSizePolicy.Expanding))
hbox = QHBoxLayout()
hbox.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
self._btnInstall = QPushButton(translations.TR_INSTALL)
hbox.addWidget(self._btnInstall)
vbox.addLayout(hbox)
#Signals
self._btnFilePath.clicked['bool'].connect(self._load_plugin_path)
self._btnInstall.clicked['bool'].connect(self.install_plugin)
def _load_plugin_path(self):
"""Ask the user a plugin filename"""
path = QFileDialog.getOpenFileName(self,
translations.TR_SELECT_PLUGIN_PATH)
if path:
self._txtFilePath.setText(path)
def install_plugin(self):
"""Install a plugin manually"""
if self._txtFilePath.text() and self._txtName.text():
plug = []
plug.append(self._txtName.text())
plug.append(self._txtVersion.text())
plug.append('')
plug.append('')
plug.append('')
plug.append(self._txtFilePath.text())
self._parent.install_plugins_manually([plug])
示例6: return_tag_completer_TextEdit
def return_tag_completer_TextEdit(parent=None):
ns = gallerydb.TagDB.get_all_ns()
for t in gallerydb.TagDB.get_all_tags():
ns.append(t)
TextEditCompleter = CompleterTextEdit()
comp = QCompleter(ns, parent)
comp.setCaseSensitivity(Qt.CaseInsensitive)
TextEditCompleter.setCompleter(comp)
return TextEditCompleter
示例7: complete
def complete(self, cr, results):
proposals = []
proposals += results.get('modules', [])
proposals += results.get('classes', [])
proposals += results.get('attributes', [])
proposals += results.get('functions', [])
self.model().setStringList(proposals)
self.popup().setCurrentIndex(self.model().index(0, 0))
cr.setWidth(self.popup().sizeHintForColumn(0)
+ self.popup().verticalScrollBar().sizeHint().width() + 10)
QCompleter.complete(self, cr)
示例8: __init__
def __init__(self, winPrincipal):
self.winPrincipal = winPrincipal
self.producto = Producto()
self.proveedor = Proveedor()
self.marca = Marca()
self.rubro = Rubro()
self.estado = ""
self.conexionProducto = conexionProducto()
self.completerRubro = QCompleter()
self.completerMarca = QCompleter()
self.completerProveedor = QCompleter()
self.configInit()
示例9: MainWindow
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.createMenu()
self.completingTextEdit = TextEdit()
self.completer = QCompleter(self)
self.completer.setModel(self.modelFromFile(':/resources/wordlist.txt'))
self.completer.setModelSorting(QCompleter.CaseInsensitivelySortedModel)
self.completer.setCaseSensitivity(Qt.CaseInsensitive)
self.completer.setWrapAround(False)
self.completingTextEdit.setCompleter(self.completer)
self.setCentralWidget(self.completingTextEdit)
self.resize(500, 300)
self.setWindowTitle("Completer")
def createMenu(self):
exitAction = QAction("Exit", self)
aboutAct = QAction("About", self)
aboutQtAct = QAction("About Qt", self)
exitAction.triggered.connect(QApplication.instance().quit)
aboutAct.triggered.connect(self.about)
aboutQtAct.triggered.connect(QApplication.instance().aboutQt)
fileMenu = self.menuBar().addMenu("File")
fileMenu.addAction(exitAction)
helpMenu = self.menuBar().addMenu("About")
helpMenu.addAction(aboutAct)
helpMenu.addAction(aboutQtAct)
def modelFromFile(self, fileName):
f = QFile(fileName)
if not f.open(QFile.ReadOnly):
return QStringListModel(self.completer)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
words = []
while not f.atEnd():
line = f.readLine().trimmed()
if line.length() != 0:
try:
line = str(line, encoding='ascii')
except TypeError:
line = str(line)
words.append(line)
QApplication.restoreOverrideCursor()
return QStringListModel(words, self.completer)
def about(self):
QMessageBox.about(self, "About",
"This example demonstrates the different features of the "
"QCompleter class.")
示例10: setupUi
def setupUi(self):
self.log.debug("Initializing UI.")
self.load_ui("dta.ui")
# set up source/target autocompletion
type_completion_list = [str(t) for t in self.policy.types()]
type_completer_model = QStringListModel(self)
type_completer_model.setStringList(sorted(type_completion_list))
self.type_completion = QCompleter()
self.type_completion.setModel(type_completer_model)
self.source.setCompleter(self.type_completion)
self.target.setCompleter(self.type_completion)
# setup indications of errors on source/target/default
self.orig_palette = self.source.palette()
self.error_palette = self.source.palette()
self.error_palette.setColor(QPalette.Base, Qt.red)
self.clear_source_error()
self.clear_target_error()
# set up processing thread
self.thread = QThread()
self.worker = ResultsUpdater(self.query)
self.worker.moveToThread(self.thread)
self.worker.raw_line.connect(self.raw_results.appendPlainText)
self.worker.finished.connect(self.thread.quit)
self.thread.started.connect(self.worker.update)
self.thread.finished.connect(self.update_complete)
# create a "busy, please wait" dialog
self.busy = QProgressDialog(self)
self.busy.setModal(True)
self.busy.setRange(0, 0)
self.busy.setMinimumDuration(0)
self.busy.canceled.connect(self.thread.requestInterruption)
self.busy.reset()
# update busy dialog from DTA INFO logs
self.handler = LogHandlerToSignal()
self.handler.message.connect(self.busy.setLabelText)
logging.getLogger("setools.dta").addHandler(self.handler)
# Ensure settings are consistent with the initial .ui state
self.max_path_length.setEnabled(self.all_paths.isChecked())
self.source.setEnabled(not self.flows_in.isChecked())
self.target.setEnabled(not self.flows_out.isChecked())
self.criteria_frame.setHidden(not self.criteria_expander.isChecked())
self.notes.setHidden(not self.notes_expander.isChecked())
# connect signals
self.buttonBox.clicked.connect(self.run)
self.source.textEdited.connect(self.clear_source_error)
self.source.editingFinished.connect(self.set_source)
self.target.textEdited.connect(self.clear_target_error)
self.target.editingFinished.connect(self.set_target)
self.all_paths.toggled.connect(self.all_paths_toggled)
self.flows_in.toggled.connect(self.flows_in_toggled)
self.flows_out.toggled.connect(self.flows_out_toggled)
self.reverse.stateChanged.connect(self.reverse_toggled)
self.exclude_types.clicked.connect(self.choose_excluded_types)
示例11: CompletingComboBox
class CompletingComboBox(QComboBox):
"""An editable combo box that filters and autocompletes."""
def __init__(self, parent=None):
super().__init__(parent)
self.setEditable(True)
self.filter = QSortFilterProxyModel(self)
self.filter.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.filter.setSourceModel(self.model())
self.completer = QCompleter(self.filter, self)
self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
self.setCompleter(self.completer)
self.lineEdit().textEdited.connect(
self.filter.setFilterFixedString)
self.currentIndexChanged.connect(self._index_changed)
def _index_changed(self, index):
self.lineEdit().selectAll()
示例12: setCompleterRubro
def setCompleterRubro(self):
listRubros = self.conexionProducto.listRubro()
self.completerRubro = QCompleter(listRubros)
self.completerRubro.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.winPrincipal.txtRubro_p.setCompleter(self.completerRubro)
示例13: __init__
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget (QWidget)
"""
super(HelpWebSearchWidget, self).__init__(parent)
from E5Gui.E5LineEdit import E5LineEdit
from E5Gui.E5LineEditButton import E5LineEditButton
from .OpenSearch.OpenSearchManager import OpenSearchManager
self.__mw = parent
self.__openSearchManager = OpenSearchManager(self)
self.__openSearchManager.currentEngineChanged.connect(
self.__currentEngineChanged)
self.__currentEngine = ""
self.__enginesMenu = QMenu(self)
self.__engineButton = E5LineEditButton(self)
self.__engineButton.setMenu(self.__enginesMenu)
self.addWidget(self.__engineButton, E5LineEdit.LeftSide)
self.__searchButton = E5LineEditButton(self)
self.__searchButton.setIcon(UI.PixmapCache.getIcon("webSearch.png"))
self.addWidget(self.__searchButton, E5LineEdit.LeftSide)
self.__model = QStandardItemModel(self)
self.__completer = QCompleter()
self.__completer.setModel(self.__model)
self.__completer.setCompletionMode(
QCompleter.UnfilteredPopupCompletion)
self.__completer.setWidget(self)
self.__searchButton.clicked.connect(self.__searchButtonClicked)
self.textEdited.connect(self.__textEdited)
self.returnPressed.connect(self.__searchNow)
self.__completer.activated[QModelIndex].connect(
self.__completerActivated)
self.__completer.highlighted[QModelIndex].connect(
self.__completerHighlighted)
self.__enginesMenu.aboutToShow.connect(self.__showEnginesMenu)
self.__suggestionsItem = None
self.__suggestions = []
self.__suggestTimer = None
self.__suggestionsEnabled = Preferences.getHelp("WebSearchSuggestions")
self.__recentSearchesItem = None
self.__recentSearches = []
self.__maxSavedSearches = 10
self.__engine = None
self.__loadSearches()
self.__setupCompleterMenu()
self.__currentEngineChanged()
示例14: __init__
def __init__(self, parent, node, node_monitor):
super(DynamicNodeIDAllocatorWidget, self).__init__(parent)
self.setTitle('Dynamic node ID allocation server (uavcan.protocol.dynamic_node_id.*)')
self._node = node
self._node_monitor = node_monitor
self._allocator = None
self._allocation_table = BasicTable(self, self.COLUMNS, font=get_monospace_font())
self._allocation_table_update_timer = QTimer(self)
self._allocation_table_update_timer.setSingleShot(False)
self._allocation_table_update_timer.start(500)
self._allocation_table_update_timer.timeout.connect(self._update_table)
self._start_stop_button = make_icon_button('rocket', 'Launch/stop the dynamic node ID allocation server', self,
checkable=True)
self._start_stop_button.clicked.connect(self._on_start_stop_button)
self._database_file = CommitableComboBoxWithHistory(self)
self._database_file.setAcceptDrops(True)
self._database_file.setToolTip('Path to the allocation table file')
self._database_file.setCurrentText(self.DEFAULT_DATABASE_FILE)
self._database_file.addItem(self._database_file.currentText())
self._database_file.on_commit = self._on_start_stop_button
self._select_database_file = make_icon_button('folder-open-o', 'Open allocation table file', self,
on_clicked=self._on_select_database_file)
db_file_completer = QCompleter()
db_file_completer.setModel(QDirModel(db_file_completer))
self._database_file.setCompleter(db_file_completer)
self._sync_gui()
layout = QVBoxLayout(self)
controls_layout = QHBoxLayout(self)
controls_layout.addWidget(self._start_stop_button)
controls_layout.addWidget(self._database_file, 1)
controls_layout.addWidget(self._select_database_file)
layout.addLayout(controls_layout)
layout.addWidget(self._allocation_table, 1)
self.setLayout(layout)
示例15: __init__
def __init__(self, device_name: str, project_manager: ProjectManager, signal=None, backend_handler=None,
network_raw_mode=False, signals=None, parent=None):
super().__init__(parent)
self.ui = Ui_SniffSettings()
self.ui.setupUi(self)
signals = signals if signals is not None else []
self.project_manager = project_manager
for encoding in self.project_manager.decodings:
self.ui.comboBox_sniff_encoding.addItem(encoding.name)
self.bootstrap(project_manager.device_conf, signal, enforce_default=True)
self.sniffer = ProtocolSniffer(bit_len=self.ui.spinbox_sniff_BitLen.value(),
center=self.ui.spinbox_sniff_Center.value(),
noise=self.ui.spinbox_sniff_Noise.value(),
tolerance=self.ui.spinbox_sniff_ErrorTolerance.value(),
modulation_type=self.ui.combox_sniff_Modulation.currentIndex(),
device=device_name,
backend_handler=BackendHandler() if backend_handler is None else backend_handler,
network_raw_mode=network_raw_mode)
self.sniffer.adaptive_noise = self.ui.checkBoxAdaptiveNoise.isChecked()
self.sniffer.automatic_center = self.ui.checkBoxAutoCenter.isChecked()
self.create_connects()
self.ui.comboBox_sniff_encoding.currentIndexChanged.emit(self.ui.comboBox_sniff_encoding.currentIndex())
self.ui.comboBox_sniff_viewtype.setCurrentIndex(constants.SETTINGS.value('default_view', 0, int))
# Auto Complete like a Boss
completer = QCompleter()
completer.setModel(QDirModel(completer))
self.ui.lineEdit_sniff_OutputFile.setCompleter(completer)
self.signals = signals
if len(signals) == 0:
self.ui.label_sniff_Signal.hide()
self.ui.btn_sniff_use_signal.hide()
self.ui.comboBox_sniff_signal.hide()
else:
for signal in signals:
self.ui.comboBox_sniff_signal.addItem(signal.name)