本文整理汇总了Python中PySide.QtGui.QButtonGroup.setExclusive方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.setExclusive方法的具体用法?Python QButtonGroup.setExclusive怎么用?Python QButtonGroup.setExclusive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.setExclusive方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ColorChoiceWidget
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
class ColorChoiceWidget(ColorWidget):
def __init__(self):
super(ColorChoiceWidget, self).__init__()
self.buttons = []
self.buttonGroup = QButtonGroup()
self.buttonGroup.setExclusive(True)
self.buttonGroup.buttonClicked.connect(self.selectColor)
def setColors(self, colors):
layout = self.buttonWidget.layout()
id = 0
for color in colors:
button = ColorButton()
button.setColor(color)
button.setCheckable(True)
layout.addWidget(button)
self.buttonGroup.addButton(button)
self.buttonGroup.setId(button, id)
id += 1
layout.addStretch(10)
def setColor(self, color):
self.color = color
for button in self.buttonGroup.buttons():
diffs = map(lambda x, y: abs(x - y), button.color, color)
if sum(diffs) < 0.0001:
button.setChecked(True)
break
def selectColor(self, button):
self.color = button.color
self.valueChanged.emit(self.color)
示例2: StackedPage
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
class StackedPage(QWidget):
def __init__(self, parent = None):
super(StackedPage, self).__init__(parent)
layout = QHBoxLayout(self)
leftpane = QVBoxLayout()
self.buttongroup = QButtonGroup(self)
self.buttongroup.setExclusive(True)
self.groupbox = QGroupBox(self)
self.groupbox.setMinimumWidth(200)
QVBoxLayout(self.groupbox)
leftpane.addWidget(self.groupbox)
leftpane.addStretch(1)
layout.addLayout(leftpane)
self.rightpane = QStackedWidget(self)
layout.addWidget(self.rightpane)
self.buttongroup.buttonClicked[int].connect(self.rightpane.setCurrentIndex)
self.rightpane.currentChanged[int].connect(self.activate)
def addPage(self, buttontext, widget):
button = QPushButton(buttontext)
button.setCheckable(True)
button.setChecked(self.rightpane.count() == 0)
self.buttongroup.addButton(button, self.rightpane.count())
self.groupbox.layout().addWidget(button)
self.rightpane.addWidget(widget)
def pages(self):
return [ self.rightpane.widget(i) for i in range(self.rightpane.count()) ]
def activate(self, ix):
page = self.rightpane.currentWidget()
if hasattr(page, "activate") and callable(page.activate):
page.activate()
def showEvent(self, *args, **kwargs):
self.activate(0)
return QWidget.showEvent(self, *args, **kwargs)
示例3: PeriodicTableWidget
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
class PeriodicTableWidget(QWidget):
selectionChanged = Signal()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# Widgets, layouts and signals
self._group = QButtonGroup()
layout = QGridLayout()
layout.setSpacing(0)
for i in range(18):
layout.setColumnMinimumWidth(i, 40)
layout.setColumnStretch(i, 0)
for i in list(range(7)) + [8, 9]:
layout.setRowMinimumHeight(i, 40)
layout.setRowStretch(i, 0)
## Element
for z, position in _ELEMENT_POSITIONS.items():
widget = ElementPushButton(z)
widget.setCheckable(True)
layout.addWidget(widget, *position)
self._group.addButton(widget, z)
## Labels
layout.addWidget(QLabel(''), 7, 0) # Dummy
layout.addWidget(QLabel('*'), 5, 2, Qt.AlignCenter)
layout.addWidget(QLabel('*'), 8, 2, Qt.AlignCenter)
layout.addWidget(QLabel('**'), 6, 2, Qt.AlignCenter)
layout.addWidget(QLabel('**'), 9, 2, Qt.AlignCenter)
for row in [0, 1, 2, 3, 4, 5, 6, 8, 9]:
layout.setRowStretch(row, 1)
self.setLayout(layout)
# Signals
self._group.buttonClicked.connect(self.selectionChanged)
# Default
self.setColorFunction(_category_color_function)
def setColorFunction(self, func):
if not callable(func):
raise ValueError('Not a function')
self._color_function = func
# Redraw
for widget in self._group.buttons():
z = self._group.id(widget)
bcolor = func(z)
fcolor = 'white' if _calculate_brightness(bcolor) < 128 else 'black'
sheet = 'background-color: %s; color: %s' % (bcolor.name(), fcolor)
widget.setStyleSheet(sheet)
def colorFunction(self):
return self._color_function
def setMultipleSelection(self, multiple):
self._group.setExclusive(not multiple)
def isMultipleSelection(self):
return not self._group.exclusive()
def setSelection(self, selection):
def _uncheckedAll():
for widget in self._group.buttons():
widget.setChecked(False)
if selection is None:
_uncheckedAll()
self.selectionChanged.emit()
return
if isinstance(selection, (int, six.string_types)):
selection = [selection]
if not self.isMultipleSelection() and len(selection) > 1:
raise ValueError('Multiple selection mode is off. Cannot select more than one element')
_uncheckedAll()
for z in selection:
if isinstance(z, six.string_types):
z = ep.atomic_number(z.strip())
self._group.button(z).setChecked(True)
self.selectionChanged.emit()
#
def selection(self):
selection = set()
for widget in self._group.buttons():
if widget.isChecked():
selection.add(self._group.id(widget))
if self.isMultipleSelection():
return frozenset(selection)
#.........这里部分代码省略.........
示例4: OptionsContainer
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
class OptionsContainer(QWidget):
def __init__(self,main_window):
QWidget.__init__(self)
self.main_window = main_window
self.layout = QGridLayout()
self.setLayout(self.layout)
self.lr = numpy.zeros(2)
self.fps = QSpinBox()
self.fps.setValue(25)
self.fps.setMinimum(1)
self.fps.setMaximum(1000)
self.layout.addWidget(QLabel("FPS:"),10,10)
self.layout.addWidget(self.fps,10,11)
self.capture_area_group = QButtonGroup()
self.capture_area_fs = QRadioButton("Full Screen")
self.connect(self.capture_area_fs, SIGNAL("clicked()"),self.capture_area_change)
self.capture_area_fs.setChecked(True)
self.capture_area_sa = QRadioButton("Selected Area")
self.connect(self.capture_area_sa, SIGNAL("clicked()"),self.capture_area_change)
self.capture_area_group.addButton(self.capture_area_fs)
self.capture_area_group.addButton(self.capture_area_sa)
self.capture_area_group.setExclusive(True)
self.layout.addWidget(self.capture_area_fs,12,10)
self.layout.addWidget(self.capture_area_sa,12,11)
self.sa_group = QGroupBox()
self.sa_grid = QGridLayout()
self.sa_group.setLayout(self.sa_grid)
self.sa_ul_bt = QPushButton("Select Upper Left")
self.connect(self.sa_ul_bt, SIGNAL("clicked()"), self.select_ul)
self.sa_lr_bt = QPushButton("Select Lower Right")
self.connect(self.sa_lr_bt, SIGNAL("clicked()"), self.select_lr)
self.sa_x = QSpinBox()
self.sa_y = QSpinBox()
self.sa_w = QSpinBox()
self.sa_h = QSpinBox()
for sb in [self.sa_h,self.sa_w,self.sa_x,self.sa_y]:
sb.setMaximum(999999)
sb.setMinimum(0)
self.sa_grid.addWidget(self.sa_ul_bt,14,10,1,1)
self.sa_grid.addWidget(self.sa_lr_bt,15,10,1,1)
self.sa_grid.addWidget(QLabel("x"),14,11,1,1)
self.sa_grid.addWidget(self.sa_x,14,12,1,1)
self.sa_grid.addWidget(QLabel("y"),15,11,1,1)
self.sa_grid.addWidget(self.sa_y,15,12,1,1)
self.sa_grid.addWidget(QLabel("w"),16,11,1,1)
self.sa_grid.addWidget(self.sa_w,16,12,1,1)
self.sa_grid.addWidget(QLabel("h"),17,11,1,1)
self.sa_grid.addWidget(self.sa_h,17,12,1,1)
self.sa_show_bt = QPushButton("Show Area")
self.sa_show_bt.setCheckable(True)
self.connect(self.sa_show_bt, SIGNAL("clicked()"), self.show_selected_area)
self.sa_grid.addWidget(self.sa_show_bt,18,10,1,10)
self.sa_group.hide()
self.layout.addWidget(self.sa_group,14,10,1,10)
self.capture_delay = QSpinBox()
self.capture_delay.setMinimum(0)
self.capture_delay.setMaximum(10000)
self.layout.addWidget(QLabel("Capture Delay"),18,10,1,1)
self.layout.addWidget(self.capture_delay,18,11,1,1)
self.capture_bt = QPushButton("Capture")
self.stop_capture_bt = QPushButton("Stop")
self.stop_capture_bt.hide()
self.layout.addWidget(self.capture_bt,20,10,1,10)
self.layout.addWidget(self.stop_capture_bt,30,10,1,10)
self.ffmpeg_flags = QLineEdit()
self.ffmpeg_flags.setText("-qscale 0 -vcodec mpeg4")
self.layout.addWidget(QLabel("FFMPEG Flags:"),40,10)
self.layout.addWidget(self.ffmpeg_flags,50,10,1,10)
self.encode_bt = QPushButton("Encode Video")
self.layout.addWidget(self.encode_bt,60,10,1,10)
self.open_dir_bt = QPushButton("Open Directory")
self.layout.addWidget(self.open_dir_bt,80,10,1,10)
self.connect(self.open_dir_bt, SIGNAL("clicked()"),self.open_cwd)
self.selected_area = SelectedArea()
def show_selected_area(self):
x = self.sa_x.value()
y = self.sa_y.value()
#.........这里部分代码省略.........
示例5: CameraControl
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
#.........这里部分代码省略.........
_safelyConnect(self.btnDown.clicked, self.deselectPreset)
self.btnDown.setIcon(QIcon(":icons/go-down"))
self.btnRight = CameraButton()
layout.addWidget(self.btnRight, 1, 2, 2, 1)
_safelyConnect(self.btnRight.pressed, lambda: self.camera.moveRight(self.panSpeed, self.tiltSpeed))
_safelyConnect(self.btnRight.released, self.camera.stop)
_safelyConnect(self.btnRight.clicked, self.deselectPreset)
self.btnRight.setIcon(QIcon(":icons/go-next"))
zoomInOut = PlusMinusButtons("Zoom")
_safelyConnect(zoomInOut.upButton.pressed, lambda: self.camera.zoomIn(self.zoomSpeed))
_safelyConnect(zoomInOut.upButton.released, self.camera.zoomStop)
_safelyConnect(zoomInOut.upButton.clicked, self.deselectPreset)
_safelyConnect(zoomInOut.downButton.pressed, lambda: self.camera.zoomOut(self.zoomSpeed))
_safelyConnect(zoomInOut.downButton.released, self.camera.zoomStop)
_safelyConnect(zoomInOut.downButton.clicked, self.deselectPreset)
layout.addWidget(zoomInOut, 0, 3, 4, 1)
focus = PlusMinusAutoButtons("Focus")
_safelyConnect(focus.upButton.pressed, self.camera.focusFar)
_safelyConnect(focus.upButton.released, self.camera.focusStop)
_safelyConnect(focus.upButton.clicked, self.deselectPreset)
_safelyConnect(focus.downButton.pressed, self.camera.focusNear)
_safelyConnect(focus.downButton.released, self.camera.focusStop)
_safelyConnect(focus.downButton.clicked, self.deselectPreset)
def autoFocusAndDeselect():
self.camera.focusAuto()
self.deselectPreset()
_safelyConnect(focus.autoButton.clicked, autoFocusAndDeselect)
layout.addWidget(focus, 0, 4, 4, 1)
brightness = PlusMinusAutoButtons("Bright")
_safelyConnect(brightness.upButton.clicked, self.camera.brighter)
_safelyConnect(brightness.downButton.clicked, self.camera.darker)
_safelyConnect(brightness.autoButton.clicked, self.camera.setAutoExposure)
layout.addWidget(brightness, 0, 5, 4, 1)
presets = QGridLayout()
presets.setRowStretch(0, 2)
presets.setRowStretch(1, 1)
self.presetGroup = QButtonGroup()
for i in range(1, 7):
btnPresetRecall = CameraButton()
presets.addWidget(btnPresetRecall, 0, i, 1, 1)
btnPresetRecall.setText(str(i))
_safelyConnect(btnPresetRecall.clicked, lambda i=i: self.recallPreset(i))
btnPresetRecall.setCheckable(True)
self.presetGroup.addButton(btnPresetRecall, i)
btnPresetSet = CameraButton()
presets.addWidget(btnPresetSet, 1, i, 1, 1)
btnPresetSet.setText("Set")
_safelyConnect(btnPresetSet.clicked, lambda i=i: self.storePreset(i))
layout.addLayout(presets, 4, 0, 3, 6)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Left:
self.btnLeft.pressed.emit()
elif e.key() == Qt.Key_Right:
self.btnRight.pressed.emit()
elif e.key() == Qt.Key_Up:
self.btnUp.pressed.emit()
elif e.key() == Qt.Key_Down:
self.btnDown.pressed.emit()
def keyReleaseEvent(self, e):
if e.key() == Qt.Key_Left:
self.btnLeft.released.emit()
elif e.key() == Qt.Key_Right:
self.btnRight.released.emit()
elif e.key() == Qt.Key_Up:
self.btnUp.released.emit()
elif e.key() == Qt.Key_Down:
self.btnDown.released.emit()
@handlePyroErrors
def storePreset(self, index):
print "Storing preset " + str(index)
result = self.camera.storePreset(index)
self.presetGroup.buttons()[index - 1].setChecked(True)
return result
@handlePyroErrors
def recallPreset(self, index):
print "Recalling preset " + str(index)
return self.camera.recallPreset(index)
def deselectPreset(self):
if self.presetGroup.checkedId() >= 0:
# Yuck.
self.presetGroup.setExclusive(False)
while (self.presetGroup.checkedId() >= 0):
self.presetGroup.checkedButton().setChecked(False)
self.presetGroup.setExclusive(True)
示例6: CameraControl
# 需要导入模块: from PySide.QtGui import QButtonGroup [as 别名]
# 或者: from PySide.QtGui.QButtonGroup import setExclusive [as 别名]
#.........这里部分代码省略.........
def move(self):
sender = self.sender()
try:
result = self.controller.move(self.cameraID, sender.cameraBinding)
self.deselectPreset()
return result
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def stop(self):
try:
self.controller.move(self.cameraID, CameraMove.Stop)
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def focus(self):
sender = self.sender()
try:
result = self.controller.focus(self.cameraID, sender.cameraBinding)
self.deselectPreset()
return result
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def stopFocus(self):
try:
self.controller.focus(self.cameraID, CameraFocus.Stop)
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def zoom(self):
sender = self.sender()
try:
result = self.controller.zoom(self.cameraID, sender.cameraBinding)
self.deselectPreset()
return result
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def stopZoom(self):
try:
self.controller.zoom(self.cameraID, CameraZoom.Stop)
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def exposure(self):
sender = self.sender()
try:
result = self.controller.backlightComp(self.cameraID, sender.cameraBinding)
self.deselectPreset()
return result
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def storePreset(self):
sender = self.sender()
try:
result = self.controller.savePreset(self.cameraID, sender.cameraBinding)
self.presetGroup.buttons()[sender.cameraBinding].setChecked(True)
return result
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def recallPreset(self):
sender = self.sender()
try:
return self.controller.recallPreset(self.cameraID, sender.cameraBinding)
except NamingError:
self.errorBox(StringConstants.nameErrorText)
except ProtocolError:
self.errorBox(StringConstants.protocolErrorText)
def deselectPreset(self):
# Yuck.
self.presetGroup.setExclusive(False)
while (self.presetGroup.checkedId() >= 0):
self.presetGroup.checkedButton().setChecked(False)
self.presetGroup.setExclusive(True)
def errorBox(self, text):
msgBox = QMessageBox()
msgBox.setText(text)
msgBox.setIcon(QMessageBox.Critical)
msgBox.exec_()