本文整理汇总了Python中PyQt4.QtGui.QButtonGroup.button方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.button方法的具体用法?Python QButtonGroup.button怎么用?Python QButtonGroup.button使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.button方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RadioBooleanFilter
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
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
示例2: TransformationModule
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
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
)
}
示例3: TokenizerModule
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
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)
}
示例4: QuestionDlg
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
#.........这里部分代码省略.........
self.connect(self.w1title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
self.connect(self.btn_start2, SIGNAL("clicked()"), self.startChoice)
self.connect(self.w2title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
def initStudent(self):
cur = conn.cursor()
cur.execute("update student set wrongquestions=0")
conn.commit()
cur.execute("update student set rightquestions=0")
conn.commit()
# cur.execute("select * from student")
# print(cur.fetchall())
cur.close()
def deleteTmpdata(self):
cur = conn.cursor()
cur.execute("delete from tmprecord where 1=1" )
conn.commit()
cur.close()
def changeTab(self, curtab):
if curtab == 0:
strwhere = " and studentsn like '03%' "
elif curtab == 1:
strwhere = " and studentsn like '04%' "
self.lstchoices = []
self.threadcounter = 0
cur = conn.cursor()
cur.execute("select studentsn from student where 1=1 " + strwhere)
self.studentSnlst = cur.fetchall()
for isn in self.studentSnlst:
self.btngroup.button(int(isn[0])).setStyleSheet("border-image: url(image/ex_stu.png); color:dark;")
self.btngroup.button(int(isn[0])).setIcon(QIcon())
# self.btngroup.buttons()[i].setStyleSheet("background-color: rgb(120,220,220);")
# self.btngroup.buttons()[i].setStyleSheet("border-image: url(image/ex_stu.png);")
curmenu = self.btngroup.button(int(isn[0])).menu()
curmenu.actions()[0].setEnabled(True)
curmenu.actions()[1].setEnabled(True)
cur.close()
def mousePressEvent(self, event):
self.offset = event.pos()
# print(self.offset)
def mouseMoveEvent(self, event):
x=event.globalX()
y=event.globalY()
x_w = self.offset.x()
y_w = self.offset.y()
self.move(x-x_w, y-y_w)
def genOneTab(self, tabtitle="", tabbtn="", tabnums="", strwhere = "where studentsn like '03%' "):
# tabtitle.setFixedHeight(40)
# tabtitle.setFixedWidth(160)
tabtitle.setFont(QFont('Courier New', 20))
tabtitle.setStyleSheet("border: 3px solid blue;\
border-radius: 6px; \
padding: 1px 18px 1px 20px;\
min-width: 8em;")
model = tabtitle.model()
for row in ["随堂演板", "随堂提问"]:
item = QStandardItem(str(row))
item.setForeground(QColor('blue'))
item.setBackground(QColor(0,200,50, 130))
示例5: LdapWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
#.........这里部分代码省略.........
self.signalModified()
def setUri(self, uris_text):
self.specific_config.setUri(self.readString(uris_text))
self.signalModified()
self.numeric_uri_warning.setVisible(ip_in_ldapuri(self.specific_config.uri))
def setUser(self, user):
self.specific_config.user = self.readString(user)
def setPassword(self, password):
self.specific_config.password = self.readString(password)
def setDnUsers(self, dn):
self.specific_config.dn_users = self.readString(dn)
def setDnGroups(self, dn):
self.specific_config.dn_groups = self.readString(dn)
def mkSslBox(self):
group = QGroupBox(tr("Check server certificate"))
group.setCheckable(True)
box = QVBoxLayout(group)
#id 0
nupki = QRadioButton(tr("Upload certificate"))
#id 1
custom = QRadioButton(tr("Use an internal PKI"))
hbox = QHBoxLayout()
box.addLayout(hbox)
self.nupki_or_custom = QButtonGroup()
self.connect(self.nupki_or_custom, SIGNAL('buttonClicked(int)'), self.toggleCustomOrNupki)
for index, radio in enumerate((custom, nupki)):
hbox.addWidget(radio)
self.nupki_or_custom.addButton(radio, index)
self.file_selector_widget = QWidget()
vbox = QVBoxLayout(self.file_selector_widget)
selector_label = QLabel(tr("Manually uploaded LDAP certificate"))
vbox.addWidget(selector_label)
add_cert_trigger = AddButton(text=tr("Upload a certificate"))
vbox.addWidget(add_cert_trigger)
vbox.addWidget(separator())
self.has_cert_message = QLabel(
tr("There is no manually uploaded server certificate")
)
self.del_cert = RemButton(
tr("Delete certificate file from server")
)
vbox.addWidget(self.has_cert_message)
vbox.addWidget(self.del_cert)
self.connect(add_cert_trigger, SIGNAL('clicked()'), self.upload_server_cert)
self.connect(self.del_cert, SIGNAL('clicked()'), self.delete_server_cert)
self.nupki_message = MessageArea()
self.nupki_message.setMessage(tr("Warning"),
tr(
"There is no server certificate in the internal PKI.<br/>"
"Please import or generate one using an internal PKI."
)
)
示例6: QuestionDlg
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
#.........这里部分代码省略.........
entry4 = popMenu.addAction("导出...")
entry4.setFont(menufont)
self.connect(entry4,SIGNAL('triggered()'), self.exportNotice)
self.btnSysMenu.setMenu(popMenu)
self.btnSysMenu.setStyleSheet("QPushButton::menu-indicator {image: url('image/sysmenu.png');subcontrol-position: right center;} ")
# self.btnSysMenu.setStyleSheet("background-color:rgb(0,100,0); color:rgb(255,255,255);")
authorinfo = QLabel(self.tabWidget)
# authorinfo.setToolTip("关闭")
authorinfo.setText("程序设计:汕头市大华路第一小学 赵小娜,有任何问题请反馈至[email protected]。")
authorinfo.setGeometry(20, 665, 470, 26)
authorinfo.setFont(QFont('Courier New'))
authorinfo.setStyleSheet("background-color:rgba(255, 255, 255,160); font-size:12px;border: 1px solid rgb(60,200,255,200);color:rgba(0,0,0,220);border-radius:12px;")
self.setWindowTitle("课堂随机提问")
self.setWindowIcon(QIcon("image/start.ico"))
self.setGeometry(100, 20, 940, 700)
# self.changeTab()
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
self.btn_start.setMyarg('start')
# print(self.btn_start.getMyarg())
self.connect(self.btn_start, SIGNAL("clicked()"), self.startChoice)
# self.connect(self.w1title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
# self.connect(self.btn_start2, SIGNAL("clicked()"), self.startChoice)
# self.connect(self.w2title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
self.btngroup.buttonClicked[int].connect(self.btns_click)
# self.connect(self.btn_start, SIGNAL("myslot(PyQt_PyObject)"), self.myslot)
# self.connect(self.btngroup, SIGNAL("buttonClicked(int)"), lambda:self.btns_click())
def myslot(self, text):
# print(text, self.dict_choices)
self.g_curbtn = text
if self.g_curbtn not in self.dict_choices:
self.btnSysMenu.setFocus()
return
# print(self.btngroup.button(int(self.g_curbtn)).parent())
# print(type(self.btngroup.button(int(self.g_curbtn)).parentWidget()))
pos = self.btngroup.button(int(self.g_curbtn)).parent().mapToGlobal(self.btngroup.button(int(self.g_curbtn)).pos())
width = self.btngroup.button(int(self.g_curbtn)).rect().height()
# print("-----", pos, width)
pos.setY(pos.y()+width-5)
indx = 0
for istate in self.dict_choices[self.g_curbtn]:
if istate == '1':
self.popMenu.actions()[indx].setEnabled(True)
elif istate == '0':
self.popMenu.actions()[indx].setEnabled(False)
indx += 1
self.popMenu.exec_(pos)
self.btnSysMenu.setFocus()
# def on_context_menu(self, point):
# print(point)
# self.popMenu.exec_(self.button.mapToGlobal(point))
def btns_click(self, btnid):
# curclassname = self.tabWidget.tabText(0)
示例7: DefaultSelectParameterWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
class DefaultSelectParameterWidget(SelectParameterWidget):
"""Widget class for Default Select Parameter."""
def __init__(self, parameter, parent=None):
"""Constructor
:param parameter: A DefaultSelectParameter object.
:type parameter: DefaultSelectParameter
"""
super(DefaultSelectParameterWidget, self).__init__(parameter, parent)
self.default_layout = QHBoxLayout()
self.radio_button_layout = QHBoxLayout()
self.radio_button_widget = QWidget()
self.default_label = QLabel(tr('Default'))
# Create radio button group
self.default_input_button_group = QButtonGroup()
# Define string enabler for radio button
self.radio_button_enabler = self.input.itemData(0, Qt.UserRole)
for i in range(len(self._parameter.default_labels)):
if '%s' in self._parameter.default_labels[i]:
label = (
self._parameter.default_labels[i] %
self._parameter.default_values[i])
else:
label = self._parameter.default_labels[i]
radio_button = QRadioButton(label)
self.radio_button_layout.addWidget(radio_button)
self.default_input_button_group.addButton(radio_button, i)
if self._parameter.default_value == \
self._parameter.default_values[i]:
radio_button.setChecked(True)
# Create double spin box for custom value
self.custom_value = QDoubleSpinBox()
if self._parameter.default_values[-1]:
self.custom_value.setValue(self._parameter.default_values[-1])
has_min = False
if self._parameter.minimum is not None:
has_min = True
self.custom_value.setMinimum(self._parameter.minimum)
has_max = False
if self._parameter.maximum is not None:
has_max = True
self.custom_value.setMaximum(self._parameter.maximum)
if has_min and has_max:
step = (self._parameter.maximum - self._parameter.minimum) / 100.0
self.custom_value.setSingleStep(step)
self.radio_button_layout.addWidget(self.custom_value)
self.toggle_custom_value()
# Reset the layout
self.input_layout.setParent(None)
self.help_layout.setParent(None)
self.label.setParent(None)
self.inner_input_layout.setParent(None)
self.input_layout = QGridLayout()
self.input_layout.setSpacing(0)
self.input_layout.addWidget(self.label, 0, 0)
self.input_layout.addLayout(self.inner_input_layout, 0, 1)
self.input_layout.addWidget(self.default_label, 1, 0)
self.input_layout.addLayout(self.radio_button_layout, 1, 1)
self.main_layout.addLayout(self.input_layout)
self.main_layout.addLayout(self.help_layout)
# check every added combobox, it could have been toggled by
# the existing keyword
self.toggle_input()
# Connect
# noinspection PyUnresolvedReferences
self.input.currentIndexChanged.connect(self.toggle_input)
self.default_input_button_group.buttonClicked.connect(
self.toggle_custom_value)
def raise_invalid_type_exception(self):
message = 'Expecting element type of %s' % (
self._parameter.element_type.__name__)
err = ValueError(message)
return err
def get_parameter(self):
"""Obtain list parameter object from the current widget state.
:returns: A DefaultSelectParameter from the current state of widget.
"""
current_index = self.input.currentIndex()
selected_value = self.input.itemData(current_index, Qt.UserRole)
if hasattr(selected_value, 'toPyObject'):
#.........这里部分代码省略.........
示例8: GroupSelectParameterWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
class GroupSelectParameterWidget(GenericParameterWidget):
"""Widget class for Group Select Parameter."""
def __init__(self, parameter, parent=None):
"""Constructor.
:param parameter: A GroupSelectParameter object.
:type parameter: GroupSelectParameter
"""
QWidget.__init__(self, parent)
self._parameter = parameter
# Store spin box
self.spin_boxes = {}
# Create elements
# Label (name)
self.label = QLabel(self._parameter.name)
# Layouts
self.main_layout = QVBoxLayout()
self.input_layout = QVBoxLayout()
# _inner_input_layout must be filled with widget in the child class
self.inner_input_layout = QVBoxLayout()
self.radio_button_layout = QGridLayout()
# Create radio button group
self.input_button_group = QButtonGroup()
# List widget
self.list_widget = QListWidget()
self.list_widget.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.list_widget.setDragDropMode(QAbstractItemView.DragDrop)
self.list_widget.setDefaultDropAction(Qt.MoveAction)
self.list_widget.setEnabled(False)
self.list_widget.setSizePolicy(
QSizePolicy.Maximum, QSizePolicy.Expanding)
for i, key in enumerate(self._parameter.options):
value = self._parameter.options[key]
radio_button = QRadioButton(value.get('label'))
self.radio_button_layout.addWidget(radio_button, i, 0)
if value.get('type') == SINGLE_DYNAMIC:
double_spin_box = QDoubleSpinBox()
self.radio_button_layout.addWidget(double_spin_box, i, 1)
double_spin_box.setValue(value.get('value', 0))
double_spin_box.setMinimum(
value.get('constraint', {}).get('min', 0))
double_spin_box.setMaximum(value.get(
'constraint', {}).get('max', 1))
double_spin_box.setSingleStep(
value.get('constraint', {}).get('step', 0.01))
step = double_spin_box.singleStep()
if step > 1:
precision = 0
else:
precision = len(str(step).split('.')[1])
if precision > 3:
precision = 3
double_spin_box.setDecimals(precision)
self.spin_boxes[key] = double_spin_box
# Enable spin box depends on the selected option
if self._parameter.selected == key:
double_spin_box.setEnabled(True)
else:
double_spin_box.setEnabled(False)
elif value.get('type') == STATIC:
static_value = value.get('value', 0)
if static_value is not None:
self.radio_button_layout.addWidget(
QLabel(str(static_value)), i, 1)
elif value.get('type') == MULTIPLE_DYNAMIC:
selected_fields = value.get('value', [])
if self._parameter.selected == key:
self.list_widget.setEnabled(True)
else:
self.list_widget.setEnabled(False)
self.input_button_group.addButton(radio_button, i)
if self._parameter.selected == key:
radio_button.setChecked(True)
# Help text
self.help_label = QLabel(self._parameter.help_text)
self.help_label.setSizePolicy(
QSizePolicy.Maximum, QSizePolicy.Expanding)
self.help_label.setWordWrap(True)
self.help_label.setAlignment(Qt.AlignTop)
self.inner_input_layout.addLayout(self.radio_button_layout)
self.inner_input_layout.addWidget(self.list_widget)
# Put elements into layouts
self.input_layout.addWidget(self.label)
self.input_layout.addLayout(self.inner_input_layout)
#.........这里部分代码省略.........
示例9: QuestionDlg
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
#.........这里部分代码省略.........
menufont = QFont("宋体", 10)
popMenu = QMenu(self)
entry1 = popMenu.addAction("初始化")
entry1.setFont(menufont)
self.connect(entry1,SIGNAL('triggered()'), self.initStudent)
entry2 = popMenu.addAction("清除提问人员")
entry2.setFont(menufont)
self.connect(entry2,SIGNAL('triggered()'), self.deleteTmpdata)
self.btnSysMenu.setMenu(popMenu)
self.btnSysMenu.setStyleSheet("QPushButton::menu-indicator {image: url('image/sysmenu.png');subcontrol-position: right center;} ")
# self.btnSysMenu.setStyleSheet("background-color:rgb(0,100,0); color:rgb(255,255,255);")
authorinfo = QLabel(tabWidget)
# authorinfo.setToolTip("关闭")
authorinfo.setText("汕头市大华一小:赵小娜")
authorinfo.setGeometry(20, 665, 235, 26)
authorinfo.setStyleSheet("background-color:rgba(255, 255, 255,160); font-size:20px;border: 1px solid rgb(60,200,255,200);color:rgba(0,0,0,220);border-radius:12px;")
self.setWindowTitle("课堂随机提问")
self.setWindowIcon(QIcon("image/start.ico"))
self.setGeometry(100, 20, 740, 700)
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
self.btn_start.setMyarg('start')
# print(self.btn_start.getMyarg())
self.connect(self.btn_start, SIGNAL("clicked()"), self.startChoice)
# self.connect(self.w1title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
self.connect(self.btn_start2, SIGNAL("clicked()"), self.startChoice)
# self.connect(self.w2title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
self.btngroup.buttonClicked[int].connect(self.btns_click)
# self.connect(self.btn_start, SIGNAL("myslot(PyQt_PyObject)"), self.myslot)
# self.connect(self.btngroup, SIGNAL("buttonClicked(int)"), lambda:self.btns_click())
def myslot(self, text):
# print(text)
self.g_curbtn = text
if self.g_curbtn not in self.dict_choices:
self.btnSysMenu.setFocus()
return
# print(self.btngroup.button(int(self.g_curbtn)).parent())
# print(type(self.btngroup.button(int(self.g_curbtn)).parentWidget()))
pos = self.btngroup.button(int(self.g_curbtn)).parent().mapToGlobal(self.btngroup.button(int(self.g_curbtn)).pos())
width = self.btngroup.button(int(self.g_curbtn)).rect().height()
# print("-----", pos, width)
pos.setY(pos.y()+width-5)
indx = 0
for istate in self.dict_choices[self.g_curbtn]:
if istate == '1':
self.popMenu.actions()[indx].setEnabled(True)
elif istate == '0':
self.popMenu.actions()[indx].setEnabled(False)
indx += 1
self.popMenu.exec_(pos)
self.btnSysMenu.setFocus()
# def on_context_menu(self, point):
# print(point)
# self.popMenu.exec_(self.button.mapToGlobal(point))
def btns_click(self, btnid):
# print(self.btngroup.button(btnid).rect())
示例10: DefaultValueParameterWidget
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
class DefaultValueParameterWidget(GenericParameterWidget):
"""Widget class for Default Value Parameter."""
def __init__(self, parameter, parent=None):
"""Constructor.
:param parameter: A DefaultValueParameter object.
:type parameter: DefaultValueParameter
"""
super(DefaultValueParameterWidget, self).__init__(parameter, parent)
self.radio_button_layout = QHBoxLayout()
# Create radio button group
self.input_button_group = QButtonGroup()
for i in range(len(self._parameter.labels)):
if '%s' in self._parameter.labels[i]:
label = (
self._parameter.labels[i] %
self._parameter.options[i])
else:
label = self._parameter.labels[i]
radio_button = QRadioButton(label)
self.radio_button_layout.addWidget(radio_button)
self.input_button_group.addButton(radio_button, i)
if self._parameter.value == \
self._parameter.options[i]:
radio_button.setChecked(True)
# Create double spin box for custom value
self.custom_value = QDoubleSpinBox()
self.custom_value.setSingleStep(0.1)
if self._parameter.options[-1]:
self.custom_value.setValue(self._parameter.options[-1])
self.radio_button_layout.addWidget(self.custom_value)
self.toggle_custom_value()
self.inner_input_layout.addLayout(self.radio_button_layout)
# Connect
# noinspection PyUnresolvedReferences
self.input_button_group.buttonClicked.connect(
self.toggle_custom_value)
def raise_invalid_type_exception(self):
"""Raise invalid type."""
message = 'Expecting element type of %s' % (
self._parameter.element_type.__name__)
err = ValueError(message)
return err
def get_parameter(self):
"""Obtain list parameter object from the current widget state.
:returns: A DefaultValueParameter from the current state of widget
:rtype: DefaultValueParameter
"""
radio_button_checked_id = self.input_button_group.checkedId()
# No radio button checked, then default value = None
if radio_button_checked_id == -1:
self._parameter.value = None
# The last radio button (custom) is checked, get the value from the
# line edit
elif radio_button_checked_id == len(self._parameter.options) - 1:
self._parameter.options[radio_button_checked_id] = \
self.custom_value.value()
self._parameter.value = self.custom_value.value()
else:
self._parameter.value = self._parameter.options[
radio_button_checked_id]
return self._parameter
def set_value(self, value):
"""Set value by item's string.
:param value: The value.
:type value: str, int
:returns: True if success, else False.
:rtype: bool
"""
# Find index of choice
try:
value_index = self._parameter.options.index(value)
self.input_button_group.button(value_index).setChecked(True)
except ValueError:
last_index = len(self._parameter.options) - 1
self.input_button_group.button(last_index).setChecked(
True)
self.custom_value.setValue(value)
self.toggle_custom_value()
def toggle_custom_value(self):
#.........这里部分代码省略.........
示例11: create_rows
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
def create_rows(self, layout, sarea):
u"""Build the rows of the dialog box"""
play_button_group = QButtonGroup(sarea)
old_play_button_group = QButtonGroup(sarea)
for num, entry in enumerate(self.entries_list, 2):
tt_text = self.build_text_help_label(entry)
ico_label = QLabel('', sarea)
ico_label.setToolTip(tt_text)
if entry.icon:
ico_label.setPixmap(QPixmap.fromImage(entry.icon))
layout.addWidget(ico_label, num, 0)
tt_label = QLabel(entry.display_word, sarea)
tt_label.setToolTip(tt_text)
layout.addWidget(tt_label, num, 1)
if self.hide_text:
tt_label.hide()
# Play button.
t_play_button = QPushButton(sarea)
play_button_group.addButton(t_play_button, num-2)
t_play_button.setToolTip(self.play_help)
t_play_button.setIcon(QIcon(os.path.join(icons_dir, 'play.png')))
layout.addWidget(t_play_button, num, self.play_column)
if self.note[entry.audio_field_name]:
t_play_old_button = QPushButton(sarea)
old_play_button_group.addButton(t_play_old_button, num-2)
t_play_old_button.setIcon(
QIcon(os.path.join(icons_dir, 'play.png')))
if not self.hide_text:
t_play_old_button.setToolTip(
self.note[entry.audio_field_name])
else:
t_play_old_button.setToolTip(self.play_old_help_short)
layout.addWidget(t_play_old_button, num, self.play_old_column)
else:
dummy_label = QLabel('', sarea)
dummy_label.setToolTip(self.play_old_empty_line_help)
layout.addWidget(dummy_label, num, self.play_old_column)
# The group where we later look what to do:
t_button_group = QButtonGroup(sarea)
t_button_group.setExclusive(True)
# Now the four buttons
t_add_button = QPushButton(sarea)
t_add_button.setCheckable(True)
t_add_button.setFlat(True)
t_add_button.setToolTip(self.add_help_text_short)
t_add_button.setIcon(QIcon(os.path.join(icons_dir, 'add.png')))
layout.addWidget(t_add_button, num, self.add_column)
t_button_group.addButton(t_add_button, Action.Add)
t_keep_button = QPushButton(sarea)
t_keep_button.setCheckable(True)
t_keep_button.setFlat(True)
t_keep_button.setToolTip(self.keep_help_text_short)
t_keep_button.setIcon(QIcon(os.path.join(icons_dir, 'keep.png')))
layout.addWidget(t_keep_button, num, self.keep_column)
t_button_group.addButton(t_keep_button, Action.Keep)
t_delete_button = QPushButton(sarea)
t_delete_button.setCheckable(True)
t_delete_button.setFlat(True)
t_delete_button.setToolTip(self.delete_help_text_short)
t_delete_button.setIcon(
QIcon(os.path.join(icons_dir, 'delete.png')))
layout.addWidget(t_delete_button, num, self.delete_column)
t_button_group.addButton(t_delete_button, Action.Delete)
t_blacklist_button = QPushButton(sarea)
t_blacklist_button.setCheckable(True)
t_blacklist_button.setFlat(True)
t_blacklist_button.setToolTip(self.blacklist_help_text_short)
t_blacklist_button.setIcon(
QIcon(os.path.join(icons_dir, 'blacklist.png')))
if entry.entry_hash:
layout.addWidget(
t_blacklist_button, num, self.blacklist_column)
else:
t_blacklist_button.hide()
dummy_label_bl = QLabel('', sarea)
dummy_label_bl.setToolTip(self.blacklist_empty_line_help)
layout.addWidget(dummy_label_bl, num, self.blacklist_column)
t_button_group.button(entry.action).setChecked(True)
# New: check a button based on how good the downloader is.
t_button_group.addButton(t_blacklist_button, Action.Blacklist)
self.buttons_groups.append(t_button_group)
play_button_group.buttonClicked.connect(
lambda button: play(
self.entries_list[play_button_group.id(button)].file_path))
# N.B.: anki.sound.play() plays files from anywhere, not just
# from the colection.media folder. We should be good,
# here. (This behaviour may be a security risk, idk.)
old_play_button_group.buttonClicked.connect(
lambda button: playFromText(
self.note[
self.entries_list[
old_play_button_group.id(button)].audio_field_name]))
示例12: AuthenticationFrontend
# 需要导入模块: from PyQt4.QtGui import QButtonGroup [as 别名]
# 或者: from PyQt4.QtGui.QButtonGroup import button [as 别名]
class AuthenticationFrontend(ScrollArea):
COMPONENT = 'auth_cert'
LABEL = tr('Authentication server')
REQUIREMENTS = ('auth_cert',)
ICON = ':/icons/auth_protocol.png'
def __init__(self, client, parent):
self.__loading = True
ScrollArea.__init__(self)
self.mainwindow = parent
self.client = client
self.modified = False
self.qauthcertobject = QAuthCertObject.getInstance()
frame = QFrame(self)
layout = QVBoxLayout(frame)
layout.addWidget(QLabel('<H1>%s</H1>' % tr('Authentication server') ))
head_box = QGroupBox(tr("How the authentication server handles certificates"))
head = QFormLayout(head_box)
self.strictCheckBox = QCheckBox()
head.addRow(QLabel(tr("Strict mode (check the client's certificate against the installed CA)")), self.strictCheckBox)
self.connect(self.strictCheckBox, SIGNAL('toggled(bool)'),
self.setStrict)
self.cl_auth_box = QGroupBox(tr("Client authentication with a certificate is"))
cl_auth = QVBoxLayout(self.cl_auth_box)
self.auth_by_cert = QButtonGroup()
self.auth_by_cert.setExclusive(True)
self.mainwindow.writeAccessNeeded(self.strictCheckBox)
labels = [tr('forbidden'), tr('allowed'), tr('mandatory')]
for index, label_button in enumerate(labels):
button = QRadioButton(label_button)
self.auth_by_cert.addButton(button, index)
cl_auth.addWidget(button)
self.mainwindow.writeAccessNeeded(button)
self.auth_by_cert.button(0).setChecked(Qt.Checked)
self.connect(self.auth_by_cert, SIGNAL('buttonClicked(int)'),
self.auth_by_cert_modified)
# Captive portal
# --------------
self.portal_groupbox = QGroupBox(tr("Captive portal"))
self.portal_groupbox.setLayout(QVBoxLayout())
# Enabled checkbox:
self.portal_checkbox = QCheckBox(tr("Enable captive portal"))
self.connect(self.portal_checkbox, SIGNAL('toggled(bool)'),
self.setPortalEnabled)
# List of networks redirected to the captive portal:
self.portal_nets_groupbox = QGroupBox(
tr("Networks handled by the captive portal"))
self.portal_nets_groupbox.setLayout(QVBoxLayout())
self.portal_nets_edit = NetworkListEdit()
self.connect(self.portal_nets_edit, SIGNAL('textChanged()'), self.setPortalNets)
self.portal_nets_groupbox.layout().addWidget(self.portal_nets_edit)
# Pack the widgets:
for widget in (self.portal_checkbox, self.portal_nets_groupbox):
self.portal_groupbox.layout().addWidget(widget)
self.mainwindow.writeAccessNeeded(self.portal_checkbox)
self.mainwindow.writeAccessNeeded(self.portal_nets_edit)
if not EDENWALL:
self.portal_groupbox.setVisible(False)
# authentication server
self.pki_widget = PkiEmbedWidget(self.client, self, 'auth_cert', PkiEmbedWidget.SHOW_ALL|PkiEmbedWidget.CRL_OPTIONAL, self.setModified)
self.mainwindow.writeAccessNeeded(self.pki_widget)
layout.addWidget(head_box)
layout.addWidget(self.cl_auth_box)
layout.addWidget(self.portal_groupbox)
layout.addWidget(self.pki_widget)
layout.addStretch()
self.setWidget(frame)
self.setWidgetResizable(True)
self.resetConf()
self.__loading = False
def setModified(self, isModified=True, message=""):
if self.__loading:
return
if isModified:
self.modified = True
self.mainwindow.setModified(self, True)
if message:
self.mainwindow.addToInfoArea(message)
else:
self.modified = False
#.........这里部分代码省略.........