本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.addItems方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.addItems方法的具体用法?Python QComboBox.addItems怎么用?Python QComboBox.addItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.addItems方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_new_operators
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
def set_new_operators(self, attr_combo, adding_all,
selected_index=None, selected_values=None):
oper_combo = QComboBox()
oper_combo.row = attr_combo.row
oper_combo.attr_combo = attr_combo
var = self.data.domain[attr_combo.currentText()]
oper_combo.addItems(self.operator_names[type(var)])
oper_combo.setCurrentIndex(selected_index or 0)
self.cond_list.setCellWidget(oper_combo.row, 1, oper_combo)
self.set_new_values(oper_combo, adding_all, selected_values)
oper_combo.currentIndexChanged.connect(
lambda _: self.set_new_values(oper_combo, False))
示例2: Scale
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
class Scale(BaseEditor):
NoCentering, CenterMean, CenterMedian = 0, 1, 2
NoScaling, ScaleBySD, ScaleBySpan = 0, 1, 2
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.setLayout(QVBoxLayout())
form = QFormLayout()
self.__centercb = QComboBox()
self.__centercb.addItems(["No Centering", "Center by Mean",
"Center by Median"])
self.__scalecb = QComboBox()
self.__scalecb.addItems(["No scaling", "Scale by SD",
"Scale by span"])
form.addRow("Center:", self.__centercb)
form.addRow("Scale:", self.__scalecb)
self.layout().addLayout(form)
self.__centercb.currentIndexChanged.connect(self.changed)
self.__scalecb.currentIndexChanged.connect(self.changed)
self.__centercb.activated.connect(self.edited)
self.__scalecb.activated.connect(self.edited)
def setParameters(self, params):
center = params.get("center", _Scale.CenteringType.Mean)
scale = params.get("scale", _Scale.ScalingType.Std)
self.__centercb.setCurrentIndex(
enum_to_index(_Scale.CenteringType, center))
self.__scalecb.setCurrentIndex(
enum_to_index(_Scale.ScalingType, scale))
def parameters(self):
return {"center": index_to_enum(_Scale.CenteringType,
self.__centercb.currentIndex()),
"scale": index_to_enum(_Scale.ScalingType,
self.__scalecb.currentIndex())}
@staticmethod
def createinstance(params):
center = params.get("center", _Scale.CenteringType.Mean)
scale = params.get("scale", _Scale.ScalingType.Std)
return _Scale(center=center, scale=scale)
def __repr__(self):
return "{}, {}".format(self.__centercb.currentText(),
self.__scalecb.currentText())
示例3: Randomize
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
class Randomize(BaseEditor):
RandomizeClasses, RandomizeAttributes, RandomizeMetas = _Randomize.Type
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.setLayout(QVBoxLayout())
form = QFormLayout()
self.__rand_type_cb = QComboBox()
self.__rand_type_cb.addItems(["Classes",
"Features",
"Meta data"])
self.__rand_type_cb.currentIndexChanged.connect(self.changed)
self.__rand_type_cb.activated.connect(self.edited)
self.__rand_seed_ch = QCheckBox()
self.__rand_seed_ch.clicked.connect(self.edited)
form.addRow("Randomize:", self.__rand_type_cb)
form.addRow("Replicable shuffling:", self.__rand_seed_ch)
self.layout().addLayout(form)
def setParameters(self, params):
rand_type = params.get("rand_type", Randomize.RandomizeClasses)
self.__rand_type_cb.setCurrentIndex(
enum_to_index(_Randomize.Type, rand_type))
self.__rand_seed_ch.setChecked(params.get("rand_seed", 1) or 0)
def parameters(self):
return {"rand_type": index_to_enum(_Randomize.Type,
self.__rand_type_cb.currentIndex()),
"rand_seed": 1 if self.__rand_seed_ch.isChecked() else None}
@staticmethod
def createinstance(params):
rand_type = params.get("rand_type", Randomize.RandomizeClasses)
rand_seed = params.get("rand_seed", 1)
return _Randomize(rand_type=rand_type, rand_seed=rand_seed)
def __repr__(self):
return "{}, {}".format(self.__rand_type_cb.currentText(),
"Replicable" if self.__rand_seed_ch.isChecked()
else "Not replicable")
示例4: __setupUi
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
#.........这里部分代码省略.........
startup.layout().setContentsMargins(0, 0, 0, 0)
cb_splash = QCheckBox(self.tr("Show splash screen"), self,
objectName="show-splash-screen")
cb_welcome = QCheckBox(self.tr("Show welcome screen"), self,
objectName="show-welcome-screen")
cb_updates = QCheckBox(self.tr("Check for updates"), self,
objectName="check-updates")
self.bind(cb_splash, "checked", "startup/show-splash-screen")
self.bind(cb_welcome, "checked", "startup/show-welcome-screen")
self.bind(cb_updates, "checked", "startup/check-updates")
startup.layout().addWidget(cb_splash)
startup.layout().addWidget(cb_welcome)
startup.layout().addWidget(cb_updates)
form.addRow(self.tr("On startup"), startup)
toolbox = QWidget(self, objectName="toolbox-group")
toolbox.setLayout(QVBoxLayout())
toolbox.layout().setContentsMargins(0, 0, 0, 0)
exclusive = QCheckBox(self.tr("Only one tab can be open at a time"))
self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive")
toolbox.layout().addWidget(exclusive)
form.addRow(self.tr("Tool box"), toolbox)
tab.setLayout(form)
# Output Tab
tab = QWidget()
self.addTab(tab, self.tr("Output"),
toolTip="Output Redirection")
form = QFormLayout()
box = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
combo = QComboBox()
combo.addItems([self.tr("Critical"),
self.tr("Error"),
self.tr("Warn"),
self.tr("Info"),
self.tr("Debug")])
self.bind(combo, "currentIndex", "logging/level")
layout.addWidget(combo)
box.setLayout(layout)
form.addRow(self.tr("Logging"), box)
box = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
cb1 = QCheckBox(self.tr("Open in external browser"),
objectName="open-in-external-browser")
self.bind(cb1, "checked", "help/open-in-external-browser")
layout.addWidget(cb1)
box.setLayout(layout)
form.addRow(self.tr("Help window"), box)
tab.setLayout(form)
# Error Reporting Tab
tab = QWidget()
self.addTab(tab, self.tr("Error Reporting"),
toolTip="Settings related to error reporting")
form = QFormLayout()
line_edit_mid = QLineEdit()
self.bind(line_edit_mid, "text", "error-reporting/machine-id")
form.addRow("Machine ID:", line_edit_mid)
tab.setLayout(form)
# Add-ons Tab
tab = QWidget()
self.addTab(tab, self.tr("Add-ons"),
toolTip="Settings related to add-on installation")
form = QFormLayout()
conda = QWidget(self, objectName="conda-group")
conda.setLayout(QVBoxLayout())
conda.layout().setContentsMargins(0, 0, 0, 0)
cb_conda_install = QCheckBox(self.tr("Install add-ons with conda"), self,
objectName="allow-conda-experimental")
self.bind(cb_conda_install, "checked", "add-ons/allow-conda-experimental")
conda.layout().addWidget(cb_conda_install)
form.addRow(self.tr("Conda"), conda)
tab.setLayout(form)
if self.__macUnified:
# Need some sensible size otherwise mac unified toolbar 'takes'
# the space that should be used for layout of the contents
self.adjustSize()
示例5: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [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)
示例6: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
#.........这里部分代码省略.........
return impute.Model, (method.learner,)
elif isinstance(method, impute.Default):
return impute.Default, (method.default,)
else:
return type(method), None
methods = set(method_key(m) for m in methods)
selected_vars = [self.varmodel[index.row()] for index in indexes]
has_discrete = any(var.is_discrete for var in selected_vars)
fixed_value = None
value_stack_enabled = False
current_value_widget = None
if len(methods) == 1:
method_type, parameters = methods.pop()
for i, m in enumerate(self.methods):
if method_type == type(m):
self.variable_button_group.button(i).setChecked(True)
if method_type is impute.Default:
(fixed_value,) = parameters
elif self.variable_button_group.checkedButton() is not None:
# Uncheck the current button
self.variable_button_group.setExclusive(False)
self.variable_button_group.checkedButton().setChecked(False)
self.variable_button_group.setExclusive(True)
assert self.variable_button_group.checkedButton() is None
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:
value_stack_enabled = True
current_value_widget = self.value_double
elif len(selected_vars) == 1:
value_stack_enabled = True
current_value_widget = self.value_combo
self.value_combo.clear()
self.value_combo.addItems(selected_vars[0].values)
else:
value_stack_enabled = False
current_value_widget = None
self.variable_button_group.button(self.AS_INPUT).setEnabled(False)
self.value_stack.setEnabled(value_stack_enabled)
if current_value_widget is not None:
self.value_stack.setCurrentWidget(current_value_widget)
if fixed_value is not None:
if current_value_widget is self.value_combo:
self.value_combo.setCurrentIndex(fixed_value)
elif current_value_widget is self.value_double:
self.value_double.setValue(fixed_value)
else:
assert 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.row(), None)
elif method_index == OWImpute.AS_INPUT:
current = self.value_stack.currentWidget()
if current is self.value_combo:
value = self.value_combo.currentIndex()
else:
value = self.value_double.value()
for index in indexes:
method = impute.Default(default=value)
self.variable_methods[index.row()] = method
else:
method = self.methods[method_index]
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):
# The fixed 'Value' in the widget has been changed by the user.
self.variable_button_group.button(self.AS_INPUT).setChecked(True)
self.set_method_for_current_selection(self.AS_INPUT)
def reset_variable_methods(self):
indexes = list(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)
示例7: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
#.........这里部分代码省略.........
for m in Method:
if method_type == m:
self.variable_button_group.button(m).setChecked(True)
if method_type == Method.Default:
(fixed_value,) = parameters
elif self.variable_button_group.checkedButton() is not None:
# Uncheck the current button
self.variable_button_group.setExclusive(False)
self.variable_button_group.checkedButton().setChecked(False)
self.variable_button_group.setExclusive(True)
assert self.variable_button_group.checkedButton() is None
# Update variable methods GUI enabled state based on selection.
for method in Method:
# use a default constructed imputer to query support
imputer = self.create_imputer(method)
enabled = all(imputer.supports_variable(var) for var in
selected_vars)
button = self.variable_button_group.button(method)
button.setEnabled(enabled)
# Update the "Value" edit GUI.
if not has_discrete:
# no discrete variables -> allow mass edit for all (continuous vars)
value_stack_enabled = True
current_value_widget = self.value_double
elif len(selected_vars) == 1:
# single discrete var -> enable and fill the values combo
value_stack_enabled = True
current_value_widget = self.value_combo
self.value_combo.clear()
self.value_combo.addItems(selected_vars[0].values)
else:
# mixed type selection -> disable
value_stack_enabled = False
current_value_widget = None
self.variable_button_group.button(Method.Default).setEnabled(False)
self.value_stack.setEnabled(value_stack_enabled)
if current_value_widget is not None:
self.value_stack.setCurrentWidget(current_value_widget)
if fixed_value is not None:
# set current value
if current_value_widget is self.value_combo:
self.value_combo.setCurrentIndex(fixed_value)
elif current_value_widget is self.value_double:
self.value_double.setValue(fixed_value)
else:
assert False
def set_method_for_current_selection(self, method_index):
# type: (Method) -> None
indexes = self.selection.selectedIndexes()
self.set_method_for_indexes(indexes, method_index)
def set_method_for_indexes(self, indexes, method_index):
# type: (List[QModelIndex], Method) -> None
if method_index == Method.AsAboveSoBelow:
for index in indexes:
self.varmodel.setData(index, None, StateRole)
elif method_index == Method.Default:
current = self.value_stack.currentWidget()
if current is self.value_combo:
value = self.value_combo.currentIndex()
示例8: set_new_values
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
def set_new_values(self, oper_combo, adding_all, selected_values=None):
# def remove_children():
# for child in box.children()[1:]:
# box.layout().removeWidget(child)
# child.setParent(None)
def add_textual(contents):
le = gui.lineEdit(box, self, None,
sizePolicy=QSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding))
if contents:
le.setText(contents)
le.setAlignment(Qt.AlignRight)
le.editingFinished.connect(self.conditions_changed)
return le
def add_numeric(contents):
le = add_textual(contents)
le.setValidator(OWSelectRows.QDoubleValidatorEmpty())
return le
def add_datetime(contents):
le = add_textual(contents)
le.setValidator(QRegExpValidator(QRegExp(TimeVariable.REGEX)))
return le
var = self.data.domain[oper_combo.attr_combo.currentText()]
box = self.cond_list.cellWidget(oper_combo.row, 2)
if selected_values is not None:
lc = list(selected_values) + ["", ""]
lc = [str(x) for x in lc[:2]]
else:
lc = ["", ""]
if box and vartype(var) == box.var_type:
lc = self._get_lineedit_contents(box) + lc
oper = oper_combo.currentIndex()
if oper_combo.currentText() == "is defined":
label = QLabel()
label.var_type = vartype(var)
self.cond_list.setCellWidget(oper_combo.row, 2, label)
elif var.is_discrete:
if oper_combo.currentText() == "is one of":
if selected_values:
lc = [x for x in list(selected_values)]
button = DropDownToolButton(self, var, lc)
button.var_type = vartype(var)
self.cond_list.setCellWidget(oper_combo.row, 2, button)
else:
combo = QComboBox()
combo.addItems([""] + var.values)
if lc[0]:
combo.setCurrentIndex(int(lc[0]))
else:
combo.setCurrentIndex(0)
combo.var_type = vartype(var)
self.cond_list.setCellWidget(oper_combo.row, 2, combo)
combo.currentIndexChanged.connect(self.conditions_changed)
else:
box = gui.hBox(self, addToLayout=False)
box.var_type = vartype(var)
self.cond_list.setCellWidget(oper_combo.row, 2, box)
if var.is_continuous:
validator = add_datetime if isinstance(var, TimeVariable) else add_numeric
box.controls = [validator(lc[0])]
if oper > 5:
gui.widgetLabel(box, " and ")
box.controls.append(validator(lc[1]))
elif var.is_string:
box.controls = [add_textual(lc[0])]
if oper in [6, 7]:
gui.widgetLabel(box, " and ")
box.controls.append(add_textual(lc[1]))
else:
box.controls = []
if not adding_all:
self.conditions_changed()
示例9: __setupUi
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import addItems [as 别名]
#.........这里部分代码省略.........
self.bind(cb_splash, "checked", "startup/show-splash-screen")
self.bind(cb_welcome, "checked", "startup/show-welcome-screen")
startup.layout().addWidget(cb_splash)
startup.layout().addWidget(cb_welcome)
form.addRow(self.tr("On startup"), startup)
toolbox = QWidget(self, objectName="toolbox-group")
toolbox.setLayout(QVBoxLayout())
toolbox.layout().setContentsMargins(0, 0, 0, 0)
exclusive = QCheckBox(self.tr("Only one tab can be open at a time"))
self.bind(exclusive, "checked", "mainwindow/toolbox-dock-exclusive")
toolbox.layout().addWidget(exclusive)
form.addRow(self.tr("Tool box"), toolbox)
tab.setLayout(form)
# Output Tab
tab = QWidget()
self.addTab(tab, self.tr("Output"),
toolTip="Output Redirection")
form = QFormLayout()
box = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
combo = QComboBox()
combo.addItems([self.tr("Critical"),
self.tr("Error"),
self.tr("Warn"),
self.tr("Info"),
self.tr("Debug")])
self.bind(combo, "currentIndex", "logging/level")
layout.addWidget(combo)
box.setLayout(layout)
form.addRow(self.tr("Logging"), box)
box = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
cb1 = QCheckBox(self.tr("Open in external browser"),
objectName="open-in-external-browser")
self.bind(cb1, "checked", "help/open-in-external-browser")
layout.addWidget(cb1)
box.setLayout(layout)
form.addRow(self.tr("Help window"), box)
tab.setLayout(form)
# Categories Tab
tab = QWidget()
layout = QVBoxLayout()
view = QListView(
editTriggers=QListView.NoEditTriggers
)
from .. import registry
reg = registry.global_registry()
model = QStandardItemModel()
settings = QSettings()
for cat in reg.categories():