本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.addItem方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.addItem方法的具体用法?Python QComboBox.addItem怎么用?Python QComboBox.addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.addItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_row
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
def add_row(self, attr=None, condition_type=None, condition_value=None):
model = self.cond_list.model()
row = model.rowCount()
model.insertRow(row)
attr_combo = QComboBox(
minimumContentsLength=12,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon)
attr_combo.row = row
for var in self._visible_variables(self.data.domain):
attr_combo.addItem(*gui.attributeItem(var))
attr_combo.setCurrentIndex(attr or 0)
self.cond_list.setCellWidget(row, 0, attr_combo)
index = QPersistentModelIndex(model.index(row, 3))
temp_button = QPushButton('×', self, flat=True,
styleSheet='* {font-size: 16pt; color: silver}'
'*:hover {color: black}')
temp_button.clicked.connect(lambda: self.remove_one(index.row()))
self.cond_list.setCellWidget(row, 3, temp_button)
self.remove_all_button.setDisabled(False)
self.set_new_operators(attr_combo, attr is not None,
condition_type, condition_value)
attr_combo.currentIndexChanged.connect(
lambda _: self.set_new_operators(attr_combo, False))
self.cond_list.resizeRowToContents(row)
示例2: DropDownRadioBooleanFilter
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
class DropDownRadioBooleanFilter(QWidget, Control):
"""Container for multiple boolean filters
"""
def __init__(self, tree, dataset, master, parent=None):
QWidget.__init__(self, parent)
Control.__init__(self, tree, dataset, master)
self.setLayout(QHBoxLayout())
self.cb = QComboBox(self)
self.layout().addWidget(self.cb)
rblayout = QVBoxLayout()
self.radioButtons = [QRadioButton("Only", self),
QRadioButton("Excluded", self)
]
for b in self.radioButtons:
rblayout.addWidget(b)
self.radioButtons[0].setChecked(True)
self.layout().addLayout(rblayout)
self.options = []
self.setOptions(tree.subelements_top("Option"))
def setOptions(self, options):
self.cb.clear()
self.options = []
for option in options:
self.cb.addItem(option.displayName)
self.options.append(option)
for op, rb in zip(self.options[0].subelements_top("Option"),
self.radioButtons):
rb.setText(op.displayName)
rb.setChecked(getattr(op, "default", "false") == "true")
def value(self):
return {"excluded": "0" if self.radioButtons[0].isChecked() else "1"}
def query(self):
filter = self.options[self.cb.currentIndex()]
filter = biomart.FilterDescription(
self.tree.registry, "FilterDescription",
filter.attributes, filter.children)
return [("Filter", filter, self.value())]
def setControlValue(self, name, value):
for i, option in enumerate(self.options):
if option.internalName == name:
self.cb.setCurrentIndex(i)
if value == "Only":
self.radioButtons[0].setChecked(True)
示例3: DropDownIdListFilter
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
class DropDownIdListFilter(QWidget, Control):
"""Container for multiple id list filters
"""
def __init__(self, tree, dataset, master, parent=None):
QWidget.__init__(self, parent)
Control.__init__(self, tree, dataset, master)
self.setLayout(QVBoxLayout())
self.setContentsMargins(0, 0, 0, 0)
self.cb = QComboBox()
self.idsEdit = QPlainTextEdit()
self.layout().addWidget(self.cb)
self.layout().addWidget(self.idsEdit)
self.options = []
self.setOptions(tree.subelements_top("Option"))
def setOptions(self, options):
self.cb.clear()
self.options = []
for option in options:
self.cb.addItem(option.displayName)
self.options.append(option)
def value(self):
return str(self.idsEdit.toPlainText()).split()
def query(self):
filter = self.options[self.cb.currentIndex()]
filter = biomart.FilterDescription(
self.tree.registry, "FilterDescription",
filter.attributes, filter.children)
return [("Filter", filter, self.value())]
def setControlValue(self, name, value):
if isinstance(value, list):
value = "\n".join(value)
for i, op in enumerate(self.options):
if name == op.internalName:
self.cb.setCurrentIndex(i)
self.idsEdit.setPlainText(value)
示例4: RecentPathsWComboMixin
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
class RecentPathsWComboMixin(RecentPathsWidgetMixin):
"""
Adds file combo handling to :obj:`RecentPathsWidgetMixin`.
The mixin constructs a combo box `self.file_combo` and provides a method
`set_file_list` for updating its content. The mixin also overloads the
inherited `add_path` and `select_file` to call `set_file_list`.
"""
def __init__(self):
super().__init__()
self.file_combo = \
QComboBox(self, sizeAdjustPolicy=QComboBox.AdjustToContents)
def add_path(self, filename):
"""Add (or move) a file name to the top of recent paths"""
super().add_path(filename)
self.set_file_list()
def select_file(self, n):
"""Move the n-th file to the top of the list"""
super().select_file(n)
self.set_file_list()
def set_file_list(self):
"""
Sets the items in the file list combo
"""
self._check_init()
self.file_combo.clear()
if not self.recent_paths:
self.file_combo.addItem("(none)")
self.file_combo.model().item(0).setEnabled(False)
else:
for i, recent in enumerate(self.recent_paths):
self.file_combo.addItem(recent.basename)
self.file_combo.model().item(i).setToolTip(recent.abspath)
if not os.path.exists(recent.abspath):
self.file_combo.setItemData(i, QBrush(Qt.red),
Qt.TextColorRole)
def workflowEnvChanged(self, key, value, oldvalue):
super().workflowEnvChanged(key, value, oldvalue)
if key == "basedir":
self.set_file_list()
示例5: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
class FileWidget(QWidget):
on_open = pyqtSignal(str)
def __init__(self, dialog_title='', dialog_format='',
start_dir=os.path.expanduser('~/'),
icon_size=(12, 20), minimal_width=200,
browse_label='Browse', on_open=None,
reload_button=True, reload_label='Reload',
recent_files=None, directory_aliases=None,
allow_empty=True, empty_file_label='(none)'):
""" Creates a widget with a button for file loading and
an optional combo box for recent files and reload buttons.
Args:
dialog_title (str): The title of the dialog.
dialog_format (str): Formats for the dialog.
start_dir (str): A directory to start from.
icon_size (int, int): The size of buttons' icons.
on_open (callable): A callback function that accepts filepath as the only argument.
reload_button (bool): Whether to show reload button.
reload_label (str): The text displayed on the reload button.
recent_files (List[str]): List of recent files.
directory_aliases (dict): An {alias: dir} dictionary for fast directories' access.
allow_empty (bool): Whether empty path is allowed.
"""
super().__init__()
self.dialog_title = dialog_title
self.dialog_format = dialog_format
self.start_dir = start_dir
self.recent_files = recent_files
self.directory_aliases = directory_aliases or {}
self.check_existence()
self.on_open.connect(on_open)
self.allow_empty = allow_empty
self.empty_file_label = empty_file_label
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
if recent_files is not None:
self.file_combo = QComboBox()
self.file_combo.setMinimumWidth(minimal_width)
self.file_combo.activated[int].connect(self.select)
self.update_combo()
layout.addWidget(self.file_combo)
self.browse_button = QPushButton(browse_label)
self.browse_button.setFocusPolicy(Qt.NoFocus)
self.browse_button.clicked.connect(self.browse)
self.browse_button.setIcon(self.style()
.standardIcon(QStyle.SP_DirOpenIcon))
self.browse_button.setIconSize(QSize(*icon_size))
self.browse_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
layout.addWidget(self.browse_button)
if reload_button:
self.reload_button = QPushButton(reload_label)
self.reload_button.setFocusPolicy(Qt.NoFocus)
self.reload_button.clicked.connect(self.reload)
self.reload_button.setIcon(self.style()
.standardIcon(QStyle.SP_BrowserReload))
self.reload_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.reload_button.setIconSize(QSize(*icon_size))
layout.addWidget(self.reload_button)
def browse(self, start_dir=None):
start_dir = start_dir or self.start_dir
path, _ = QFileDialog().getOpenFileName(self, self.dialog_title,
start_dir, self.dialog_format)
if path and self.recent_files is not None:
if path in self.recent_files:
self.recent_files.remove(path)
self.recent_files.insert(0, path)
self.update_combo()
self.open_file(path)
def select(self, n):
name = self.file_combo.currentText()
if n < len(self.recent_files):
name = self.recent_files[n]
del self.recent_files[n]
self.recent_files.insert(0, name)
self.open_file(self.recent_files[0])
self.update_combo()
elif name == self.empty_file_label:
self.open_file(self.empty_file_label)
elif name in self.directory_aliases:
self.browse(self.directory_aliases[name])
def update_combo(self):
if self.recent_files is not None:
self.file_combo.clear()
for file in self.recent_files:
self.file_combo.addItem(os.path.split(file)[1])
if self.allow_empty or not self.recent_files:
#.........这里部分代码省略.........
示例6: OWPubmed
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
#.........这里部分代码省略.........
required_text_fields = [
field
for field_name, field
in zip(text_includes_params, PUBMED_TEXT_FIELDS)
if field_name
]
batch_size = min(Pubmed.MAX_BATCH_SIZE, self.num_records) + 1
with self.progressBar(self.num_records/batch_size) as progress:
self.progress = progress
self.output_corpus = self.pubmed_api._retrieve_records(
self.num_records,
required_text_fields
)
self.retrieve_records_button.setText('Retrieve records')
self.download_running = False
self.send(Output.CORPUS, self.output_corpus)
self.update_retrieval_info()
self.run_search_button.setEnabled(True)
def api_progress_callback(self, start_at=None):
if start_at is not None:
self.progress.count = start_at
else:
self.progress.advance()
def api_error_callback(self, error):
self.Error.api_error(str(error))
if self.progress is not None:
self.progress.finish()
def update_search_info(self):
max_records_count = min(
self.pubmed_api.MAX_RECORDS,
self.pubmed_api.search_record_count
)
self.search_info_label.setText(
'Number of retrievable records for '
'this search query: {} '.format(max_records_count)
)
self.max_records_label.setText(
'records from {}.'.format(max_records_count)
)
self.max_records_label.setMaximumSize(self.max_records_label
.sizeHint())
self.num_records_input.setMaximum(max_records_count)
self.retrieve_records_button.setFocus()
def update_retrieval_info(self):
document_count = 0
if self.output_corpus is not None:
document_count = len(self.output_corpus)
self.retrieval_info_label.setText(
'Number of records retrieved: {} '.format(document_count)
)
self.retrieval_info_label.setMaximumSize(
self.retrieval_info_label.sizeHint()
)
def select_email(self, n):
if n < len(self.recent_emails):
email = self.recent_emails[n]
del self.recent_emails[n]
self.recent_emails.insert(0, email)
if len(self.recent_emails) > 0:
self.set_email_list()
def set_email_list(self):
self.email_combo.clear()
for email in self.recent_emails:
self.email_combo.addItem(email)
def select_keywords(self, n):
if n < len(self.recent_keywords):
keywords = self.recent_keywords[n]
del self.recent_keywords[n]
self.recent_keywords.insert(0, keywords)
if len(self.recent_keywords) > 0:
self.set_keyword_list()
def set_keyword_list(self):
self.keyword_combo.clear()
if not self.recent_keywords:
# Sample queries.
self.recent_keywords.append('orchid')
self.recent_keywords.append('hypertension')
self.recent_keywords.append('blood pressure')
self.recent_keywords.append('radiology')
for keywords in self.recent_keywords:
self.keyword_combo.addItem(keywords)
def open_calendar(self, widget):
cal_dlg = CalendarDialog(self, 'Date picker')
if cal_dlg.exec_():
widget.setText(cal_dlg.picked_date)
示例7: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItem [as 别名]
#.........这里部分代码省略.........
self.check_existence()
self.on_open.connect(on_open)
layout = QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
if recent_files is not None:
self.file_combo = QComboBox()
self.file_combo.setMinimumWidth(minimal_width)
self.file_combo.activated[int].connect(self.select)
self.update_combo()
layout.addWidget(self.file_combo)
self.browse_button = QPushButton(browse_label)
self.browse_button.setFocusPolicy(Qt.NoFocus)
self.browse_button.clicked.connect(self.browse)
self.browse_button.setIcon(self.style()
.standardIcon(QStyle.SP_DirOpenIcon))
self.browse_button.setIconSize(QSize(*icon_size))
self.browse_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
layout.addWidget(self.browse_button)
if reload_button:
self.reload_button = QPushButton(reload_label)
self.reload_button.setFocusPolicy(Qt.NoFocus)
self.reload_button.clicked.connect(self.reload)
self.reload_button.setIcon(self.style()
.standardIcon(QStyle.SP_BrowserReload))
self.reload_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.reload_button.setIconSize(QSize(*icon_size))
layout.addWidget(self.reload_button)
def browse(self, start_dir=None):
start_dir = start_dir or self.start_dir
path, _ = QFileDialog().getOpenFileName(self, self.dialog_title,
start_dir, self.dialog_format)
if path and self.recent_files is not None:
if path in self.recent_files:
self.recent_files.remove(path)
self.recent_files.insert(0, path)
self.update_combo()
if path:
self.open_file(path)
def select(self, n):
name = self.file_combo.currentText()
if name == self.empty_file_label:
del self.recent_files[n]
self.recent_files.insert(0, self.empty_file_label)
self.update_combo()
self.open_file(self.empty_file_label)
elif name in self.directory_aliases:
self.browse(self.directory_aliases[name])
elif n < len(self.recent_files):
name = self.recent_files[n]
del self.recent_files[n]
self.recent_files.insert(0, name)
self.update_combo()
self.open_file(self.recent_files[0])
def update_combo(self):
""" Sync combo values to the changes in self.recent_files. """
if self.recent_files is not None:
self.file_combo.clear()
for i, file in enumerate(self.recent_files):
# remove (none) when we have some files and allow_empty=False
if file == self.empty_file_label and \
not self.allow_empty and len(self.recent_files) > 1:
del self.recent_files[i]
else:
self.file_combo.addItem(os.path.split(file)[1])
for alias in self.directory_aliases.keys():
self.file_combo.addItem(alias)
def reload(self):
if self.recent_files:
self.select(0)
def check_existence(self):
if self.recent_files:
to_remove = []
for file in self.recent_files:
doc_path = os.path.join(get_sample_corpora_dir(), file)
exists = any(os.path.exists(f) for f in [file, doc_path])
if file != self.empty_file_label and not exists:
to_remove.append(file)
for file in to_remove:
self.recent_files.remove(file)
def open_file(self, path):
self.on_open.emit(path if path != self.empty_file_label else '')
def get_selected_filename(self):
if self.recent_files:
return self.recent_files[0]
else:
return self.empty_file_label