本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.clear方法的具体用法?Python QComboBox.clear怎么用?Python QComboBox.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.clear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DropDownRadioBooleanFilter
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [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)
示例2: DropDownIdListFilter
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [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)
示例3: RecentPathsWComboMixin
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [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()
示例4: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
self.send("Data", data)
self.modified = False
def send_report(self):
specific = []
for i, var in enumerate(self.varmodel):
method = self.variable_methods.get(i, None)
if method is not None:
specific.append("{} ({})".format(var.name, str(method)))
default = self.default_method.name
if specific:
self.report_items((
("Default method", default),
("Specific imputers", ", ".join(specific))
))
else:
self.report_items((("Method", default),))
def _on_var_selection_changed(self):
indexes = self.selection.selectedIndexes()
methods = set(self.get_method_for_column(i.row()).name for i in indexes)
selected_vars = [self.varmodel[index.row()] for index in indexes]
has_discrete = any(var.is_discrete for var in selected_vars)
if len(methods) == 1:
method = methods.pop()
for i, m in enumerate(self.METHODS):
if method == m.name:
self.variable_button_group.button(i).setChecked(True)
elif self.variable_button_group.checkedButton() is not None:
self.variable_button_group.setExclusive(False)
self.variable_button_group.checkedButton().setChecked(False)
self.variable_button_group.setExclusive(True)
for method, button in zip(self.METHODS,
self.variable_button_group.buttons()):
enabled = all(method.supports_variable(var) for var in
selected_vars)
button.setEnabled(enabled)
if not has_discrete:
self.value_stack.setEnabled(True)
self.value_stack.setCurrentWidget(self.value_double)
self._on_value_changed()
elif len(selected_vars) == 1:
self.value_stack.setEnabled(True)
self.value_stack.setCurrentWidget(self.value_combo)
self.value_combo.clear()
self.value_combo.addItems(selected_vars[0].values)
self._on_value_changed()
else:
self.variable_button_group.button(self.AS_INPUT).setEnabled(False)
self.value_stack.setEnabled(False)
def set_method_for_current_selection(self, method_index):
indexes = self.selection.selectedIndexes()
self.set_method_for_indexes(indexes, method_index)
def set_method_for_indexes(self, indexes, method_index):
if method_index == self.DEFAULT:
for index in indexes:
self.variable_methods.pop(index, None)
else:
method = self.METHODS[method_index].copy()
for index in indexes:
self.variable_methods[index.row()] = method
self.update_varview(indexes)
self._invalidate()
def update_varview(self, indexes=None):
if indexes is None:
indexes = map(self.varmodel.index, range(len(self.varmodel)))
for index in indexes:
self.varmodel.setData(index, self.get_method_for_column(index.row()), Qt.UserRole)
def _on_value_selected(self):
self.variable_button_group.button(self.AS_INPUT).setChecked(True)
self._on_value_changed()
def _on_value_changed(self):
widget = self.value_stack.currentWidget()
if widget is self.value_combo:
value = self.value_combo.currentText()
else:
value = self.value_double.value()
self.default_value = value
self.METHODS[self.AS_INPUT].default = value
index = self.variable_button_group.checkedId()
if index == self.AS_INPUT:
self.set_method_for_current_selection(index)
def reset_variable_methods(self):
indexes = map(self.varmodel.index, range(len(self.varmodel)))
self.set_method_for_indexes(indexes, self.DEFAULT)
self.variable_button_group.button(self.DEFAULT).setChecked(True)
示例5: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
imputer = self.methods[self.MODEL_BASED_IMPUTER]
imputer.learner = self.learner
button = self.default_button_group.button(self.MODEL_BASED_IMPUTER)
button.setText(imputer.name)
variable_button = self.variable_button_group.button(self.MODEL_BASED_IMPUTER)
variable_button.setText(imputer.name)
if learner is not None:
self.default_method_index = self.MODEL_BASED_IMPUTER
self.update_varview()
self.commit()
def get_method_for_column(self, column_index):
"""Returns the imputation method for column by its index.
"""
if not isinstance(column_index, int):
column_index = column_index.row()
return self.variable_methods.get(column_index,
self.methods[self.DEFAULT])
def _invalidate(self):
self.modified = True
if self.__task is not None:
self.cancel()
self.commit()
def commit(self):
self.cancel()
self.warning()
self.Error.imputation_failed.clear()
self.Error.model_based_imputer_sparse.clear()
if self.data is None or len(self.data) == 0 or len(self.varmodel) == 0:
self.Outputs.data.send(self.data)
self.modified = False
return
data = self.data
impute_state = [
(i, var, self.variable_methods.get(i, self.default_method))
for i, var in enumerate(self.varmodel)
]
def impute_one(method, var, data):
# type: (impute.BaseImputeMethod, Variable, Table) -> Any
if isinstance(method, impute.Model) and data.is_sparse():
raise SparseNotSupported()
elif isinstance(method, impute.DropInstances):
return RowMask(method(data, var))
elif not method.supports_variable(var):
raise VariableNotSupported(var)
else:
return method(data, var)
futures = []
for _, var, method in impute_state:
f = self.executor.submit(
impute_one, copy.deepcopy(method), var, data)
futures.append(f)
w = qconcurrent.FutureSetWatcher(futures)
w.doneAll.connect(self.__commit_finish)
示例6: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
button = self.default_button_group.button(Method.Model)
button.setText(imputer.name)
variable_button = self.variable_button_group.button(Method.Model)
variable_button.setText(imputer.name)
if learner is not None:
self.default_method_index = Method.Model
self.update_varview()
self.commit()
def get_method_for_column(self, column_index):
# type: (int) -> impute.BaseImputeMethod
"""
Return the imputation method for column by its index.
"""
assert 0 <= column_index < len(self.varmodel)
idx = self.varmodel.index(column_index, 0)
state = idx.data(StateRole)
if state is None:
state = (Method.AsAboveSoBelow, ())
return self.create_imputer(state[0], *state[1])
def _invalidate(self):
self.modified = True
if self.__task is not None:
self.cancel()
self.commit()
def commit(self):
self.cancel()
self.warning()
self.Error.imputation_failed.clear()
self.Error.model_based_imputer_sparse.clear()
if self.data is None or len(self.data) == 0 or len(self.varmodel) == 0:
self.Outputs.data.send(self.data)
self.modified = False
return
data = self.data
impute_state = [
(i, var, self.get_method_for_column(i))
for i, var in enumerate(self.varmodel)
]
# normalize to the effective method bypasing AsDefault
impute_state = [
(i, var, m.method if isinstance(m, AsDefault) else m)
for i, var, m in impute_state
]
def impute_one(method, var, data):
# type: (impute.BaseImputeMethod, Variable, Table) -> Any
if isinstance(method, impute.Model) and data.is_sparse():
raise SparseNotSupported()
elif isinstance(method, impute.DropInstances):
return RowMask(method(data, var))
elif not method.supports_variable(var):
raise VariableNotSupported(var)
else:
return method(data, var)
futures = []
for _, var, method in impute_state:
f = self.executor.submit(
示例7: OWSql
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
self.servertext.setStyleSheet(err_style)
else:
self.servertext.setStyleSheet('')
if 'role' in text:
self.usernametext.setStyleSheet(err_style)
else:
self.usernametext.setStyleSheet('')
if 'database' in text:
self.databasetext.setStyleSheet(err_style)
else:
self.databasetext.setStyleSheet('')
def _parse_host_port(self):
hostport = self.servertext.text().split(':')
self.host = hostport[0]
self.port = hostport[1] if len(hostport) == 2 else None
def connect(self):
self._parse_host_port()
self.database, _, self.schema = self.databasetext.text().partition('/')
self.username = self.usernametext.text() or None
self.password = self.passwordtext.text() or None
try:
if self.backendcombo.currentIndex() < 0:
return
backend = self.backends[self.backendcombo.currentIndex()]
self.backend = backend(dict(
host=self.host,
port=self.port,
database=self.database,
user=self.username,
password=self.password
))
self.Error.connection.clear()
self._save_credentials()
self.database_desc = OrderedDict((
("Host", self.host), ("Port", self.port),
("Database", self.database), ("User name", self.username)
))
self.refresh_tables()
except BackendError as err:
error = str(err).split('\n')[0]
self.Error.connection(error)
self.database_desc = self.data_desc_table = None
self.tablecombo.clear()
def refresh_tables(self):
self.tables.clear()
self.Error.missing_extension.clear()
if self.backend is None:
self.data_desc_table = None
return
self.tables.append("Select a table")
self.tables.append("Custom SQL")
self.tables.extend(self.backend.list_tables(self.schema))
# Called on tablecombo selection change:
def select_table(self):
curIdx = self.tablecombo.currentIndex()
if self.tablecombo.itemText(curIdx) != "Custom SQL":
self.custom_sql.setVisible(False)
return self.open_table()
else:
self.custom_sql.setVisible(True)
self.data_desc_table = None
示例8: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [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:
#.........这里部分代码省略.........
示例9: OWPubmed
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
self.retrieval_info_label = gui.label(
self.controlArea,
self,
'Number of records retrieved: /')
# Load the most recent emails.
self.set_email_list()
# Load the most recent queries.
self.set_keyword_list()
# Check the email and enable controls accordingly.
if self.recent_emails:
email = self.recent_emails[0]
self.email_is_valid = validate_email(email)
self.enable_controls()
def sync_email(self):
email = self.email_combo.currentText()
self.email_is_valid = validate_email(email)
self.enable_controls()
def enable_controls(self):
# Enable/disable controls accordingly.
for control in self.pubmed_controls:
control.setEnabled(self.email_is_valid)
if self.pubmed_api is None or self.pubmed_api.search_record_count == 0:
self.retrieve_records_button.setEnabled(False)
if not self.email_is_valid:
self.email_combo.setFocus()
def run_search(self):
self.Error.clear()
self.Warning.clear()
self.run_search_button.setEnabled(False)
self.retrieve_records_button.setEnabled(False)
# Add the email to history.
email = self.email_combo.currentText()
if email not in self.recent_emails:
self.recent_emails.insert(0, email)
# Check if the PubMed object is present.
if self.pubmed_api is None:
self.pubmed_api = Pubmed(
email=email,
progress_callback=self.api_progress_callback,
error_callback=self.api_error_callback,
)
if self.search_tabs.currentIndex() == 0:
# Get query parameters.
terms = self.keyword_combo.currentText().split()
authors = self.author_input.text().split()
error = self.pubmed_api._search_for_records(
terms, authors, self.pub_date_from, self.pub_date_to
)
if error is not None:
self.Error.api_error(str(error))
return
if self.keyword_combo.currentText() not in self.recent_keywords:
self.recent_keywords.insert(
0,
示例10: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import clear [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