本文整理汇总了Python中PyQt4.QtGui.QButtonGroup类的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup类的具体用法?Python QButtonGroup怎么用?Python QButtonGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QButtonGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TokenizerModule
class TokenizerModule(PreprocessorModule):
DEFAULT_SETTINGS = {
'is_enabled': True,
'method': 0,
}
NLTKTokenizer, NLTKPunctTokenizer, TwitterTokenizer = 0, 1, 2
tokenizer_values = {
NLTKTokenizer: 'default',
NLTKPunctTokenizer: 'no_punct',
TwitterTokenizer: 'twitter'
}
tokenizer_names = {
NLTKTokenizer: 'NLTK tokenizer',
NLTKPunctTokenizer: 'NLTK tokenizer (no punctuation)',
TwitterTokenizer: 'Twitter tokenizer',
}
tokenizer_method = 0
def __init__(self, data):
data = data or self.DEFAULT_SETTINGS
PreprocessorModule.__init__(
self, 'Tokenizer', False,
data.get('is_enabled')
)
self.group = QButtonGroup(self, exclusive=True)
for method in [
self.NLTKTokenizer,
self.NLTKPunctTokenizer,
self.TwitterTokenizer,
]:
rb = QRadioButton(self, text=self.tokenizer_names[method])
self.add_to_content_area(rb)
self.group.addButton(rb, method)
self.group.buttonClicked.connect(self.group_button_clicked)
# Restore the previous state, after starting off the layout.
self.restore_data(data)
def group_button_clicked(self):
self.tokenizer_method = self.group.checkedId()
self.notify_on_change()
def restore_data(self, data):
self.tokenizer_method = data.get('method')
b = self.group.button(self.tokenizer_method)
b.setChecked(True)
def export_data(self):
return {
'is_enabled': self.enabled,
'method': self.tokenizer_method,
}
def get_pp_setting(self):
return {
'tokenizer': self.tokenizer_values.get(self.tokenizer_method)
}
示例2: ChooseBlogDialog
class ChooseBlogDialog(QDialog, Ui_ChooseBlogDialog):
def __init__(self, available_blogs, addToDB):
QDialog.__init__(self)
Ui_ChooseBlogDialog.__init__(self)
self.func = addToDB
self.setupUi(self)
radioboxLayout = QVBoxLayout()
self.radiobuttonGroup = QButtonGroup()
self.radios = []
for blog in available_blogs:
radio = BlogRadio("Blog Title: %s, Url: %s" %(blog.blogname, blog.homeurl), blog)
self.radiobuttonGroup.addButton(radio)
radioboxLayout.addWidget(radio)
self.radios.append(radio)
self.chooseBlogFrame.setLayout(radioboxLayout)
self.adjustSize()
connect(self.chooseBlogButtonBox, SIGNAL("accepted()"), self.addBlog) #AddBlogDialog.accept)
connect(self.chooseBlogButtonBox, SIGNAL("rejected()"), self.reject)#AddBlogDialog.reject)
def addBlog(self):
if self.radiobuttonGroup.checkedButton():
self.func(self.radiobuttonGroup.checkedButton().blog)
self.accept()
else:
QMessageBox.warning(self, "Choose A Blog", "Please choose a blog and click OK. If you do not want to add a blog, Please click 'Cancel'", QMessageBox.Ok, QMessageBox.Ok)
pass
示例3: __init__
def __init__(self, iface_name, parent=None):
IfaceWizardPage.__init__(self, parent)
self.q_netobject = QNetObject.getInstance()
self.setSubTitle("What kind of interface do you want to configure?")
box = QVBoxLayout(self)
self.ethernet = "ethernet", "Activate ethernet interface %s" % iface_name , QRadioButton()
self.vlan = "vlan", "Create a VLAN interface", QRadioButton()
group = QButtonGroup(self)
form = QFormLayout()
options = (self.ethernet, self.vlan)
for item in options:
group.addButton(item[2])
form.addRow(item[1], item[2])
self.registerField(item[0], item[2])
self.ethernet[2].setChecked(Qt.Checked)
box.addLayout(form)
box.addStretch()
box.addWidget(
HelpMissingFunction("""\
All interfaces but one (%s) are configured.
In order to be able to activate an ethernet interface for bonding agregation, \
you must deconfigure at least one ethernet interface first \
(which may be in use by vlans or bondings).""" % iface_name)
)
示例4: TransformationModule
class TransformationModule(PreprocessorModule):
DEFAULT_SETTINGS = {
'is_enabled': True,
'method': 0,
}
PorterStemmer, SnowballStemmer, Lemmatizer = 0, 1, 2
transformation_values = {
PorterStemmer: PS,
SnowballStemmer: SS,
Lemmatizer: LM,
}
transformation_method = 0
def __init__(self, data):
data = data or self.DEFAULT_SETTINGS
PreprocessorModule.__init__(
self, 'Stemming', True,
data.get('is_enabled')
)
self.group = QButtonGroup(self, exclusive=True)
for method in [
self.PorterStemmer,
self.SnowballStemmer,
self.Lemmatizer
]:
rb = QRadioButton(
self,
text=self.transformation_values[method].name
)
self.add_to_content_area(rb)
self.group.addButton(rb, method)
self.group.buttonClicked.connect(self.group_button_clicked)
# Restore the previous state, after starting off the layout.
self.restore_data(data)
def group_button_clicked(self):
self.transformation_method = self.group.checkedId()
self.notify_on_change()
def restore_data(self, data):
self.transformation_method = data.get('method')
b = self.group.button(self.transformation_method)
b.setChecked(True)
def export_data(self):
return {
'is_enabled': self.enabled,
'method': self.transformation_method,
}
def get_pp_setting(self):
return {
'transformation': self.transformation_values.get(
self.transformation_method
)
}
示例5: ActionsPane
class ActionsPane(QWidget):
def __init__(self):
super().__init__()
self.group = QButtonGroup()
self.group.setExclusive(False)
self.scope_widget = ActionsScope()
self.action_buttons = QVBoxLayout()
self.big_red_button = QPushButton("Automate !!!", clicked=self.automate)
self.big_red_button.setStyleSheet("QPushButton { background-color : red}")
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.layout.addWidget(self.scope_widget)
self.layout.addLayout(self.action_buttons)
self.layout.addStretch()
self.layout.addWidget(self.big_red_button)
def registerAction(self, action):
button = ActionButton(action)
self.group.addButton(button.checkbox)
self.action_buttons.addWidget(button)
def getCheckedActions(self):
return [btn.parent().action for btn in self.group.buttons() if btn.isChecked()]
def automate(self, event):
for action in self.getCheckedActions():
action.on_triggered()
示例6: ScopeBox
class ScopeBox(QGroupBox):
title = None
button_type = None
def __init__(self):
if self.title is None or self.button_type is None:
raise Exception("Still too abstract!")
super().__init__(title=self.title)
self.populate_button_id()
self.build_layout()
self.populate_box()
self.select_default()
if self.button_type == 'check':
self.group.setExclusive(False)
def populate_button_id(self):
pass
def build_layout(self):
self.group = QButtonGroup()
self.layout = QVBoxLayout()
self.setLayout(self.layout)
def populate_box(self):
keys = list(self.button_id.keys())
keys.sort()
BtnClass = None
if self.button_type == 'check':
BtnClass = QCheckBox
elif self.button_type == 'radio':
BtnClass = QRadioButton
for key in keys:
btn = BtnClass(key)
self.layout.addWidget(btn)
self.group.addButton(btn, self.button_id[key])
def select_default(self):
pass
def getSelection(self):
selection = None
if self.button_type == 'radio':
selection = self.group.checkedId()
elif self.button_type == 'check':
selection = []
for btn in self.group.buttons():
if btn.isChecked():
selection.append(btn.text())
return selection
示例7: AxisWidgetContainer
class AxisWidgetContainer(GridWidget):
def __init__(self, axisModel, parent = None):
super(AxisWidgetContainer, self).__init__(["_Axis", "_Value_", "_X(24)", "_Y(24)"], parent)
self.axisModel = axisModel
self.xGroup = QButtonGroup()
self.yGroup = QButtonGroup()
self.xGroup.buttonClicked.connect(self.showXAxisButtonClicked)
self.yGroup.buttonClicked.connect(self.showYAxisButtonClicked)
axis = 0
for axis in range(axisModel.currentJoystickNumAxes()):
self.__createTextWidgetForAxis__(axis)
if axis > 0:
self.graphWidget = AxisGraphWidget(self)
self.addWidget(self.graphWidget, 3, 0, 1, 2)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.scrollArea.sizePolicy().hasHeightForWidth())
self.scrollArea.setSizePolicy(sizePolicy)
def __createTextWidgetForAxis__(self, axis):
textWidget = AxisTextWidget(axis, self)
self.axisModel.addAxisObserver(textWidget, axis)
showInX = QRadioButton()
showInY = QRadioButton()
showInX.setObjectName(str(axis))
showInY.setObjectName(str(axis))
showInX.setLayoutDirection(Qt.RightToLeft)
showInY.setLayoutDirection(Qt.RightToLeft)
showInX.setMaximumSize(24, 24)
showInY.setMaximumSize(24, 24)
self.xGroup.addButton(showInX)
self.yGroup.addButton(showInY)
gridLayout = QGridLayout()
gridLayout.addWidget(textWidget, 0, 0, 1, 2)
gridLayout.addWidget(showInX, 0, 2, 1, 1)
gridLayout.addWidget(showInY, 0, 3, 1, 1)
self.addLayoutToScrollArea(gridLayout)
def showXAxisButtonClicked(self, button):
if button.isChecked():
self.graphWidget.setXAxis(int(button.objectName()))
self.axisModel.addAxisObserver(self.graphWidget, int(button.objectName()))
else:
self.axisModel.removeAxisObserver(self.graphWidget, int(button.objectName()))
def showYAxisButtonClicked(self, button):
if button.isChecked():
self.graphWidget.setYAxis(int(button.objectName()))
self.axisModel.addAxisObserver(self.graphWidget, int(button.objectName()))
else:
self.axisModel.removeAxisObserver(self.graphWidget, int(button.objectName()))
示例8: __init__
def __init__(self):
super(IntroductionPage, self).__init__()
self.setTitle(self.tr("Creación de un nuevo Proyecto"))
self.setSubTitle(self.tr("Información básica del Proyecto"))
container = QVBoxLayout(self)
hbox = QHBoxLayout()
# Nombre
hbox.addWidget(QLabel(self.tr("Nombre del Proyecto:")))
self.line_name = QLineEdit()
hbox.addWidget(self.line_name)
container.addLayout(hbox)
# Ubicación
group = QGroupBox(self.tr("Ubicación:"))
box = QVBoxLayout(group)
button_group = QButtonGroup(self)
radio_buttons = [
self.tr("Directorio por defecto"),
self.tr("Otro")
]
for _id, radiob in enumerate(radio_buttons):
radio_button = QRadioButton(radiob)
button_group.addButton(radio_button, _id)
box.addWidget(radio_button)
if _id == 0:
# El primero checked por defecto
radio_button.setChecked(True)
container.addWidget(group)
self.line_location = QLineEdit()
container.addWidget(self.line_location)
hbox = QHBoxLayout()
hbox.addWidget(QLabel(self.tr("Archivo del Proyecto: ")))
self._project_filename = QLineEdit()
hbox.addWidget(self._project_filename)
container.addLayout(hbox)
hbox = QHBoxLayout()
hbox.addWidget(QLabel(self.tr("Archivo resultante: ")))
self._resulting_filename = QLineEdit()
hbox.addWidget(self._resulting_filename)
container.addLayout(hbox)
# Conexiones
self.connect(button_group, SIGNAL("buttonClicked(int)"),
self._update_location)
self.connect(self.line_name, SIGNAL("textChanged(const QString&)"),
self._on_project_name_changed)
self.connect(self.line_name, SIGNAL("textChanged(const QString&)"),
lambda: self.emit(SIGNAL("completeChanged()")))
self._update_location(0)
示例9: __init__
def __init__(self, model, key, radiobuttonswithvalues):
Mapping.__init__(self, model, key)
self.radiobuttonswithvalues = radiobuttonswithvalues
buttongroup = None
for radiobutton, correspondingvalue in self.radiobuttonswithvalues.items():
# Tiresome extra setup to ensure that exactly one button is ever checked
if buttongroup is None:
buttongroup = QButtonGroup(radiobutton.parent())
buttongroup.addButton(radiobutton)
# NB: default-argument indirection below to solve closure capture issues
radiobutton.connect(radiobutton, SIGNAL("clicked()"), lambda cv=correspondingvalue: self.updateModelValue(cv))
示例10: RadioBooleanFilter
class RadioBooleanFilter(QWidget, Control):
""" Boolean filter (Only/Exclude)
"""
def __init__(self, tree, dataset, master, parent=None):
QWidget.__init__(self, parent)
Control.__init__(self, tree, dataset, master)
self.setLayout(QVBoxLayout())
self.buttonGroup = QButtonGroup(self)
self.values = []
for i, option in enumerate(tree.subelements_top("Option")):
rb = QRadioButton(option.displayName, self)
self.buttonGroup.addButton(rb)
self.buttonGroup.setId(rb, i)
self.layout().addWidget(rb)
self.values.append(option.value)
self.buttonGroup.button(0).setChecked(True)
def value(self):
return {"excluded": "%i" % self.buttonGroup.checkedId()}
def get_filter(self):
return self.tree.internalName, self.value()
def query(self):
return [("Filter", self.tree, self.value())]
def setControlValue(self, name, value):
for i, v in enumerate(self.values):
if v == value:
button = self.buttonGroup.button(i)
button.setChecked(True)
break
示例11: __init__
def __init__(self, parent, hex_widget):
utils.Dialog.__init__(self, parent, name='add_bookmark_dialog')
self.hexWidget = hex_widget
self.ui = Ui_AddBookmarkDialog()
self.ui.setupUi(self)
self._canCreateBookmark = True
self._isColorChoosen = False
self._groupMark = QButtonGroup()
self._groupMark.addButton(self.ui.btnMarkCaret)
self._groupMark.addButton(self.ui.btnMarkSelection)
if self.hexWidget.hasSelection:
self.ui.btnMarkSelection.setChecked(True)
else:
self.ui.btnMarkCaret.setChecked(True)
self._groupBind = QButtonGroup()
self._groupBind.addButton(self.ui.btnBoundToPosition)
self._groupBind.addButton(self.ui.btnBoundToData)
self.ui.btnBoundToData.setChecked(True)
self._bookmarkColor = QColor(Qt.red)
self.ui.btnMarkCaret.toggled.connect(self._updateOk)
self.ui.btnMarkSelection.toggled.connect(self._updateOk)
self.ui.btnMarkCaret.toggled.connect(self._updateColor)
self.ui.btnMarkSelection.toggled.connect(self._updateColor)
self.ui.btnSelectColor.clicked.connect(self._selectBookmarkColor)
self._updateOk()
bookmark_name = ''
if self._canCreateBookmark:
bookmark_range = self.createBookmark()
# find existing bookmarks that contain this one
c_bookmarks = [b for b in self.hexWidget.bookmarks if b.contains(bookmark_range)]
if c_bookmarks:
c_bookmark = min(c_bookmarks, key=lambda x: x.size)
bookmark_name = c_bookmark.name + '.'
if bookmark_name:
self.ui.txtName.setText(bookmark_name)
else:
bookmark_name = utils.tr('bookmark{0}').format(currentBookmarkIndex)
self.ui.txtName.setText(bookmark_name)
self.ui.txtName.selectAll()
self._updateColor()
示例12: add_node
def add_node(self, parentItem, path, type):
item = QTreeWidgetItem(parentItem)
item.setText(0, path_leaf(path))
buttonGroup = QButtonGroup()
isNewFile = type is "UNTRACKED"
isModifiedFile = type is "MODIFIED"
isMissing = type is "MISSING"
isDirectory = type is "DIR"
if isNewFile:
item.setText(1, type)
item.setForeground(1, QBrush(QColor(0, 255, 0)))
if isModifiedFile:
item.setText(1, type)
item.setForeground(1, QBrush(QColor(0, 0, 255)))
if isMissing:
item.setText(1, type)
item.setForeground(1, QBrush(QColor(255, 0, 0)))
if isDirectory:
for i in range(self.tree.columnCount()):
item.setBackground(i, QBrush(QColor(230, 230, 255)))
# must keep reference to buttonGroup for its callback to work
parent_data = self.retrieve_data(parentItem)
if parent_data != None:
path = os.path.join(parent_data[0], path)
self.attach_data(item, (path, buttonGroup, type))
for i in range(self.uncheckableColumns, self.tree.columnCount()):
if i == self.tree.columnCount() - 7 and isMissing:
continue # option to add not enabled for missing files
if i == self.tree.columnCount() - 4 and isNewFile:
continue # option to resolve not enabled for new files
if i == self.tree.columnCount() - 3 and not isMissing:
continue # option to stop tracking enabled only for missing files
if i == self.tree.columnCount() - 2 and not isNewFile:
continue # option to delete enabled only for untracked files
if i == self.tree.columnCount() - 2 and isDirectory:
continue # option to delete not enabled for directories, too dangerous
button = QRadioButton()
buttonGroup.addButton(button, i - self.uncheckableColumns) # id is the index
button.treeItem = item
self.tree.setItemWidget(item, i, button)
buttonGroup.buttonClicked.connect(self.tree_item_radio_clicked)
return item
示例13: __init__
def __init__(self, mode="DateTime"):
QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_datatimerpicker()
self.ui.setupUi(self)
self.group = QButtonGroup()
self.group.setExclusive(True)
self.group.addButton(self.ui.ambutton)
self.group.addButton(self.ui.pmbutton)
self.ui.ambutton.toggled.connect(self.isDirty)
self.ui.pmbutton.toggled.connect(self.isDirty)
self.ui.datepicker.selectionChanged.connect(self.isDirty)
self.ui.hourpicker.itemSelectionChanged.connect(self.isDirty)
self.ui.minutepicker.itemSelectionChanged.connect(self.isDirty)
self.ui.buttonBox.accepted.connect(self.accept)
self.ui.buttonBox.rejected.connect(self.reject)
self.ui.setasnowbutton.pressed.connect(self.setAsNow)
self.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint)
if mode == "Date":
self.ui.hourpicker.hide()
self.ui.minutepicker.hide()
self.ui.ampmbutton.hide()
elif mode == "Time":
self.ui.datepicker.hide()
示例14: __init__
def __init__(self):
"""
Constructor
"""
ConfigurationPageBase.__init__(self)
self.setupUi(self)
self.setObjectName("HelpViewersPage")
self.helpViewerGroup = QButtonGroup()
self.helpViewerGroup.addButton(self.helpBrowserButton)
self.helpViewerGroup.addButton(self.qtAssistantButton)
self.helpViewerGroup.addButton(self.webBrowserButton)
self.helpViewerGroup.addButton(self.customViewerButton)
self.customViewerCompleter = E4FileCompleter(self.customViewerEdit)
# set initial values
hvId = Preferences.getHelp("HelpViewerType")
if hvId == 1:
self.helpBrowserButton.setChecked(True)
elif hvId == 2:
self.qtAssistantButton.setChecked(True)
elif hvId == 3:
self.webBrowserButton.setChecked(True)
else:
self.customViewerButton.setChecked(True)
self.customViewerEdit.setText(\
Preferences.getHelp("CustomViewer"))
示例15: __init__
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# Widgets, layouts and signals
self._group = QButtonGroup()
layout = QGridLayout()
layout.setSpacing(0)
## Element
for z, position in _ELEMENT_POSITIONS.items():
widget = ElementPushButton(z)
widget.setStyle(QStyleFactory.create("windows"))
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.AlignRight)
layout.addWidget(QLabel('*'), 8, 2, Qt.AlignRight)
layout.addWidget(QLabel('**'), 6, 2, Qt.AlignRight)
layout.addWidget(QLabel('**'), 9, 2, Qt.AlignRight)
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)