本文整理汇总了Python中AnyQt.QtWidgets.QComboBox类的典型用法代码示例。如果您正苦于以下问题:Python QComboBox类的具体用法?Python QComboBox怎么用?Python QComboBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QComboBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createEditor
def createEditor(self, parent, _QStyleOptionViewItem, index):
combo = QComboBox(parent)
attr = index.model()[index.row()][0]
combo.setModel(self._combo_continuous_model if attr.is_continuous else
self._combo_discrete_model if attr.is_discrete else
self._combo_string_model)
return combo
示例2: __init__
def __init__(self, tree, dataset, master, parent=None):
QComboBox.__init__(self, parent)
Control.__init__(self, tree, dataset, master)
self.setSelectionMode(QListView.ExtendedSelection)
model = QStringListModel(self)
self.setModel(model)
self.setOptions(tree.subelements_top("Option"))
示例3: __init__
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
示例4: DropDownRadioBooleanFilter
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)
示例5: RecentPathsWComboMixin
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)
def workflowEnvChanged(self, key, value, oldvalue):
super().workflowEnvChanged(key, value, oldvalue)
if key == "basedir":
self.set_file_list()
示例6: __init__
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)
示例7: add_row
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)
示例8: set_new_operators
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))
示例9: DropDownIdListFilter
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)
示例10: Randomize
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")
示例11: __init__
def __init__(self):
super().__init__()
self.data = None # type: Optional[Orange.data.Table]
self.learner = None # type: Optional[Learner]
self.default_learner = SimpleTreeLearner()
self.modified = False
self.executor = qconcurrent.ThreadExecutor(self)
self.__task = None
main_layout = QVBoxLayout()
main_layout.setContentsMargins(10, 10, 10, 10)
self.controlArea.layout().addLayout(main_layout)
box = QGroupBox(title=self.tr("Default Method"), flat=False)
box_layout = QVBoxLayout(box)
main_layout.addWidget(box)
button_group = QButtonGroup()
button_group.buttonClicked[int].connect(self.set_default_method)
for method, _ in list(METHODS.items())[1:-1]:
imputer = self.create_imputer(method)
button = QRadioButton(imputer.name)
button.setChecked(method == self.default_method_index)
button_group.addButton(button, method)
box_layout.addWidget(button)
self.default_button_group = button_group
box = QGroupBox(title=self.tr("Individual Attribute Settings"),
flat=False)
main_layout.addWidget(box)
horizontal_layout = QHBoxLayout(box)
main_layout.addWidget(box)
self.varview = QListView(
selectionMode=QListView.ExtendedSelection,
uniformItemSizes=True
)
self.varview.setItemDelegate(DisplayFormatDelegate())
self.varmodel = itemmodels.VariableListModel()
self.varview.setModel(self.varmodel)
self.varview.selectionModel().selectionChanged.connect(
self._on_var_selection_changed
)
self.selection = self.varview.selectionModel()
horizontal_layout.addWidget(self.varview)
method_layout = QVBoxLayout()
horizontal_layout.addLayout(method_layout)
button_group = QButtonGroup()
for method in Method:
imputer = self.create_imputer(method)
button = QRadioButton(text=imputer.name)
button_group.addButton(button, method)
method_layout.addWidget(button)
self.value_combo = QComboBox(
minimumContentsLength=8,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength,
activated=self._on_value_selected
)
self.value_double = QDoubleSpinBox(
editingFinished=self._on_value_selected,
minimum=-1000., maximum=1000., singleStep=.1, decimals=3,
)
self.value_stack = value_stack = QStackedWidget()
value_stack.addWidget(self.value_combo)
value_stack.addWidget(self.value_double)
method_layout.addWidget(value_stack)
button_group.buttonClicked[int].connect(
self.set_method_for_current_selection
)
method_layout.addStretch(2)
reset_button = QPushButton(
"Restore All to Default", checked=False, checkable=False,
clicked=self.reset_variable_state, default=False,
autoDefault=False)
method_layout.addWidget(reset_button)
self.variable_button_group = button_group
box = gui.auto_commit(
self.controlArea, self, "autocommit", "Apply",
orientation=Qt.Horizontal,
checkbox_label="Apply automatically")
box.button.setFixedWidth(180)
box.layout().insertStretch(0)
示例12: __init__
def __init__(self):
super().__init__()
self.file_combo = \
QComboBox(self, sizeAdjustPolicy=QComboBox.AdjustToContents)
示例13: set_new_values
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()
示例14: OWSql
class OWSql(OWWidget):
name = "SQL Table"
id = "orange.widgets.data.sql"
description = "Load data set from SQL."
icon = "icons/SQLTable.svg"
priority = 30
category = "Data"
keywords = ["data", "file", "load", "read", "SQL"]
class Outputs:
data = Output("Data", Table, doc="Attribute-valued data set read from the input file.")
settings_version = 2
want_main_area = False
resizing_enabled = False
host = Setting(None)
port = Setting(None)
database = Setting(None)
schema = Setting(None)
username = ""
password = ""
table = Setting(None)
sql = Setting("")
guess_values = Setting(True)
download = Setting(False)
materialize = Setting(False)
materialize_table_name = Setting("")
class Information(OWWidget.Information):
data_sampled = Msg("Data description was generated from a sample.")
class Error(OWWidget.Error):
connection = Msg("{}")
no_backends = Msg("Please install a backend to use this widget")
missing_extension = Msg("Database is missing extension{}: {}")
def __init__(self):
super().__init__()
self.backend = None
self.data_desc_table = None
self.database_desc = None
vbox = gui.vBox(self.controlArea, "Server", addSpace=True)
box = gui.vBox(vbox)
self.backends = BackendModel(Backend.available_backends())
self.backendcombo = QComboBox(box)
if len(self.backends):
self.backendcombo.setModel(self.backends)
else:
self.Error.no_backends()
box.setEnabled(False)
box.layout().addWidget(self.backendcombo)
self.servertext = QLineEdit(box)
self.servertext.setPlaceholderText('Server')
self.servertext.setToolTip('Server')
self.servertext.editingFinished.connect(self._load_credentials)
if self.host:
self.servertext.setText(self.host if not self.port else
'{}:{}'.format(self.host, self.port))
box.layout().addWidget(self.servertext)
self.databasetext = QLineEdit(box)
self.databasetext.setPlaceholderText('Database[/Schema]')
self.databasetext.setToolTip('Database or optionally Database/Schema')
if self.database:
self.databasetext.setText(
self.database if not self.schema else
'{}/{}'.format(self.database, self.schema))
box.layout().addWidget(self.databasetext)
self.usernametext = QLineEdit(box)
self.usernametext.setPlaceholderText('Username')
self.usernametext.setToolTip('Username')
box.layout().addWidget(self.usernametext)
self.passwordtext = QLineEdit(box)
self.passwordtext.setPlaceholderText('Password')
self.passwordtext.setToolTip('Password')
self.passwordtext.setEchoMode(QLineEdit.Password)
box.layout().addWidget(self.passwordtext)
self._load_credentials()
self.tables = TableModel()
tables = gui.hBox(box)
self.tablecombo = QComboBox(
minimumContentsLength=35,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength
)
self.tablecombo.setModel(self.tables)
self.tablecombo.setToolTip('table')
tables.layout().addWidget(self.tablecombo)
self.connect()
#.........这里部分代码省略.........
示例15: Scale
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())