本文整理汇总了Python中PySide.QtGui.QComboBox.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.currentIndex方法的具体用法?Python QComboBox.currentIndex怎么用?Python QComboBox.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QComboBox
的用法示例。
在下文中一共展示了QComboBox.currentIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddDeviceDlg
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class AddDeviceDlg(QDialog):
def __init__(self, root_node, parent=None):
super(AddDeviceDlg, self).__init__(parent)
self.setWindowTitle("Add Relief Device")
id_label = QLabel("&Relief Device ID:")
self.id_lineedit = QLineEdit()
self.id_lineedit.setMaxLength(200)
id_label.setBuddy(self.id_lineedit)
area_label = QLabel("Associated Relief Device &Area:")
self.area_combobox = QComboBox()
for area in root_node.children:
self.area_combobox.addItem(area.name, area)
area_label.setBuddy(self.area_combobox)
color_label = QLabel("&Text Color:")
self.color_combobox = QComboBox()
for key in sorted(COLORS.keys()):
pixmap = QPixmap(26, 26)
pixmap.fill(COLORS[key])
self.color_combobox.addItem(QIcon(pixmap), key)
color_label.setBuddy(self.color_combobox)
button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
layout = QGridLayout()
layout.addWidget(id_label, 0, 0)
layout.addWidget(self.id_lineedit, 0, 1)
layout.addWidget(area_label, 1, 0)
layout.addWidget(self.area_combobox, 1, 1)
layout.addWidget(color_label, 2, 0)
layout.addWidget(self.color_combobox, 2, 1)
layout.addWidget(button_box, 3, 1)
self.setLayout(layout)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
def accept(self):
if len(self.id_lineedit.text().strip()) == 0:
QMessageBox.warning(self, "Error: Relief Device ID Blank", "The relief device must be given an ID.", QMessageBox.Ok)
self.id_lineedit.setFocus()
return
selected_area = self.area_combobox.itemData(self.area_combobox.currentIndex())
for device in selected_area.children:
if device.name == self.id_lineedit.text():
QMessageBox.warning(self, "Error: Relief Device ID Already Exists",
"Cannot add relief device because that relief device ID already exists. Please create a new relief device ID.", QMessageBox.Ok)
self.id_lineedit.setFocus()
self.id_lineedit.setSelection(0, self.id_lineedit.maxLength())
return
QDialog.accept(self)
def returnVals(self):
return (self.id_lineedit.text(), self.area_combobox.itemData(self.area_combobox.currentIndex()),
COLORS[self.color_combobox.currentText()])
示例2: CopyScenarioDlg
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class CopyScenarioDlg(QDialog):
def __init__(self, root_node, parent=None):
super(CopyScenarioDlg, self).__init__(parent)
self.setWindowTitle("Duplicate Scenario")
device_label = QLabel("&Copy Scenario To:")
self.device_combobox = QComboBox()
device_label.setBuddy(self.device_combobox)
for area in root_node.children:
for device in area.children:
self.device_combobox.addItem(device.name, device)
button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
layout = QGridLayout()
layout.addWidget(device_label, 0, 0)
layout.addWidget(self.device_combobox, 0, 1)
layout.addWidget(button_box, 1, 1)
self.setLayout(layout)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
def returnVals(self):
return self.device_combobox.itemData(self.device_combobox.currentIndex())
示例3: DragPlotWidget
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class DragPlotWidget(QFrame):
''' draggable widget plotting data and
a combo box to choose channel
'''
def __init__(self, parent=None):
super(DragPlotWidget, self).__init__(parent)
# transparent fill color and a frame with size 400x250
self.setStyleSheet("QFrame { border: 2px solid black; background-image: url(); }")
self.setGeometry(1,1,400,250)
# arrange elements in a gridLayout
l = QGridLayout()
self.setLayout(l)
self.p = pq.PlotWidget(self)
self.p.setYRange(-0.0002, 0.0002)
self.pl1 = self.p.plot(np.linspace(0,3.4, 1000)) # initial plot
self.box = QComboBox(self)
self.box.addItems(["EMG " + str(x+1) for x in range(16)])
self.box.currentIndexChanged.connect(self.changeChannel)
l.addWidget(self.p)
l.addWidget(self.box)
self.dragPos = QPoint(0,0)
def mousePressEvent(self, e):
''' enter drag mode by left click and save position '''
if e.buttons() != Qt.LeftButton:
return
self.dragPos = e.pos()
def mouseMoveEvent(self, e):
''' move by holding left mouse button and update position
- removing offset by subtracting saved dragPos
'''
if e.buttons() != Qt.LeftButton:
return
position = e.pos() + self.pos() - self.dragPos
self.move(position)
self.update()
self.parent().update()
def mouseReleaseEvent(self, e):
''' release left mouse button and exit drag mode '''
if e.buttons() != Qt.LeftButton:
return
position = e.pos() + self.pos() - self.dragPos
self.move(position)
def changeChannel(self, index):
''' change channel to index and clear plot '''
self.p.plot([0], clear=True)
def updatePlot(self, data):
''' plot new data '''
self.p.plot(data[self.box.currentIndex()], clear=True)
示例4: AddScenarioDlg
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class AddScenarioDlg(QDialog):
def __init__(self, root_node, parent=None):
super(AddScenarioDlg, self).__init__(parent)
self.setWindowTitle("Add Scenario")
type_label = QLabel("&Scenario Type:")
self.type_combobox = QComboBox()
type_label.setBuddy(self.type_combobox)
self.type_combobox.addItems(["External Fire", "Liquid Overfill", "Regulator Failure"])
device_label = QLabel("&Associated Relief Device:")
self.device_combobox = QComboBox()
device_label.setBuddy(self.device_combobox)
for area in root_node.children:
for device in area.children:
self.device_combobox.addItem(device.name, device)
button_box = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
layout = QGridLayout()
layout.addWidget(type_label, 0, 0)
layout.addWidget(self.type_combobox, 0, 1)
layout.addWidget(device_label, 1, 0)
layout.addWidget(self.device_combobox, 1, 1)
layout.addWidget(button_box, 2, 1)
self.setLayout(layout)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
def returnVals(self):
return (self.type_combobox.currentText(), self.device_combobox.itemData(self.device_combobox.currentIndex()))
示例5: _OptionsSelector
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [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())
示例6: MessageBoxWithCheckbox
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class MessageBoxWithCheckbox(QMessageBox):
def __init__(self, parent=None):
super(MessageBoxWithCheckbox, self).__init__(parent)
self.instance_state_widget = QComboBox()
self.layout().addWidget(self.instance_state_widget, 1, 1)
def exec_(self, *args, **kwargs):
return QMessageBox.exec_(self, *args, **kwargs), \
self.instance_state_widget.currentIndex()
示例7: LandmarkWidget
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class LandmarkWidget(QWidget):
landmarkTypeChanged = Signal(object)
def __init__(self):
super(LandmarkWidget, self).__init__()
self.typeLabel = QLabel("Picker type:")
self.typeCombo = QComboBox()
self.typeCombo.addItem("Surface")
self.typeCombo.addItem("Two step")
self.typeCombo.currentIndexChanged.connect(self.comboboxChanged)
self.surfaceWidget = SurfaceLandmarkWidget()
self.twoStepWidget = TwoStepLandmarkWidget()
self.surfaceWidget.setHidden(True)
self.twoStepWidget.setHidden(True)
layout = QGridLayout()
layout.setAlignment(Qt.AlignTop)
layout.addWidget(self.typeLabel, 0, 0)
layout.addWidget(self.typeCombo, 0, 1)
layout.addWidget(self.surfaceWidget, 1, 0, 1, 2)
layout.addWidget(self.twoStepWidget, 2, 0, 1, 2)
self.setLayout(layout)
self.update()
def update(self):
idx = self.typeCombo.currentIndex()
if idx == 0:
self.surfaceWidget.setHidden(False)
self.twoStepWidget.setHidden(True)
self.landmarkType = SurfaceType
elif idx == 1:
self.surfaceWidget.setHidden(True)
self.twoStepWidget.setHidden(False)
self.landmarkType = TwoStepType
@Slot(int)
def comboboxChanged(self, index):
self.update()
self.landmarkTypeChanged.emit(self)
示例8: SimpleComboboxOption
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class SimpleComboboxOption(SimpleOption):
def __init__(self, settingsName, labelText, defaultValue, checkable=False, *options):
self.options = options
super(SimpleComboboxOption,self).__init__(settingsName, labelText, defaultValue, checkable)
def editor(self, defaultValue):
#options = ('Uniform','Exponential','Normal','Log Normal')
options = self.options
self.combo = QComboBox()
self.combo.addItems(options)
self.combo.setCurrentIndex(int(QSettings().value(self.settingsName, defaultValue)))
self.combo.setToolTip('Default value: %s' % defaultValue)
#self.combo.setAlignment(Qt.AlignLeft|Qt.AlignTop)
self.layout().addWidget(self.combo)
def setEnabled(self, e):
self.combo.setEnabled(e)
def getValue(self):
return self.combo.currentIndex()
def getName(self):
return self.combo.currentText()
示例9: LCRow
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class LCRow():
def __init__(self,fileName,experimentName,guess):
self.fileName = QLabel(fileName)
self.plateID = QLineEdit()
self.experiment = QLineEdit()
self.guess = QLabel(guess[0] + ', ' + guess[1])
self.robot = QComboBox()
self.platePosition = QComboBox()
self.plateID.setText(path.splitext(path.basename(fileName))[0])
self.experiment.setText(experimentName)
self.robot.addItems(['2000','FX','96'])
self.robot.setCurrentIndex(self.robot.findText(guess[0]))
self.platePosition.addItems(['Plate 0','Plate 1','Plate 2','Plate 3','Plate 4'])
self.platePosition.setCurrentIndex(self.platePosition.findText(guess[1]))
def getFileName(self): return self.fileName.text()
def getPlateID(self): return self.plateID.text()
def getExperiment(self): return self.experiment.text()
def getRobot(self): return self.robot.currentText()
def getPlatePosition(self): return self.platePosition.currentIndex()
示例10: ToolOther
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class ToolOther(QtGui.QWidget):
def __init__(self, parent, ClientObj):
QtGui.QWidget.__init__(self, parent)
self.user_config = ClientObj.user_config
self._parent = parent
self.grid = QtGui.QGridLayout(self)
self.grid.setContentsMargins(2, 2, 2, 2)
self.grid.setSpacing(2)
self.grid.setColumnStretch(0, 3)
self.grid.setColumnStretch(1, 5)
# lang settings
self.lang_lbl = LabelWordWrap(_("Select Language"), self)
self.lang_lbl.setMaximumWidth(self.lang_lbl.sizeHint().width())
self.lang_ComboBox = QComboBox(self)
lang_dict = {"en": _("English"), "ru": _("Russian"), "fr": _("French")}
for lang in lang_dict:
self.lang_ComboBox.addItem(lang_dict[lang])
self.lang_ComboBox.setItemData(self.lang_ComboBox.count() - 1, lang)
if ClientObj.lang == lang:
self.lang_ComboBox.setCurrentIndex(self.lang_ComboBox.count() - 1)
# add lang settings in grid
self.grid.addWidget(self.lang_lbl, 0, 0)
self.grid.addWidget(self.lang_ComboBox, 0, 1)
# add open file in grid
self.cert_path_lbl = LabelWordWrap(_("Path to Certificates"), self)
self.cert_path_lbl.setMaximumWidth(self.cert_path_lbl.sizeHint().width())
self.fd_cert = FileOpenWgt(self, "dir", _("Certificate Directory"), "~/.calculate")
self.fd_cert.setToolTip(_("Empty to default path"))
self.fd_cert.setText(ClientObj.path_to_cert)
self.grid.addWidget(self.cert_path_lbl, 1, 0)
self.grid.addWidget(self.fd_cert, 1, 1)
# # add timeout in grid
# self.timeout_lbl = LabelWordWrap(_('Timeout'), self)
# self.timeout_lbl.setMaximumWidth(self.timeout_lbl.sizeHint().width())
#
# self.timeout_lineedit = QtGui.QLineEdit(self)
#
# self.timeout_lineedit.setText(str(ClientObj.timeout))
#
# self.grid.addWidget(self.timeout_lbl, 2, 0)
# self.grid.addWidget(self.timeout_lineedit, 2, 1)
# add spacer
self.grid.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding), 5, 0, 1, 2)
# connect all with change value slot
self.lang_ComboBox.currentIndexChanged.connect(self.changed_val)
self.fd_cert.textChanged.connect(self.changed_val)
# self.timeout_lineedit.textChanged.connect(self.changed_val)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
def changed_val(self):
self._parent.changed_flag = True
def check_cfg(self, flag, config, part, param, value):
# if param not exists in config
if not flag:
part_flag = False
temp_cfg = []
for line in config:
temp_cfg.append(line)
# add new line in config
if line.startswith(part):
temp_cfg.append("%s = %s\n" % (param, value))
part_flag = True
config = temp_cfg
# if part not exists
if not part_flag:
config.append("\n")
config.append("%s\n" % part)
config.append("%s = %s\n" % (param, value))
return config
def save_changes(self, ClientObj):
def wrapper():
if not os.path.isfile(self.user_config):
f = open(self.user_config, "w")
f.close()
fc = open(self.user_config, "r")
config = fc.readlines()
fc.close()
new_config = []
lang_flag = False
cert_flag = False
# timeout_flag = False
#.........这里部分代码省略.........
示例11: ColorMapWidget
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class ColorMapWidget(QWidget):
"""Interface for changing ColorMap information. It shows the current
color map selection, a selector for other colormaps, and the option
to cycle the color map by any number of ordinal values.
This widget was designed for use with the tab dialog. It can be used by
itself or it can be used as part of a bigger color tab.
Changes to this widget are emitted via a changeSignal as a ColorMap
object and this widget's tag.
"""
changeSignal = Signal(ColorMap, str)
def __init__(self, parent, initial_map, tag):
"""Creates a ColorMap widget.
parent
The Qt parent of this widget.
initial_map
The colormap set on creation.
tag
A name for this widget, will be emitted on change.
"""
super(ColorMapWidget, self).__init__(parent)
self.color_map = initial_map.color_map
self.color_map_name = initial_map.color_map_name
self.color_step = initial_map.color_step
self.step_size = initial_map.step_size
self.tag = tag
self.color_map_label = "Color Map"
self.color_step_label = "Cycle Color Map"
self.number_steps_label = "Colors"
self.color_step_tooltip = "Use the given number of evenly spaced " \
+ " colors from the map and assign to discrete values in cycled " \
+ " sequence."
layout = QVBoxLayout()
layout.addWidget(self.buildColorBarControl())
layout.addItem(QSpacerItem(5,5))
layout.addWidget(self.buildColorStepsControl())
self.setLayout(layout)
def buildColorBarControl(self):
"""Builds the portion of this widget for color map selection."""
widget = QWidget()
layout = QHBoxLayout()
label = QLabel(self.color_map_label)
self.colorbar = QLabel(self)
self.colorbar.setPixmap(QPixmap.fromImage(ColorBarImage(
self.color_map, 180, 15)))
self.mapCombo = QComboBox(self)
self.mapCombo.addItems(map_names)
self.mapCombo.setCurrentIndex(map_names.index(self.color_map_name))
self.mapCombo.currentIndexChanged.connect(self.colorbarChange)
layout.addWidget(label)
layout.addItem(QSpacerItem(5,5))
layout.addWidget(self.mapCombo)
layout.addItem(QSpacerItem(5,5))
layout.addWidget(self.colorbar)
widget.setLayout(layout)
return widget
@Slot(int)
def colorbarChange(self, ind):
"""Handles a selection of a different colormap."""
indx = self.mapCombo.currentIndex()
self.color_map_name = map_names[indx]
self.color_map = getMap(self.color_map_name)
self.colorbar.setPixmap(QPixmap.fromImage(ColorBarImage(
self.color_map, 180, 12)))
self.changeSignal.emit(ColorMap(self.color_map_name, self.color_step,
self.step_size), self.tag)
def buildColorStepsControl(self):
"""Builds the portion of this widget for color cycling options."""
widget = QWidget()
layout = QHBoxLayout()
self.stepBox = QCheckBox(self.color_step_label)
self.stepBox.stateChanged.connect(self.colorstepsChange)
self.stepEdit = QLineEdit("8", self)
# Setting max to sys.maxint in the validator causes an overflow! D:
self.stepEdit.setValidator(QIntValidator(1, 65536, self.stepEdit))
self.stepEdit.setEnabled(False)
self.stepEdit.editingFinished.connect(self.colorstepsChange)
if self.color_step > 0:
self.stepBox.setCheckState(Qt.Checked)
#.........这里部分代码省略.........
示例12: OptionSection
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class OptionSection(QWidget):
"""
Collects options and returns proper representation when requested
"""
def __init__(self, parent=None):
super(OptionSection, self).__init__(parent)
#create widgets
label_buffer_size = QLabel("Buffer Size")
self.spinbox_buffer_size = ValidatedSpinBox()
self.spinbox_buffer_size.setSingleStep(10)
self.spinbox_buffer_size.setMaximum(9999999)
self.spinbox_buffer_size.setSuffix(" bytes")
self.spinbox_buffer_size.setValue(55)
label_timeout = QLabel("Timeout")
self.spinbox_timeout = ValidatedSpinBox()
self.spinbox_timeout.setMaximum(9999999)
self.spinbox_timeout.setSuffix(" ms")
self.spinbox_timeout.setSingleStep(100)
self.spinbox_timeout.setValue(1000)
label_delay = QLabel("Delay Between Packets")
self.spinbox_delay = ValidatedSpinBox()
self.spinbox_delay.setMaximum(9999999)
self.spinbox_delay.setSuffix(" ms")
self.spinbox_delay.setSingleStep(100)
self.spinbox_delay.setValue(1000)
label_delay_distribution = QLabel("Delay Distribution")
self.combobox_delay_distribution = QComboBox()
self.combobox_delay_distribution.addItem("Constant")
self.combobox_delay_distribution.insertSeparator(10)
self.combobox_delay_distribution.addItems(["Uniform", "Gaussian", "Poisson", "Exponential"])
label_packet_count = QLabel("Packets to Send")
self.spinbox_packet_count = ValidatedSpinBox()
self.spinbox_packet_count.setMaximum(9999999)
self.spinbox_packet_count.setValue(3)
#setup layout
layout = QFormLayout()
layout.addRow(label_buffer_size, self.spinbox_buffer_size)
layout.addRow(label_timeout, self.spinbox_timeout)
layout.addRow(label_delay, self.spinbox_delay)
layout.addRow(label_delay_distribution, self.combobox_delay_distribution)
layout.addRow(label_packet_count, self.spinbox_packet_count)
self.setLayout(layout)
def getOptions(self):
"""
Return a RequestData object representing selected options
"""
buf_size = self.spinbox_buffer_size.value()
timeout = self.spinbox_timeout.value()
delay = self.spinbox_delay.value() / 1000
packet_count = self.spinbox_packet_count.value()
selected_distribution = self.combobox_delay_distribution.currentIndex()
if selected_distribution == 0:
distribution = RequestData.DISTRIBUTION_CONSTANT
elif selected_distribution == 1:
distribution = RequestData.DISTRIBUTION_UNIFORM
elif selected_distribution == 2:
distribution = RequestData.DISTRIBUTION_GAUSSIAN
elif selected_distribution == 3:
distribution = RequestData.DISTRIBUTION_POISSON
elif selected_distribution == 4:
distribution = RequestData.DISTRIBUTION_EXPONENTIAL
return RequestData(buf_size, timeout, delay, packet_count, distribution)
def disableWidgets(self):
for widget in [self.spinbox_buffer_size, self.spinbox_delay,
self.spinbox_packet_count, self.spinbox_timeout,
self.combobox_delay_distribution]:
widget.setEnabled(False)
def enableWidgets(self):
for widget in [self.spinbox_buffer_size, self.spinbox_delay,
self.spinbox_packet_count, self.spinbox_timeout,
self.combobox_delay_distribution]:
widget.setEnabled(True)
示例13: RateView
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class RateView(QGroupBox):
'''The box containing the rate value'''
def __init__(self, title = 'Rate', parent = None):
'''Initialize'''
super(RateView, self).__init__(parent)
self.setTitle(title)
self._createWidgets()
def _createWidgets(self):
'''Create the widgets contained in this box'''
# Rate or lifetime chooser
self.rate = QRadioButton('Rate', self)
self.rate.setToolTip(ttt('Choose this to express exchange as rate'))
self.lifetime = QRadioButton('Lifetime', self)
self.lifetime.setToolTip(ttt('Choose this to express exchange as '
'lifetime'))
# Box containing value
self.rate_value = QLineEdit(self)
validate = QDoubleValidator(self.rate_value)
validate.setDecimals(3)
validate.setBottom(0.0)
self.rate_value.setValidator(validate)
self.rate_value.setToolTip(ttt('The rate or lifetime value'))
# Unit
self.unit = QComboBox(self)
self.unit.setToolTip(ttt('Selects the input unit for the rate '
'or lifetime'))
def initUI(self):
'''Lays out the widgets'''
radios = QVBoxLayout()
radios.addWidget(self.rate)
radios.addWidget(self.lifetime)
rate = QGridLayout()
rate.addWidget(QLabel("Unit: "), 1, 1)
rate.addWidget(self.unit, 1, 2)
rate.addWidget(QLabel("Value: "), 2, 1)
rate.addWidget(self.rate_value, 2, 2)
total = QHBoxLayout()
total.addLayout(radios)
total.addStretch()
total.addLayout(rate)
self.setLayout(total)
def makeConnections(self):
'''Connect the widgets together'''
# When one radio button is checked, change the combo box model
# and un-check the other radio button
self.rate.clicked.connect(self.setRateModel)
self.lifetime.clicked.connect(self.setLifetimeModel)
# If the text changes, emit that rate
self.rate_value.editingFinished.connect(self.emitRate)
# If the underlying model changes, adjust the text
self.model.rateChanged.connect(self.updateRate)
# If the unit changes, update rate
self.unit.currentIndexChanged.connect(self.updateUnit)
def setModel(self, model):
'''Attaches models to the views'''
self.model = model
def setRate(self, rate):
'''Set the rate manually'''
self.rate_value.setText(str(rate))
self.rate_value.editingFinished.emit()
def setUnit(self, unit):
'''Set the unit manually'''
if unit == 's':
self.lifetime.click()
self.unit.setCurrentIndex(0)
elif unit == 'ns':
self.lifetime.click()
self.unit.setCurrentIndex(1)
elif unit == 'ps':
self.lifetime.click()
self.unit.setCurrentIndex(2)
elif unit == 'fs':
self.lifetime.click()
self.unit.setCurrentIndex(3)
elif unit in ('Hz', 'hz'):
self.rate.click()
self.unit.setCurrentIndex(0)
elif unit in ('GHz', 'ghz'):
self.rate.click()
self.unit.setCurrentIndex(1)
elif unit in ('THz', 'thz'):
self.rate.click()
self.unit.setCurrentIndex(2)
elif unit in ('PHz', 'phz'):
self.rate.click()
self.unit.setCurrentIndex(3)
#.........这里部分代码省略.........
示例14: _PhotonDistributionResultOptionsToolItem
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [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()
示例15: BeamWizardPage
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import currentIndex [as 别名]
class BeamWizardPage(_ExpandableOptionsWizardPage):
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle("Beam")
def _initUI(self):
# Variables
self._widgets = {}
# Widgets
self._cb_beam = QComboBox()
self._wdg_beam = QStackedWidget()
# Layouts
layout = _ExpandableOptionsWizardPage._initUI(self)
layout.addRow("Type of beam", self._cb_beam)
layout.addRow(self._wdg_beam)
# Signals
self._cb_beam.currentIndexChanged.connect(self._onBeamChanged)
self._cb_beam.currentIndexChanged.connect(self.valueChanged)
return layout
def _onBeamChanged(self):
newindex = self._cb_beam.currentIndex()
oldwidget = self._wdg_beam.currentWidget()
newwidget = self._wdg_beam.widget(newindex)
if newwidget is None:
return
try:
newwidget.setValue(oldwidget.value())
except:
newwidget.setValue(self.options().beam)
self._wdg_beam.setCurrentIndex(newindex)
def initializePage(self):
_ExpandableOptionsWizardPage.initializePage(self)
# Clear
self._widgets.clear()
for i in reversed(range(self._cb_beam.count())):
self._cb_beam.removeItem(i)
self._wdg_beam.removeWidget(self._wdg_beam.widget(i))
# Populate combo box
it = self._iter_widgets("pymontecarlo.ui.gui.options.beam", "BEAMS")
for clasz, widget_class, programs in it:
widget = widget_class()
self._widgets[clasz] = widget
program_text = ", ".join(map(attrgetter("name"), programs))
text = "{0} ({1})".format(widget.accessibleName(), program_text)
self._cb_beam.addItem(text)
self._wdg_beam.addWidget(widget)
widget.setParticlesEnabled(False)
for program in programs:
converter = program.converter_class
for particle in converter.PARTICLES:
widget.setParticleEnabled(particle, True)
widget.valueChanged.connect(self.valueChanged)
# Select beam
beam = self.options().beam
widget = self._widgets.get(beam.__class__)
if widget is None:
widget = next(iter(self._widgets.values()))
widget.setValue(beam)
self._wdg_beam.setCurrentWidget(widget)
self._cb_beam.setCurrentIndex(self._wdg_beam.currentIndex())
def validatePage(self):
if not self._wdg_beam.currentWidget().hasAcceptableInput():
return False
self.options().beam = self._wdg_beam.currentWidget().value()
return True
def expandCount(self):
try:
return len(expand(self._wdg_beam.currentWidget().value()))
except:
return 0