本文整理汇总了Python中PySide.QtGui.QComboBox.itemData方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.itemData方法的具体用法?Python QComboBox.itemData怎么用?Python QComboBox.itemData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QComboBox
的用法示例。
在下文中一共展示了QComboBox.itemData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddDeviceDlg
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [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 itemData [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: AddScenarioDlg
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [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()))
示例4: get_widget_value
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [as 别名]
def get_widget_value(self, widget: QtGui.QComboBox):
return widget.itemData(widget.currentIndex(), QtCore.Qt.UserRole)
示例5: ToolOther
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [as 别名]
#.........这里部分代码省略.........
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
for line in config:
if line.startswith("lang "):
lang_flag = True
new_config.append("lang = %s\n" % self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex()))
elif line.startswith("path_to_cert "):
cert_flag = True
if os.path.isdir(self.fd_cert.text()):
new_config.append("path_to_cert = %s\n" % self.fd_cert.text())
elif not self.fd_cert.text():
new_config.append("path_to_cert = no\n")
else:
new_config.append(line)
# elif line.startswith('timeout '):
# timeout_flag = True
# try:
# timeout = int(self.timeout_lineedit.text())
# except ValueError:
# timeout = ClientObj.timeout
# new_config.append('timeout = %d\n' %timeout)
else:
new_config.append(line)
new_config = self.check_cfg(
lang_flag, new_config, "[other]", "lang", self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex())
)
if not self.fd_cert.text().lower():
new_config = self.check_cfg(cert_flag, new_config, "[other]", "path_to_cert", "no")
elif os.path.isdir(self.fd_cert.text()):
new_config = self.check_cfg(cert_flag, new_config, "[other]", "path_to_cert", self.fd_cert.text())
# try:
# timeout = int(self.timeout_lineedit.text())
# except ValueError:
# timeout = ClientObj.timeout
# new_config = self.check_cfg (timeout_flag, new_config, \
# '[other]', 'timeout', timeout)
fnc = open(self.user_config, "w")
for line in new_config:
fnc.write(line)
fnc.close()
# read config for changed parameters
ClientObj.create_user_config()
ClientObj.read_user_config(ClientObj.user_config)
# reset unsaved changes flag
self._parent.changed_flag = False
if ClientObj.client:
from session_function import client_post_cert
ClientObj.lang = self.lang_ComboBox.itemData(self.lang_ComboBox.currentIndex())
if ClientObj.client:
try:
client_post_cert(ClientObj.client, ClientObj.lang)
except:
return
ClientObj.methods_list = client_list_methods(ClientObj.sid, ClientObj.client)
from DisplayMethod import DisplayMethod
if type(ClientObj.MainWidget.MainFrameWgt) == DisplayMethod:
ClientObj.MainWidget.display_methods()
return wrapper
示例6: TransferPanel
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [as 别名]
#.........这里部分代码省略.........
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
Logbook.Create(fn)
self._openLogbook(fn)
@QtCore.Slot()
def _btnTransferClicked(self):
'Transfer Dives'
idx = self._cbxComputer.currentIndex()
示例7: ExposureControl
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [as 别名]
#.........这里部分代码省略.........
layout = QGridLayout()
title = QLabel("Exposure")
title.setAlignment(Qt.AlignCenter)
layout.addWidget(title, 0, 0, 1, 4)
btnAuto = OptionButton()
btnAuto.setText("Full Auto")
_safelyConnect(btnAuto.clicked, self.camera.setAutoExposure)
btnAuto.setChecked(True)
layout.addWidget(btnAuto, 1, 0)
btnTV = OptionButton()
btnTV.setText("Tv")
_safelyConnect(btnTV.clicked, self.camera.setShutterPriority)
layout.addWidget(btnTV, 1, 1)
btnAV = OptionButton()
btnAV.setText("Av")
_safelyConnect(btnAV.clicked, self.camera.setAperturePriority)
layout.addWidget(btnAV, 1, 2)
btnManual = OptionButton()
btnManual.setText("M")
_safelyConnect(btnManual.clicked, self.camera.setManualExposure)
layout.addWidget(btnManual, 1, 3)
layout.addWidget(QLabel("Aperture"), 2, 0)
self.aperture = QComboBox(self)
for a in list(Aperture):
self.aperture.addItem(a.label, userData=a)
self.aperture.currentIndexChanged.connect(self.setAperture)
self.aperture.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.aperture.setEnabled(False)
layout.addWidget(self.aperture, 2, 1, 1, 3)
layout.addWidget(QLabel("Shutter"), 3, 0)
self.shutter = QComboBox(self)
for s in list(Shutter):
self.shutter.addItem(s.label, userData=s)
self.shutter.currentIndexChanged.connect(self.setShutter)
self.shutter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.shutter.setEnabled(False)
layout.addWidget(self.shutter, 3, 1, 1, 3)
layout.addWidget(QLabel("Gain"), 4, 0)
self.gain = QComboBox(self)
for g in list(Gain):
self.gain.addItem(g.label, userData=g)
self.gain.currentIndexChanged.connect(self.setGain)
self.gain.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.gain.setEnabled(False)
layout.addWidget(self.gain, 4, 1, 1, 3)
self.exposureButtons = QButtonGroup()
self.exposureButtons.addButton(btnAuto, self.Mode.AUTO.value)
self.exposureButtons.addButton(btnTV, self.Mode.TV.value)
self.exposureButtons.addButton(btnAV, self.Mode.AV.value)
self.exposureButtons.addButton(btnManual, self.Mode.MANUAL.value)
self.exposureButtons.buttonClicked.connect(self.onExposureMethodSelected)
layout.setRowStretch(0, 0)
layout.setRowStretch(1, 1)
layout.setRowStretch(2, 1)
layout.setRowStretch(3, 1)
layout.setRowStretch(4, 1)
self.setLayout(layout)
def onExposureMethodSelected(self):
checked = self.exposureButtons.checkedId()
self.aperture.setEnabled(checked & (self.Mode.MANUAL | self.Mode.AV))
self.shutter.setEnabled(checked & (self.Mode.MANUAL | self.Mode.TV))
self.gain.setEnabled(checked & self.Mode.MANUAL.value)
@handlePyroErrors
def setAperture(self, idx):
ap = self.aperture.itemData(idx)
self.camera.setAperture(ap)
@handlePyroErrors
def setShutter(self, idx):
sh = self.shutter.itemData(idx)
self.camera.setShutter(sh)
@handlePyroErrors
def setGain(self, idx):
g = self.gain.itemData(idx)
self.camera.setGain(g)
示例8: AudioTest
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import itemData [as 别名]
#.........这里部分代码省略.........
self.modeButton.clicked.connect(self.toggleMode)
layout.addWidget(self.modeButton)
self.suspendResumeButton = QPushButton(self)
self.suspendResumeButton.setText(SUSPEND_LABEL)
self.suspendResumeButton.clicked.connect(self.toggleSuspendResume)
layout.addWidget(self.suspendResumeButton)
window.setLayout(layout)
self.setCentralWidget(window)
window.show()
def initializeAudio(self):
self.pullTimer.timeout.connect(self.pullTimerExpired)
self.pullMode = True
self.fmt.setFrequency(DATA_FREQUENCY_HZ)
self.fmt.setChannels(1)
self.fmt.setSampleSize(16)
self.fmt.setCodec('audio/pcm')
self.fmt.setByteOrder(QAudioFormat.LittleEndian)
self.fmt.setSampleType(QAudioFormat.SignedInt)
info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice())
if not info.isFormatSupported(self.fmt):
print 'Default format not supported - trying to use nearest'
self.fmt = info.nearestFormat(self.fmt)
self.generator = Generator(self.fmt, DURATION_SECONDS * 1000000,
TONE_FREQUENCY_HZ, self, self.dump)
self.createAudioOutput()
def createAudioOutput(self):
self.audioOutput = QAudioOutput(self.device, self.fmt, self)
self.audioOutput.notify.connect(self.notified)
self.audioOutput.stateChanged.connect(self.stateChanged)
self.generator.start()
self.audioOutput.start(self.generator)
# Slots
def notified(self):
print 'Bytes free %d, elapsed usecs %d, processed usecs %d' % (
self.audioOutput.bytesFree(),
self.audioOutput.elapsedUSecs(),
self.audioOutput.processedUSecs())
def pullTimerExpired(self):
if self.audioOutput.state() != QAudio.StoppedState:
chunks = self.audioOutput.bytesFree() / self.audioOutput.periodSize()
while chunks:
data = self.generator.read(self.audioOutput.periodSize())
self.output.write(data)
if len(data) != self.audioOutput.periodSize():
break
chunks -= 1
def toggleMode(self):
self.pullTimer.stop()
self.audioOutput.stop()
if self.pullMode:
self.modeButton.setText(PULL_MODE_LABEL)
self.output = self.audioOutput.start()
self.pullMode = False
self.pullTimer.start(5)
else:
self.modeButton.setText(PUSH_MODE_LABEL)
self.pullMode = True
self.audioOutput.start(self.generator)
self.suspendResumeButton.setText(SUSPEND_LABEL)
def toggleSuspendResume(self):
if self.audioOutput.state() == QAudio.SuspendedState:
print 'Status: Suspended, resuming'
self.audioOutput.resume()
self.suspendResumeButton.setText(SUSPEND_LABEL)
elif self.audioOutput.state() == QAudio.ActiveState:
print 'Status: Active, suspending'
self.audioOutput.suspend()
self.suspendResumeButton.setText(RESUME_LABEL)
elif self.audioOutput.state() == QAudio.StoppedState:
print 'Status: Stopped, resuming'
self.audioOutput.resume()
self.suspendResumeButton.setText(SUSPEND_LABEL)
elif self.audioOutput.state() == QAudio.IdleState:
print 'Status: Idle'
def stateChanged(self, state):
print 'State changed: ', state
def deviceChanged(self, index):
self.pullTimer.stop()
self.generator.stop()
self.audioOutput.stop()
self.audioOutput.disconnect(self)
self.device = self.deviceBox.itemData(index)
self.createAudioOutput()