本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.currentIndex方法的具体用法?Python QComboBox.currentIndex怎么用?Python QComboBox.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.currentIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scale
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [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())
示例2: DropDownRadioBooleanFilter
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [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 currentIndex [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: Randomize
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [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")
示例5: FeatureEditor
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [as 别名]
class FeatureEditor(QFrame):
FUNCTIONS = dict(chain([(key, val) for key, val in math.__dict__.items()
if not key.startswith("_")],
[(key, val) for key, val in builtins.__dict__.items()
if key in {"str", "float", "int", "len",
"abs", "max", "min"}]))
featureChanged = Signal()
featureEdited = Signal()
modifiedChanged = Signal(bool)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
layout = QFormLayout(
fieldGrowthPolicy=QFormLayout.ExpandingFieldsGrow
)
layout.setContentsMargins(0, 0, 0, 0)
self.nameedit = QLineEdit(
placeholderText="Name...",
sizePolicy=QSizePolicy(QSizePolicy.Minimum,
QSizePolicy.Fixed)
)
self.expressionedit = QLineEdit(
placeholderText="Expression..."
)
self.attrs_model = itemmodels.VariableListModel(
["Select Feature"], parent=self)
self.attributescb = QComboBox(
minimumContentsLength=16,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon,
sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
)
self.attributescb.setModel(self.attrs_model)
sorted_funcs = sorted(self.FUNCTIONS)
self.funcs_model = itemmodels.PyListModelTooltip()
self.funcs_model.setParent(self)
self.funcs_model[:] = chain(["Select Function"], sorted_funcs)
self.funcs_model.tooltips[:] = chain(
[''],
[self.FUNCTIONS[func].__doc__ for func in sorted_funcs])
self.functionscb = QComboBox(
minimumContentsLength=16,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon,
sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum))
self.functionscb.setModel(self.funcs_model)
hbox = QHBoxLayout()
hbox.addWidget(self.attributescb)
hbox.addWidget(self.functionscb)
layout.addRow(self.nameedit, self.expressionedit)
layout.addRow(self.tr(""), hbox)
self.setLayout(layout)
self.nameedit.editingFinished.connect(self._invalidate)
self.expressionedit.textChanged.connect(self._invalidate)
self.attributescb.currentIndexChanged.connect(self.on_attrs_changed)
self.functionscb.currentIndexChanged.connect(self.on_funcs_changed)
self._modified = False
def setModified(self, modified):
if not type(modified) is bool:
raise TypeError
if self._modified != modified:
self._modified = modified
self.modifiedChanged.emit(modified)
def modified(self):
return self._modified
modified = Property(bool, modified, setModified,
notify=modifiedChanged)
def setEditorData(self, data, domain):
self.nameedit.setText(data.name)
self.expressionedit.setText(data.expression)
self.setModified(False)
self.featureChanged.emit()
self.attrs_model[:] = ["Select Feature"]
if domain is not None and (domain or domain.metas):
self.attrs_model[:] += chain(domain.attributes,
domain.class_vars,
domain.metas)
def editorData(self):
return FeatureDescriptor(name=self.nameedit.text(),
expression=self.nameedit.text())
def _invalidate(self):
self.setModified(True)
self.featureEdited.emit()
self.featureChanged.emit()
#.........这里部分代码省略.........
示例6: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [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 currentIndex [as 别名]
#.........这里部分代码省略.........
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()
else:
value = self.value_double.value()
for index in indexes:
state = (int(Method.Default), (value,))
self.varmodel.setData(index, state, StateRole)
else:
state = (int(method_index), ())
for index in indexes:
self.varmodel.setData(index, state, StateRole)
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()),
DisplayMethodRole)
def _on_value_selected(self):
# The fixed 'Value' in the widget has been changed by the user.
self.variable_button_group.button(Method.Default).setChecked(True)
self.set_method_for_current_selection(Method.Default)
def reset_variable_state(self):
indexes = list(map(self.varmodel.index, range(len(self.varmodel))))
self.set_method_for_indexes(indexes, Method.AsAboveSoBelow)
self.variable_button_group.button(Method.AsAboveSoBelow).setChecked(True)
示例8: OWSql
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentIndex [as 别名]
#.........这里部分代码省略.........
cm.username = self.username or ''
cm.password = self.password or ''
def _credential_manager(self, host, port):
return CredentialManager("SQL Table: {}:{}".format(host, port))
def error(self, id=0, text=""):
super().error(id, text)
err_style = 'QLineEdit {border: 2px solid red;}'
if 'server' in text or 'host' in text:
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))