本文整理汇总了Python中PySide.QtGui.QComboBox.model方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.model方法的具体用法?Python QComboBox.model怎么用?Python QComboBox.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QComboBox
的用法示例。
在下文中一共展示了QComboBox.model方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _OptionsSelector
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
class _OptionsSelector(QDialog):
def __init__(self, list_options, parent=None):
QDialog.__init__(self, parent)
# Variables
model = _AvailableOptionsListModel()
for options in list_options:
model.addOptions(options)
# Widgets
lbltext = QLabel('Select the options to import')
self._combobox = QComboBox()
self._combobox.setModel(model)
buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
# Layouts
layout = QVBoxLayout()
layout.addWidget(lbltext)
layout.addWidget(self._combobox)
layout.addWidget(buttons)
self.setLayout(layout)
# Signals
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
def options(self):
return self._combobox.model().options(self._combobox.currentIndex())
示例2: LimitWizardPage
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
#.........这里部分代码省略.........
def insert(self, index, limit):
self.insertRows(index)
self.setData(self.createIndex(index, 0), limit)
def remove(self, limit):
index = self._limits.index(limit)
self.removeRows(index)
def modify(self, index, limit):
self.setData(self.createIndex(index, 0), limit)
def clear(self):
self.removeRows(0, self.rowCount())
def limits(self):
limits = set(self._limits)
limits.discard(None)
return limits
def limit(self, index):
return self._limits[index.row()]
class _LimitTableDelegate(QItemDelegate):
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
return None
def setEditorData(self, editor, index):
pass
def setModelData(self, editor, model, index):
return None
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Limit')
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._LimitTableModel()
# Widgets
self._cb_limit = QComboBox()
self._cb_limit.setModel(self._LimitComboBoxModel())
btn_limit_add = QPushButton()
btn_limit_add.setIcon(getIcon("list-add"))
self._tbl_limit = QTableView()
self._tbl_limit.setModel(tbl_model)
self._tbl_limit.setItemDelegate(self._LimitTableDelegate())
header = self._tbl_limit.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
header.hide()
policy = self._tbl_limit.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_limit.setSizePolicy(policy)
tlb_limit = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_limit.addWidget(spacer)
示例3: _PhotonDistributionResultOptionsToolItem
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
class _PhotonDistributionResultOptionsToolItem(_ResultToolItem):
def _initUI(self):
# Variables
result = self.result()
transitions = sorted(result.iter_transitions())
transition0 = transitions[0]
model = _TransitionListModel(transitions)
# Widgets
self._chk_errorbar = QCheckBox("Show error bars")
self._chk_errorbar.setChecked(True)
self._cb_transition = QComboBox()
self._cb_transition.setModel(model)
self._cb_transition.setCurrentIndex(0)
self._chk_pg = QCheckBox("No absorption, no fluorescence")
state = result.exists(transition0, True, False, False, False)
self._chk_pg.setEnabled(state)
self._chk_pg.setChecked(state)
self._chk_eg = QCheckBox("With absorption, no fluorescence")
state = result.exists(transition0, True, True, False, False)
self._chk_eg.setEnabled(state)
self._chk_eg.setChecked(state)
self._chk_pt = QCheckBox("No absorption, with fluorescence")
state = result.exists(transition0, True, False, True, True)
self._chk_pt.setEnabled(state)
self._chk_pt.setChecked(state)
self._chk_et = QCheckBox("With absorption, with fluorescence")
state = result.exists(transition0, True, True, True, True)
self._chk_et.setEnabled(state)
self._chk_et.setChecked(state)
# Layouts
layout = _ResultToolItem._initUI(self)
layout.addRow(self._chk_errorbar)
layout.addRow("Transition", self._cb_transition)
boxlayout = QVBoxLayout()
boxlayout.addWidget(self._chk_pg)
boxlayout.addWidget(self._chk_eg)
boxlayout.addWidget(self._chk_pt)
boxlayout.addWidget(self._chk_et)
box_generated = QGroupBox("Curves")
box_generated.setLayout(boxlayout)
layout.addRow(box_generated)
# Signals
self._cb_transition.currentIndexChanged.connect(self._onTransitionChanged)
self._chk_pg.stateChanged.connect(self.stateChanged)
self._chk_eg.stateChanged.connect(self.stateChanged)
self._chk_pt.stateChanged.connect(self.stateChanged)
self._chk_et.stateChanged.connect(self.stateChanged)
self._chk_errorbar.stateChanged.connect(self.stateChanged)
return layout
def _onTransitionChanged(self):
result = self.result()
index = self._cb_transition.currentIndex()
transition = self._cb_transition.model().transition(index)
self._chk_pg.setEnabled(result.exists(transition, True, False, False, False))
self._chk_eg.setEnabled(result.exists(transition, True, True, False, False))
self._chk_pt.setEnabled(result.exists(transition, True, False, True, True))
self._chk_et.setEnabled(result.exists(transition, True, True, True, True))
self.stateChanged.emit()
def transition(self):
index = self._cb_transition.currentIndex()
return self._cb_transition.model().transition(index)
def showConditions(self):
return (
self._chk_pg.isChecked() and self._chk_pg.isEnabled(),
self._chk_eg.isChecked() and self._chk_eg.isEnabled(),
self._chk_pt.isChecked() and self._chk_pt.isEnabled(),
self._chk_et.isChecked() and self._chk_et.isEnabled(),
)
def showErrorbar(self):
return self._chk_errorbar.isChecked()
示例4: __init__
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
def __init__(self, results, result_key,
parameter_getters, x_parameter_name,
series=None, parent=None):
QDialog.__init__(self, parent)
# Variables
self._results = results
self._result_key = result_key
self._parameter_getters = parameter_getters
options = results.options
# Widgets
self._txt_name = QLineEdit()
self._cb_parameters = {}
for name, getter in parameter_getters.items():
if name == x_parameter_name:
continue
combobox = QComboBox()
values = np.array(getter(options), ndmin=1)
combobox.setModel(_ValuesModel(values))
self._cb_parameters[name] = combobox
self._cb_summary_key = QComboBox()
self._cb_summary_key.setModel(_ValuesModel([]))
buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
# Layouts
layout = QFormLayout()
if sys.platform == 'darwin': # Fix for Mac OS
layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
layout.addRow('Name', self._txt_name)
for name, combobox in self._cb_parameters.items():
layout.addRow(name, combobox)
layout.addRow('Summary variable', self._cb_summary_key)
layout.addRow(buttons)
self.setLayout(layout)
# Signals
buttons.accepted.connect(self._onOk)
buttons.rejected.connect(self.reject)
for combobox in self._cb_parameters.values():
combobox.currentIndexChanged.connect(self._onParameterChanged)
# Defaults
if series is not None:
self._txt_name.setText(series.name)
for name, _, value in series.conditions:
combobox = self._cb_parameters[name]
index = combobox.model().valueIndex(value)
combobox.setCurrentIndex(index)
self._onParameterChanged()
index = self._cb_summary_key.model().valueIndex(series.summary_key)
self._cb_summary_key.setCurrentIndex(index)
else:
self._onParameterChanged()
示例5: _SeriesDialog
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
class _SeriesDialog(QDialog):
def __init__(self, results, result_key,
parameter_getters, x_parameter_name,
series=None, parent=None):
QDialog.__init__(self, parent)
# Variables
self._results = results
self._result_key = result_key
self._parameter_getters = parameter_getters
options = results.options
# Widgets
self._txt_name = QLineEdit()
self._cb_parameters = {}
for name, getter in parameter_getters.items():
if name == x_parameter_name:
continue
combobox = QComboBox()
values = np.array(getter(options), ndmin=1)
combobox.setModel(_ValuesModel(values))
self._cb_parameters[name] = combobox
self._cb_summary_key = QComboBox()
self._cb_summary_key.setModel(_ValuesModel([]))
buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
# Layouts
layout = QFormLayout()
if sys.platform == 'darwin': # Fix for Mac OS
layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow)
layout.addRow('Name', self._txt_name)
for name, combobox in self._cb_parameters.items():
layout.addRow(name, combobox)
layout.addRow('Summary variable', self._cb_summary_key)
layout.addRow(buttons)
self.setLayout(layout)
# Signals
buttons.accepted.connect(self._onOk)
buttons.rejected.connect(self.reject)
for combobox in self._cb_parameters.values():
combobox.currentIndexChanged.connect(self._onParameterChanged)
# Defaults
if series is not None:
self._txt_name.setText(series.name)
for name, _, value in series.conditions:
combobox = self._cb_parameters[name]
index = combobox.model().valueIndex(value)
combobox.setCurrentIndex(index)
self._onParameterChanged()
index = self._cb_summary_key.model().valueIndex(series.summary_key)
self._cb_summary_key.setCurrentIndex(index)
else:
self._onParameterChanged()
def _onParameterChanged(self):
summary_keys = set()
for container in self._results:
match = True
for name, expected in self.parameterValue().items():
getter = self._parameter_getters[name]
actual = getter(container.options)
if actual != expected:
match = False
break
if not match:
continue
try:
result = container[self._result_key]
except KeyError:
continue
summary_keys.update(result.get_summary().keys())
self._cb_summary_key.setModel(_ValuesModel(summary_keys))
def _onOk(self):
if self._cb_summary_key.currentIndex() < 0:
return
self.accept()
def name(self):
name = self._txt_name.text().strip()
if not name:
parts = []
#.........这里部分代码省略.........
示例6: TransferPanel
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
#.........这里部分代码省略.........
if max is not None and (max == 'true'):
self.showMaximized()
# Open the Logbook
if file is not None:
self._openLogbook(file)
def _writeSettings(self):
'Write settings to the configuration'
settings = QSettings()
settings.beginGroup('MainWindow')
settings.setValue('pos', self.pos())
settings.setValue('size', self.size())
settings.setValue('max', self.isMaximized())
settings.setValue('file', self._logbookPath)
settings.endGroup()
def closeEvent(self, e):
'Intercept an OnClose event'
self._writeSettings()
e.accept()
#--------------------------------------------------------------------------
# Slots
@QtCore.Slot()
def _btnAddComputerClicked(self):
'Add a Dive Computer'
dc = AddDiveComputerWizard.RunWizard(self)
if dc is not None:
self._logbook.session.add(dc)
self._logbook.session.commit()
self._cbxComputer.model().reload()
self._cbxComputer.setCurrentIndex(self._cbxComputer.findText(dc.name))
@QtCore.Slot()
def _btnRemoveComputerClicked(self):
'Remove a Dive Computer'
idx = self._cbxComputer.currentIndex()
dc = self._cbxComputer.itemData(idx, Qt.UserRole+0)
if QMessageBox.question(self, self.tr('Delete Dive Computer?'),
self.tr('Are you sure you want to delete "%s"?') % dc.name,
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) == QMessageBox.Yes:
self._logbook.session.delete(dc)
self._logbook.session.commit()
self._cbxComputer.model().reload()
@QtCore.Slot()
def _btnBrowseClicked(self):
'Browse for a Logbook File'
if self._logbook is not None:
dir = os.path.dirname(self._logbookPath)
else:
dir = os.path.expanduser('~')
fn = QFileDialog.getOpenFileName(self,
caption=self.tr('Select a Logbook file'), dir=dir,
filter='Logbook Files (*.lbk);;All Files(*.*)')[0]
if fn == '':
return
if not os.path.exists(fn):
if QMessageBox.question(self, self.tr('Create new Logbook?'),
self.tr('Logbook "%s" does not exist. Would you like to create it?') % os.path.basename(fn),
QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) != QMessageBox.Yes:
return
示例7: DetectorWizardPage
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
#.........这里部分代码省略.........
def clear(self):
self.removeRows(0, self.rowCount())
def detectors(self):
detectors = {}
for key, detector in self._detectors:
if detector is not None:
detectors.setdefault(key, []).append(detector)
return detectors
def detector(self, index):
return self._detectors[index.row()][1]
def key(self, index):
return self._detectors[index.row()][0]
class _DetectorTableDelegate(QItemDelegate):
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
column = index.column()
if column == 0:
editor = QLineEdit(parent)
editor.setValidator(QRegExpValidator(QRegExp(r"^(?!\s*$).+")))
return editor
elif column == 1:
return None
def setEditorData(self, editor, index):
column = index.column()
if column == 0:
key = index.model().data(index, Qt.DisplayRole)
editor.setText(key)
def setModelData(self, editor, model, index):
column = index.column()
if column == 0:
if not editor.hasAcceptableInput():
return
model.setData(index, editor.text())
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Detector')
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._DetectorTableModel()
# Widgets
self._cb_detector = QComboBox()
self._cb_detector.setModel(self._DetectorComboBoxModel())
btn_detector_add = QPushButton()
btn_detector_add.setIcon(getIcon("list-add"))
self._tbl_detector = QTableView()
self._tbl_detector.setModel(tbl_model)
self._tbl_detector.setItemDelegate(self._DetectorTableDelegate())
header = self._tbl_detector.horizontalHeader()
header.setResizeMode(1, QHeaderView.Stretch)
policy = self._tbl_detector.sizePolicy()
policy.setVerticalStretch(True)
示例8: ModelWizardPage
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import model [as 别名]
class ModelWizardPage(_ExpandableOptionsWizardPage):
class _ModelTypeComboBoxModel(QAbstractListModel):
def __init__(self, model_types=None):
QAbstractListModel.__init__(self)
if model_types is None:
model_types = []
self._model_types = list(model_types)
def rowCount(self, *args, **kwargs):
return len(self._model_types)
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or \
not (0 <= index.row() < self.rowCount()):
return None
if role == Qt.TextAlignmentRole:
return Qt.AlignCenter
if role != Qt.DisplayRole:
return None
return str(self._model_types[index.row()])
def modelType(self, index):
return self._model_types[index]
class _ModelComboBoxModel(QAbstractListModel):
def __init__(self, models_text=None):
QAbstractListModel.__init__(self)
if models_text is None:
models_text = {}
self._models_text = models_text.copy()
self._models = {}
for model in models_text.keys():
self._models.setdefault(model.type, []).append(model)
self._model_type = None
def rowCount(self, *args, **kwargs):
return len(self._models.get(self._model_type, []))
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or \
not (0 <= index.row() < self.rowCount()):
return None
if role == Qt.TextAlignmentRole:
return Qt.AlignCenter
if role != Qt.DisplayRole:
return None
model = self._models[self._model_type][index.row()]
return self._models_text[model]
def setModelType(self, model_type):
self._model_type = model_type
self.reset()
def model(self, index):
return self._models[self._model_type][index]
def add(self, model):
if model not in self._models_text:
raise ValueError('No text defined for model: %s' % model)
self._models[model.type].append(model)
self.reset()
def remove(self, model):
self._models[model.type].remove(model)
self.reset()
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Model')
def _initUI(self):
# Widgets
self._cb_model_type = QComboBox()
self._cb_model_type.setModel(self._ModelTypeComboBoxModel())
self._cb_model = QComboBox()
self._cb_model.setModel(self._ModelComboBoxModel())
self._cb_model.setMaxVisibleItems(10)
btn_model_add = QPushButton()
btn_model_add.setIcon(getIcon("list-add"))
self._tbl_model = ModelTableWidget()
tlb_model = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_model.addWidget(spacer)
#.........这里部分代码省略.........