本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.currentText方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.currentText方法的具体用法?Python QComboBox.currentText怎么用?Python QComboBox.currentText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.currentText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scale
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [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: Randomize
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [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")
示例3: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [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)
示例4: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [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:
#.........这里部分代码省略.........
示例5: OWPubmed
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [as 别名]
#.........这里部分代码省略.........
.sizeHint())
self.pubmed_controls.append(self.num_records_input)
# Download articles.
# Search for records button.
self.retrieve_records_button = gui.button(
self.controlArea,
self,
'Retrieve records',
callback=self.retrieve_records,
tooltip='Retrieves the specified documents.')
self.pubmed_controls.append(self.retrieve_records_button)
# Num. retrieved records info label.
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:
示例6: FileWidget
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import currentText [as 别名]
class FileWidget(QWidget):
on_open = pyqtSignal(str)
# TODO consider removing directory_aliases since it is not used any more
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
# Recent files should also contain `empty_file_label` so
# when (none) is selected this is stored in settings.
self.recent_files = recent_files if recent_files is not None else []
self.directory_aliases = directory_aliases or {}
self.allow_empty = allow_empty
self.empty_file_label = empty_file_label
if self.empty_file_label not in self.recent_files \
and (self.allow_empty or not self.recent_files):
self.recent_files.append(self.empty_file_label)
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)
#.........这里部分代码省略.........