本文整理汇总了Python中qtpy.QtWidgets.QComboBox.addItems方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.addItems方法的具体用法?Python QComboBox.addItems怎么用?Python QComboBox.addItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.addItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _AcquisitionRasterWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class _AcquisitionRasterWidget(_AcquisitionWidget):
def _init_ui(self):
# Widgets
self._cb_raster_mode = QComboBox()
self._cb_raster_mode.addItems([None] + list(_RASTER_MODES))
# Layouts
layout = _AcquisitionWidget._init_ui(self)
layout.addRow('Raster mode', self._cb_raster_mode)
# Singals
self._cb_raster_mode.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _AcquisitionWidget.parameter(self, parameter)
parameter.raster_mode = self._cb_raster_mode.currentText()
return parameter
def setParameter(self, condition):
_AcquisitionWidget.setParameter(self, condition)
self._cb_raster_mode.setCurrentIndex(self._cb_raster_mode.findText(condition.raster_mode))
def setReadOnly(self, state):
_AcquisitionWidget.setReadOnly(self, state)
self._cb_raster_mode.setEnabled(not state)
def isReadOnly(self):
return _AcquisitionWidget.isReadOnly(self) and \
not self._cb_raster_mode.isEnabled()
示例2: populate_unit_layout
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
def populate_unit_layout(self, unit_layout, gui=None):
"""
Populate horizontal layout (living on conversion gui)
with appropriate widgets.
Layouts:
[QComboBox]
:param unit_layout: (QHBoxLayout) Horizontal layout
:param gui: conversion gui
:return: updated unit_layout
"""
unit_str = self._unit.to_string()
options = self._unit.find_equivalent_units(include_prefix_units=True)
options = [i.to_string() for i in options]
options.sort(key=lambda x: x.upper())
if unit_str not in options:
options.append(unit_str)
index = options.index(unit_str)
combo = QComboBox()
# combo.setFixedWidth(200)
combo.addItems(options)
combo.setCurrentIndex(index)
combo.currentIndexChanged.connect(self._update_message)
self.options_combo = combo
unit_layout.addWidget(combo)
self._update_message()
return unit_layout
示例3: buttonwidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class buttonwidget(QWidget):
def __init__(self):
# how connect
super(buttonwidget, self).__init__()
self.grid = QGridLayout()
self.btnConnect = QPushButton("Connect")
self.grid.addWidget(self.btnConnect, 0, 0, 1, 5)
self.btnLock = QPushButton("Lock Cassette")
self.grid.addWidget(self.btnLock, 1, 0, 1, 5)
self.btnPurge = QPushButton("Purge")
self.grid.addWidget(self.btnPurge, 2, 0, 1, 2)
self.cbxPurgeType = QComboBox()
self.cbxPurgeType.addItems(["Normal", "Extended", "Add Conditioner", "Custom"])
self.grid.addWidget(self.cbxPurgeType, 2, 2, 1, 2)
self.txtNumPurge = QLineEdit()
self.grid.addWidget(self.txtNumPurge, 2, 4, 1, 1)
self.btnRecover = QPushButton("Recover")
self.grid.addWidget(self.btnRecover, 3, 0, 1, 5)
self.btnHelp = QPushButton("Help")
self.grid.addWidget(self.btnHelp, 4, 0, 1, 5)
self.setLayout(self.grid)
def updateButtonText(self):
print('updating text')
def EnableDisableButtons(self):
print('enabeling,disabeling buttons')
示例4: _CompositionWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class _CompositionWidget(_ConditionWidget):
def _init_ui(self):
# Widgets
self._cb_unit = QComboBox()
self._cb_unit.addItems(list(_COMPOSITION_UNITS))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow('<i>Unit</i>', self._cb_unit)
# Signals
self._cb_unit.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.unit = self._cb_unit.currentText()
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_unit.setCurrentIndex(self._cb_unit.findText(condition.unit))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_unit.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_unit.isEnabled()
示例5: DetectorSpectrometerWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class DetectorSpectrometerWidget(_DetectorWidget):
def __init__(self, parent=None):
_DetectorWidget.__init__(self, DetectorSpectrometer, parent)
def _init_ui(self):
# Widgets
self._txt_channel_count = NumericalAttributeLineEdit(self.CLASS.channel_count)
self._txt_channel_count.setFormat('{0:d}')
self._wdg_calibration = CalibrationWidget()
self._cb_collection_mode = QComboBox()
self._cb_collection_mode.addItems([None] + list(_COLLECTION_MODES))
# Layout
layout = _DetectorWidget._init_ui(self)
layout.insertRow(0, '<i>Channel count</i>', self._txt_channel_count)
layout.insertRow(1, '<i>Calibration</i>', self._wdg_calibration)
layout.addRow('Collection mode', self._cb_collection_mode)
# Signals
self._txt_channel_count.textEdited.connect(self.edited)
self._wdg_calibration.edited.connect(self.edited)
self._cb_collection_mode.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(1, CalibrationConstant('Quantity', 'm', 0.0))
def parameter(self, parameter=None):
parameter = _DetectorWidget.parameter(self, parameter)
parameter.channel_count = self._txt_channel_count.text()
parameter.calibration = self._wdg_calibration.calibration()
parameter.collection_mode = self._cb_collection_mode.currentText()
return parameter
def setParameter(self, condition):
_DetectorWidget.setParameter(self, condition)
self._txt_channel_count.setText(condition.channel_count)
self._wdg_calibration.setCalibration(condition.calibration)
self._cb_collection_mode.setCurrentIndex(self._cb_collection_mode.findText(condition.collection_mode))
def setReadOnly(self, state):
_DetectorWidget.setReadOnly(self, state)
self._txt_channel_count.setReadOnly(state)
self._wdg_calibration.setReadOnly(state)
self._cb_collection_mode.setEnabled(not state)
def isReadOnly(self):
return _DetectorWidget.isReadOnly(self) and \
self._txt_channel_count.isReadOnly() and \
self._wdg_calibration.isReadOnly() and \
not self._cb_collection_mode.isEnabled()
def hasAcceptableInput(self):
return _DetectorWidget.hasAcceptableInput(self) and \
self._txt_channel_count.hasAcceptableInput() and \
self._wdg_calibration.hasAcceptableInput()
示例6: _create_settings_widgets
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
def _create_settings_widgets(self, settings):
"""
Create a widget for a settings instance, containing label/editor pairs
for each setting in the current level of the passed QSettings instance.
The key of the setting is used as the label, but it's capitalized and
underscores are replaced by spaces.
"""
wrap = QWidget(self)
form = QFormLayout()
hint_lookup = Settings()
for k in settings.allKeys():
if k.startswith("_"):
continue # Ignore hidden keys
v = settings.value(k) # Read value
label = k.capitalize().replace('_', ' ')
abs_key = settings.group() + '/' + k
self._initial_values[abs_key] = v # Store initial value
hints = hint_lookup.get_enum_hint(abs_key) # Check for enum hints
# Create a fitting editor widget based on value type:
if hints is not None:
w = QComboBox()
w.addItems(hints)
w.setEditable(True)
w.setEditText(v)
w.editTextChanged.connect(partial(self._on_setting_changed,
abs_key, w))
elif isinstance(v, str):
if v.lower() in ('true', 'false'):
w = QCheckBox()
w.setChecked(v.lower() == 'true')
w.toggled.connect(partial(self._on_setting_changed,
abs_key, w))
else:
w = QLineEdit(v)
w.textChanged.connect(partial(self._on_setting_changed,
abs_key, w))
elif isinstance(v, int):
w = QSpinBox()
w.setRange(np.iinfo(np.int32).min, np.iinfo(np.int32).max)
w.setValue(v)
w.valueChanged.connect(partial(self._on_setting_changed,
abs_key, w))
elif isinstance(v, float):
w = QDoubleSpinBox()
w.setRange(np.finfo(np.float32).min, np.finfo(np.float32).max)
w.setValue(v)
w.valueChanged.connect(partial(self._on_setting_changed,
abs_key, w))
else:
w = QLineEdit(str(v))
w.textChanged.connect(partial(self._on_setting_changed,
abs_key, w))
self._lut[abs_key] = w
form.addRow(label, w)
wrap.setLayout(form)
return wrap
示例7: NewGrainDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class NewGrainDialog(QDialog):
def __init__(self):
super(NewGrainDialog, self).__init__()
self.setup_ui()
def setup_ui(self):
self.setWindowTitle("Add New Grain")
self.setWindowIcon(QIcon(RESOURCE_PATH + "icons/nakka-finocyl.gif"))
self.resize(400, 400)
controls = QGridLayout()
gb_frame = QGroupBox(self.tr("Grain Design"))
gb_frame.setLayout(controls)
self.cb_grain_type = QComboBox()
# TODO: make grain types auto propagate combobox
self.cb_grain_type.addItems([self.tr("Cylindrical (BATES)")])
controls.addWidget(QLabel(self.tr("Core Shape")), 0, 0)
controls.addWidget(self.cb_grain_type, 0, 1)
self.cb_propellant_type = QComboBox()
self.cb_propellant_type.addItems(app_context.propellant_db.propellant_names())
controls.addWidget(QLabel(self.tr("Propellant Type")), 1, 0)
controls.addWidget(self.cb_propellant_type, 1, 1)
# ok and cancel buttons
btn_ok = QPushButton(self.tr("Apply"))
btn_ok.clicked.connect(self.confirm_grain)
btn_cancel = QPushButton(self.tr("Close"))
btn_cancel.clicked.connect(self.close)
lay_btns = QHBoxLayout()
lay_btns.addWidget(btn_ok)
lay_btns.addWidget(btn_cancel)
frame_btns = QFrame()
frame_btns.setLayout(lay_btns)
# master layout
master = QVBoxLayout()
master.addWidget(gb_frame)
master.addSpacing(10)
master.addWidget(frame_btns)
self.setLayout(master)
def confirm_grain(self):
# grain = OpenBurnGrain.from_widget_factory(...)
pass
示例8: IntensityIDWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class IntensityIDWidget(_ConditionWidget):
def __init__(self, parent=None):
_ConditionWidget.__init__(self, IntensityID, parent)
def _init_ui(self):
print("TEST HUHU")
# Controls
self._cb_type = QComboBox()
self._cb_type.addItems([None] + list(_INTENSITY_TYPES))
self._cb_measure = QComboBox()
self._cb_measure.addItems([None] + list(_INTENSITY_MEASURES))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow("<i>Type</i>", self._cb_type)
layout.addRow("<i>Measure</i>", self._cb_measure)
# Signals
self._cb_type.currentIndexChanged.connect(self.edited)
self._cb_measure.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(None, None)
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.type = self._cb_type
parameter.measure = self._cb_measure
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_type.setCurrentIndex(self._cb_type.findText(condition.type))
self._cb_measure.setCurrentIndex(self._cb_measure.findText(condition.measure))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_type.setEnabled(not state)
self._cb_measure.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_type.isEnabled() and \
not self._cb_measure.isEnabled()
def hasAcceptableInput(self):
return _ConditionWidget.hasAcceptableInput(self)
示例9: LayoutSaveDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class LayoutSaveDialog(QDialog):
""" """
def __init__(self, parent, order):
super(LayoutSaveDialog, self).__init__(parent)
# variables
self._parent = parent
# widgets
self.combo_box = QComboBox(self)
self.combo_box.addItems(order)
self.combo_box.setEditable(True)
self.combo_box.clearEditText()
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel,
Qt.Horizontal, self)
self.button_ok = self.button_box.button(QDialogButtonBox.Ok)
self.button_cancel = self.button_box.button(QDialogButtonBox.Cancel)
# widget setup
self.button_ok.setEnabled(False)
self.dialog_size = QSize(300, 100)
self.setWindowTitle('Save layout as')
self.setModal(True)
self.setMinimumSize(self.dialog_size)
self.setFixedSize(self.dialog_size)
# layouts
self.layout = QVBoxLayout()
self.layout.addWidget(self.combo_box)
self.layout.addWidget(self.button_box)
self.setLayout(self.layout)
# signals and slots
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.close)
self.combo_box.editTextChanged.connect(self.check_text)
def check_text(self, text):
"""Disable empty layout name possibility"""
if to_text_string(text) == u'':
self.button_ok.setEnabled(False)
else:
self.button_ok.setEnabled(True)
示例10: FontLayout
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class FontLayout(QGridLayout):
"""Font selection"""
def __init__(self, value, parent=None):
QGridLayout.__init__(self)
font = tuple_to_qfont(value)
assert font is not None
# Font family
self.family = QFontComboBox(parent)
self.family.setCurrentFont(font)
self.addWidget(self.family, 0, 0, 1, -1)
# Font size
self.size = QComboBox(parent)
self.size.setEditable(True)
sizelist = list(range(6, 12)) + list(range(12, 30, 2)) + [36, 48, 72]
size = font.pointSize()
if size not in sizelist:
sizelist.append(size)
sizelist.sort()
self.size.addItems([str(s) for s in sizelist])
self.size.setCurrentIndex(sizelist.index(size))
self.addWidget(self.size, 1, 0)
# Italic or not
self.italic = QCheckBox(_("Italic"), parent)
self.italic.setChecked(font.italic())
self.addWidget(self.italic, 1, 1)
# Bold or not
self.bold = QCheckBox(_("Bold"), parent)
self.bold.setChecked(font.bold())
self.addWidget(self.bold, 1, 2)
def get_font(self):
font = self.family.currentFont()
font.setItalic(self.italic.isChecked())
font.setBold(self.bold.isChecked())
font.setPointSize(int(self.size.currentText()))
return qfont_to_tuple(font)
示例11: BackgroundIDWidget
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class BackgroundIDWidget(_ConditionWidget):
def __init__(self, parent=None):
_ConditionWidget.__init__(self, BackgroundID, parent)
def _init_ui(self):
# Controls
self._cb_interpolation = QComboBox()
self._cb_interpolation.addItems([None] + list(_BACKGROUND_INTERPOLATIONS))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow("<i>Interpolation</i>", self._cb_interpolation)
# Signals
self._cb_interpolation.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(None)
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.interpolation = self._cb_interpolation
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_interpolation.setCurrentIndex(self._cb_interpolation.findText(condition.interpolation))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_interpolation.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_interpolation.isEnabled()
def hasAcceptableInput(self):
return _ConditionWidget.hasAcceptableInput(self)
示例12: LSPServerEditor
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class LSPServerEditor(QDialog):
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 2084
DEFAULT_CMD = ''
DEFAULT_ARGS = ''
DEFAULT_CONFIGURATION = '{}'
DEFAULT_EXTERNAL = False
HOST_REGEX = re.compile(r'^\w+([.]\w+)*$')
NON_EMPTY_REGEX = re.compile(r'^\S+$')
JSON_VALID = _('JSON valid')
JSON_INVALID = _('JSON invalid')
def __init__(self, parent, language=None, cmd='', host='127.0.0.1',
port=2084, args='', external=False, configurations={},
**kwargs):
super(LSPServerEditor, self).__init__(parent)
self.parent = parent
self.external = external
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.button_ok = bbox.button(QDialogButtonBox.Ok)
self.button_cancel = bbox.button(QDialogButtonBox.Cancel)
self.button_ok.setEnabled(False)
description = _('To create a new configuration, '
'you need to select a programming '
'language, along with a executable '
'name for the server to execute '
'(If the instance is local), '
'and the host and port. Finally, '
'you need to provide the '
'arguments that the server accepts. '
'The placeholders <tt>%(host)s</tt> and '
'<tt>%(port)s</tt> refer to the host '
'and the port, respectively.')
server_settings_description = QLabel(description)
server_settings_description.setWordWrap(True)
lang_label = QLabel(_('Language:'))
self.lang_cb = QComboBox(self)
self.lang_cb.setToolTip(_('Programming language provided '
'by the LSP server'))
self.lang_cb.addItem(_('Select a language'))
self.lang_cb.addItems(LSP_LANGUAGES)
if language is not None:
idx = LSP_LANGUAGES.index(language)
self.lang_cb.setCurrentIndex(idx + 1)
self.button_ok.setEnabled(True)
host_label = QLabel(_('Host:'))
self.host_input = QLineEdit(self)
self.host_input.setToolTip(_('Name of the host that will provide '
'access to the server'))
self.host_input.setText(host)
self.host_input.textChanged.connect(lambda x: self.validate())
port_label = QLabel(_('Port:'))
self.port_spinner = QSpinBox(self)
self.port_spinner.setToolTip(_('TCP port number of the server'))
self.port_spinner.setMinimum(1)
self.port_spinner.setMaximum(60000)
self.port_spinner.setValue(port)
cmd_label = QLabel(_('Command to execute:'))
self.cmd_input = QLineEdit(self)
self.cmd_input.setToolTip(_('Command used to start the '
'LSP server locally'))
self.cmd_input.setText(cmd)
if not external:
self.cmd_input.textChanged.connect(lambda x: self.validate())
args_label = QLabel(_('Server arguments:'))
self.args_input = QLineEdit(self)
self.args_input.setToolTip(_('Additional arguments required to '
'start the server'))
self.args_input.setText(args)
conf_label = QLabel(_('LSP Server Configurations:'))
self.conf_input = CodeEditor(None)
self.conf_input.textChanged.connect(self.validate)
color_scheme = CONF.get('appearance', 'selected')
self.conf_input.setup_editor(
language='JSON',
color_scheme=color_scheme,
wrap=False,
edge_line=True,
highlight_current_line=True,
highlight_current_cell=True,
occurrence_highlighting=True,
auto_unindent=True,
font=get_font(),
filename='config.json')
self.conf_input.setToolTip(_('Additional LSP server configurations '
'set at runtime. JSON required'))
conf_text = '{}'
try:
conf_text = json.dumps(configurations, indent=4, sort_keys=True)
except Exception:
pass
#.........这里部分代码省略.........
示例13: CSVSettingsDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class CSVSettingsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.settings = QSettings()
# decimal
self.decimalLabel = QLabel(self.tr("decimal:"))
self.decimalComboBox = QComboBox()
self.decimalLabel.setBuddy(self.decimalComboBox)
self.decimalComboBox.addItems([",", "."])
# separator
self.separatorLabel = QLabel(self.tr("separator:"))
self.separatorComboBox = QComboBox()
self.separatorLabel.setBuddy(self.separatorComboBox)
self.separatorComboBox.addItem("Semicolon ';'", ';')
self.separatorComboBox.addItem("Comma ','", ',')
self.separatorComboBox.addItem("Tabulator '\\t'", '\t')
self.separatorComboBox.addItem("Whitespace ' '", ' ')
# buttons
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
# layout
layout = QGridLayout()
layout.addWidget(self.decimalLabel, 0, 0)
layout.addWidget(self.decimalComboBox, 0, 1)
layout.addWidget(self.separatorLabel, 1, 0)
layout.addWidget(self.separatorComboBox, 1, 1)
layout.addWidget(self.buttons, 2, 0, 1, 2)
self.setLayout(layout)
# settings
self.decimalComboBox.setCurrentIndex(
self.decimalComboBox.findText(
self.settings.value(DECIMAL_SETTING, ","))
)
self.separatorComboBox.setCurrentIndex(
self.separatorComboBox.findData(
self.settings.value(SEPARATOR_SETTING, ";"))
)
self.setWindowTitle(self.tr("record settings"))
def accept(self):
self.settings.setValue(DECIMAL_SETTING, self.decimal)
self.settings.setValue(SEPARATOR_SETTING, self.separator)
super().accept()
# decimal property
@property
def decimal(self):
return self.decimalComboBox.currentText()
# seperator property
@property
def separator(self):
return self.separatorComboBox.itemData(
self.separatorComboBox.currentIndex())
示例14: setup_and_check
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
def setup_and_check(self, data, title='', readonly=False,
xlabels=None, ylabels=None):
"""
Setup ArrayEditor:
return False if data is not supported, True otherwise
"""
self.data = data
is_record_array = data.dtype.names is not None
is_masked_array = isinstance(data, np.ma.MaskedArray)
if data.size == 0:
self.error(_("Array is empty"))
return False
if data.ndim > 3:
self.error(_("Arrays with more than 3 dimensions are not supported"))
return False
if xlabels is not None and len(xlabels) != self.data.shape[1]:
self.error(_("The 'xlabels' argument length do no match array "
"column number"))
return False
if ylabels is not None and len(ylabels) != self.data.shape[0]:
self.error(_("The 'ylabels' argument length do no match array row "
"number"))
return False
if not is_record_array:
dtn = data.dtype.name
if dtn not in SUPPORTED_FORMATS and not dtn.startswith('str') \
and not dtn.startswith('unicode'):
arr = _("%s arrays") % data.dtype.name
self.error(_("%s are currently not supported") % arr)
return False
self.layout = QGridLayout()
self.setLayout(self.layout)
self.setWindowIcon(ima.icon('arredit'))
if title:
title = to_text_string(title) + " - " + _("NumPy array")
else:
title = _("Array editor")
if readonly:
title += ' (' + _('read only') + ')'
self.setWindowTitle(title)
self.resize(600, 500)
# Stack widget
self.stack = QStackedWidget(self)
if is_record_array:
for name in data.dtype.names:
self.stack.addWidget(ArrayEditorWidget(self, data[name],
readonly, xlabels, ylabels))
elif is_masked_array:
self.stack.addWidget(ArrayEditorWidget(self, data, readonly,
xlabels, ylabels))
self.stack.addWidget(ArrayEditorWidget(self, data.data, readonly,
xlabels, ylabels))
self.stack.addWidget(ArrayEditorWidget(self, data.mask, readonly,
xlabels, ylabels))
elif data.ndim == 3:
pass
else:
self.stack.addWidget(ArrayEditorWidget(self, data, readonly,
xlabels, ylabels))
self.arraywidget = self.stack.currentWidget()
self.stack.currentChanged.connect(self.current_widget_changed)
self.layout.addWidget(self.stack, 1, 0)
# Buttons configuration
btn_layout = QHBoxLayout()
if is_record_array or is_masked_array or data.ndim == 3:
if is_record_array:
btn_layout.addWidget(QLabel(_("Record array fields:")))
names = []
for name in data.dtype.names:
field = data.dtype.fields[name]
text = name
if len(field) >= 3:
title = field[2]
if not is_text_string(title):
title = repr(title)
text += ' - '+title
names.append(text)
else:
names = [_('Masked data'), _('Data'), _('Mask')]
if data.ndim == 3:
# QSpinBox
self.index_spin = QSpinBox(self, keyboardTracking=False)
self.index_spin.valueChanged.connect(self.change_active_widget)
# QComboBox
names = [str(i) for i in range(3)]
ra_combo = QComboBox(self)
ra_combo.addItems(names)
ra_combo.currentIndexChanged.connect(self.current_dim_changed)
# Adding the widgets to layout
label = QLabel(_("Axis:"))
btn_layout.addWidget(label)
btn_layout.addWidget(ra_combo)
self.shape_label = QLabel()
btn_layout.addWidget(self.shape_label)
label = QLabel(_("Index:"))
btn_layout.addWidget(label)
btn_layout.addWidget(self.index_spin)
#.........这里部分代码省略.........
示例15: CondaPackageActionDialog
# 需要导入模块: from qtpy.QtWidgets import QComboBox [as 别名]
# 或者: from qtpy.QtWidgets.QComboBox import addItems [as 别名]
class CondaPackageActionDialog(QDialog):
""" """
def __init__(self, parent, prefix, name, action, version, versions, packages_sizes, active_channels):
super(CondaPackageActionDialog, self).__init__(parent)
self._parent = parent
self._prefix = prefix
self._version_text = None
self._name = name
self._dependencies_dic = {}
self._active_channels = active_channels
self._packages_sizes = packages_sizes
self.api = ManagerAPI()
# Widgets
self.label = QLabel(self)
self.combobox_version = QComboBox()
self.label_version = QLabel(self)
self.widget_version = None
self.table_dependencies = None
self.checkbox = QCheckBox(_("Install dependencies (recommended)"))
self.bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
self.button_ok = self.bbox.button(QDialogButtonBox.Ok)
self.button_cancel = self.bbox.button(QDialogButtonBox.Cancel)
self.button_cancel.setDefault(True)
self.button_cancel.setAutoDefault(True)
dialog_size = QSize(300, 90)
# Helper variable values
action_title = {
C.ACTION_UPGRADE: _("Upgrade package"),
C.ACTION_DOWNGRADE: _("Downgrade package"),
C.ACTION_REMOVE: _("Remove package"),
C.ACTION_INSTALL: _("Install package"),
}
# FIXME: There is a bug, a package installed by anaconda has version
# astropy 0.4 and the linked list 0.4 but the available versions
# in the json file do not include 0.4 but 0.4rc1... so...
# temporal fix is to check if inside list otherwise show full list
if action == C.ACTION_UPGRADE:
if version in versions:
index = versions.index(version)
combo_versions = versions[index + 1 :]
else:
versions = versions
elif action == C.ACTION_DOWNGRADE:
if version in versions:
index = versions.index(version)
combo_versions = versions[:index]
else:
versions = versions
elif action == C.ACTION_REMOVE:
combo_versions = [version]
self.combobox_version.setEnabled(False)
elif action == C.ACTION_INSTALL:
combo_versions = versions
# Reverse order for combobox
combo_versions = list(reversed(combo_versions))
if len(versions) == 1:
if action == C.ACTION_REMOVE:
labeltext = _("Package version to remove:")
else:
labeltext = _("Package version available:")
self.label_version.setText(combo_versions[0])
self.widget_version = self.label_version
else:
labeltext = _("Select package version:")
self.combobox_version.addItems(combo_versions)
self.widget_version = self.combobox_version
self.label.setText(labeltext)
self.label_version.setAlignment(Qt.AlignLeft)
self.table_dependencies = QWidget(self)
layout = QVBoxLayout()
version_layout = QHBoxLayout()
version_layout.addWidget(self.label)
version_layout.addStretch()
version_layout.addWidget(self.widget_version)
layout.addLayout(version_layout)
self.widgets = [self.checkbox, self.button_ok, self.widget_version, self.table_dependencies]
# Create a Table
if action in [C.ACTION_INSTALL, C.ACTION_UPGRADE, C.ACTION_DOWNGRADE]:
table = QTableView(self)
dialog_size = QSize(dialog_size.width() + 40, 300)
self.table_dependencies = table
layout.addWidget(self.checkbox)
self.checkbox.setChecked(True)
self._changed_version(versions[0])
table.setSelectionBehavior(QAbstractItemView.SelectRows)
#.........这里部分代码省略.........