本文整理汇总了Python中PyQt5.QtWidgets.QButtonGroup.id方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.id方法的具体用法?Python QButtonGroup.id怎么用?Python QButtonGroup.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GSideToolbar
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import id [as 别名]
class GSideToolbar(QWidget):
selectionChanged = pyqtSignal(str)
def __init__(self, buttons):
super().__init__()
self.selectedId = None
self.mainLayout = QVBoxLayout(self)
self.buttonGroup = QButtonGroup()
self.buttons = {}
for button in buttons:
b = QPushButton(button.name)
self.buttonGroup.addButton(b)
self.buttonGroup.setId(b, button.id)
self.buttons[button.id] = b
self.mainLayout.addWidget(b)
self.buttonGroup.buttonClicked.connect(self.buttonClicked)
self.mainLayout.addStretch()
def buttonState(self, state):
pass
def buttonClicked(self, button : QPushButton):
buttonId = self.buttonGroup.id(button)
buttonName = self.buttons[buttonId].text()
self.selectionChanged.emit(buttonName)
@staticmethod
def createButton(text, icon):
pass
示例2: SettingsDialog
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import id [as 别名]
class SettingsDialog(QDialog, Ui_Dialog):
def __init__(self, parent):
super().__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setupUi(self)
self.lineEdit_loginUsername.setText(app.settings.get("adapter-legacy", "username"))
self.lineEdit_loginPassword.setText(app.settings.get("adapter-legacy", "password"))
self.checkBox_autoLogin.setChecked(app.settings.getbool("legacy", "autologin"))
self.checkBox_autoStartFrontend.setChecked(app.autoStart)
if sys.platform == "linux":
self.checkBox_autoStartFrontend.setEnabled(True)
adapter = app.adapterManager[0]
# Xwared Management
managedBySystemd = adapter.daemonManagedBySystemd
managedByUpstart = adapter.daemonManagedByUpstart
managedByAutostart = adapter.daemonManagedByAutostart
self.radio_managedBySystemd.setChecked(managedBySystemd)
self.radio_managedByUpstart.setChecked(managedByUpstart)
self.radio_managedByAutostart.setChecked(managedByAutostart)
self.radio_managedByNothing.setChecked(
not (managedBySystemd or managedByUpstart or managedByAutostart))
initType = getInitType()
self.radio_managedBySystemd.setEnabled(initType == InitType.SYSTEMD)
self.radio_managedByUpstart.setEnabled(initType == InitType.UPSTART)
if not adapter.useXwared:
self.group_etmStartWhen.setEnabled(False)
self.group_initManaged.setEnabled(False)
self.btngrp_etmStartWhen = QButtonGroup()
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen1, 1)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen2, 2)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen3, 3)
if adapter.useXwared:
startEtmWhen = adapter.startEtmWhen
self.btngrp_etmStartWhen.button(startEtmWhen).setChecked(True)
# frontend
self.checkBox_enableDevelopersTools.setChecked(
app.settings.getbool("legacy", "enabledeveloperstools"))
self.checkBox_allowFlash.setChecked(app.settings.getbool("legacy", "allowflash"))
self.checkBox_minimizeToSystray.setChecked(
app.settings.getbool("frontend", "minimizetosystray"))
self.checkBox_closeToMinimize.setChecked(
app.settings.getbool("frontend", "closetominimize"))
self.checkBox_popNotifications.setChecked(
app.settings.getbool("frontend", "popnotifications"))
self.checkBox_notifyBySound.setChecked(
app.settings.getbool("frontend", "notifybysound"))
self.checkBox_showMonitorWindow.setChecked(
app.settings.getbool("frontend", "showmonitorwindow"))
self.spinBox_monitorFullSpeed.setValue(
app.settings.getint("frontend", "monitorfullspeed"))
# clipboard related
self.checkBox_watchClipboard.stateChanged.connect(self.slotWatchClipboardToggled)
self.checkBox_watchClipboard.setChecked(app.settings.getbool("frontend", "watchclipboard"))
self.slotWatchClipboardToggled(self.checkBox_watchClipboard.checkState())
self.plaintext_watchPattern.setPlainText(app.settings.get("frontend", "watchpattern"))
self.btn_addMount.clicked.connect(self.slotAddMount)
self.btn_removeMount.clicked.connect(self.slotRemoveMount)
# Mounts
self.setupMounts()
# backend setting is a different thing!
self.setupETM()
@pyqtSlot(int)
def slotWatchClipboardToggled(self, state):
self.plaintext_watchPattern.setEnabled(state)
@pyqtSlot()
def setupMounts(self):
adapter = app.adapterManager[0]
if not adapter.useXwared:
self.tab_mount.setEnabled(False)
return
self.table_mounts.setRowCount(0)
self.table_mounts.clearContents()
mountsMapping = app.adapterManager[0].mountsFaker.getMountsMapping()
for i, mount in enumerate(app.adapterManager[0].mountsFaker.mounts):
self.table_mounts.insertRow(i)
# drive1: the drive letter it should map to, by alphabetical order
drive1 = app.adapterManager[0].mountsFaker.driveIndexToLetter(i)
self.table_mounts.setItem(i, 0, QTableWidgetItem(drive1 + "\\TDDOWNLOAD"))
# mounts = ['/path/to/1', 'path/to/2', ...]
self.table_mounts.setItem(i, 1, QTableWidgetItem(mount))
# drive2: the drive letter it actually is assigned to
#.........这里部分代码省略.........
示例3: SettingsDialog
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import id [as 别名]
class SettingsDialog(QDialog, Ui_Dialog):
def __init__(self, parent):
super().__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setupUi(self)
self.lineEdit_loginUsername.setText(app.settings.get("account", "username"))
self.lineEdit_loginPassword.setText(app.settings.get("account", "password"))
self.checkBox_autoLogin.setChecked(app.settings.getbool("account", "autologin"))
self.checkBox_autoStartFrontend.setChecked(self.doesAutoStartFileExists())
self.checkBox_enableDevelopersTools.setChecked(
app.settings.getbool("frontend", "enabledeveloperstools"))
self.checkBox_allowFlash.setChecked(app.settings.getbool("frontend", "allowflash"))
self.checkBox_minimizeToSystray.setChecked(
app.settings.getbool("frontend", "minimizetosystray"))
self.checkBox_closeToMinimize.setChecked(
app.settings.getbool("frontend", "closetominimize"))
self.checkBox_popNotifications.setChecked(
app.settings.getbool("frontend", "popnotifications"))
self.checkBox_notifyBySound.setChecked(
app.settings.getbool("frontend", "notifybysound"))
self.checkBox_showMonitorWindow.setChecked(
app.settings.getbool("frontend", "showmonitorwindow"))
self.spinBox_monitorFullSpeed.setValue(
app.settings.getint("frontend", "monitorfullspeed"))
# clipboard related
self.checkBox_watchClipboard.stateChanged.connect(self.slotWatchClipboardToggled)
self.checkBox_watchClipboard.setChecked(app.settings.getbool("frontend", "watchclipboard"))
self.slotWatchClipboardToggled(self.checkBox_watchClipboard.checkState())
self.plaintext_watchPattern.setPlainText(app.settings.get("frontend", "watchpattern"))
self.btngrp_etmStartWhen = QButtonGroup()
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen1, 1)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen2, 2)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen3, 3)
try:
startEtmWhen = callXwaredInterface("getStartEtmWhen")
self.btngrp_etmStartWhen.button(startEtmWhen).setChecked(True)
except SocketDoesntExist:
self.group_etmStartWhen.setEnabled(False)
self.btn_addMount.clicked.connect(self.slotAddMount)
self.btn_removeMount.clicked.connect(self.slotRemoveMount)
self.btn_refreshMount.clicked.connect(self.setupMounts)
# Mounts
self.setupMounts()
# backend setting is a different thing!
self.setupETM()
@staticmethod
def doesAutoStartFileExists():
return os.path.lexists(constants.FRONTEND_AUTOSTART_FILE)
@pyqtSlot(int)
def slotWatchClipboardToggled(self, state):
# disable pattern settings, before
# 1. complete patterns
# 2. test glib key file compatibility
self.plaintext_watchPattern.setReadOnly(True)
self.plaintext_watchPattern.setEnabled(state)
@pyqtSlot()
def setupMounts(self):
self.table_mounts.setRowCount(0)
self.table_mounts.clearContents()
permissionCheckResult = app.mountsFaker.permissionCheck()
permissionCheckFailed = ["无法获得检测权限。运行{}查看原因。".format(constants.PERMISSIONCHECK)]
mountsMapping = app.mountsFaker.getMountsMapping()
for i, mount in enumerate(app.mountsFaker.mounts):
# mounts = ['/path/to/1', 'path/to/2', ...]
self.table_mounts.insertRow(i)
self.table_mounts.setItem(i, 0, QTableWidgetItem(mount))
# drive1: the drive letter it should map to, by alphabetical order
drive1 = chr(ord('C') + i) + ":"
self.table_mounts.setItem(i, 1, QTableWidgetItem(drive1))
# drive2: the drive letter it actually is assigned to
drive2 = mountsMapping.get(mount, "无")
# check 1: permission
errors = permissionCheckResult.get(mount, permissionCheckFailed)
# check 2: mapping
if drive1 != drive2:
errors.append(
"警告:盘符映射在'{actual}',而不是'{should}'。需要重启后端修复。".format(
actual = drive2,
should = drive1))
brush = QBrush()
if errors:
brush.setColor(Qt.red)
errString = "\n".join(errors)
else:
#.........这里部分代码省略.........
示例4: create_rows
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import id [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]))
示例5: SettingsDialog
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import id [as 别名]
class SettingsDialog(QDialog, Ui_Dialog):
def __init__(self, parent):
super().__init__(parent)
self.setWindowModality(Qt.WindowModal)
self.setAttribute(Qt.WA_DeleteOnClose)
self.mainWin = parent
self.setupUi(self)
self.lineEdit_loginUsername.setText(self.settings.get("account", "username"))
self.lineEdit_loginPassword.setText(self.settings.get("account", "password"))
self.checkBox_autoLogin.setChecked(self.settings.getbool("account", "autologin"))
self.checkBox_enableDevelopersTools.setChecked(
self.settings.getbool("frontend", "enabledeveloperstools"))
self.checkBox_allowFlash.setChecked(self.settings.getbool("frontend", "allowflash"))
self.checkBox_minimizeToSystray.setChecked(self.settings.getbool("frontend", "minimizetosystray"))
self.checkBox_closeToMinimize.setChecked(self.settings.getbool("frontend", "closetominimize"))
self.checkBox_popNotifications.setChecked(self.settings.getbool("frontend", "popnotifications"))
self.checkBox_notifyBySound.setChecked(self.settings.getbool("frontend", "notifybysound"))
self.checkBox_showMonitorWindow.setChecked(self.settings.getbool("frontend", "showmonitorwindow"))
self.spinBox_monitorFullSpeed.setValue(self.settings.getint("frontend", "monitorfullspeed"))
# clipboard related
self.checkBox_watchClipboard.stateChanged.connect(self.slotWatchClipboardToggled)
self.checkBox_watchClipboard.setChecked(self.settings.getbool("frontend", "watchclipboard"))
self.slotWatchClipboardToggled(self.checkBox_watchClipboard.checkState())
self.plaintext_watchPattern.setPlainText(self.settings.get("frontend", "watchpattern"))
from PyQt5.QtWidgets import QButtonGroup
self.btngrp_etmStartWhen = QButtonGroup()
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen1, 1)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen2, 2)
self.btngrp_etmStartWhen.addButton(self.radio_backendStartWhen3, 3)
self.btngrp_etmStartWhen.button(self.settings.getint("xwared", "startetmwhen")).setChecked(True)
self.accepted.connect(self.writeSettings)
self.btn_addMount.clicked.connect(self.slotAddMount)
self.btn_removeMount.clicked.connect(self.slotRemoveMount)
self.btn_refreshMount.clicked.connect(self.setupMounts)
# Mounts
self.setupMounts()
# backend setting is a different thing!
self.setupETM()
# shorthand
@property
def settings(self):
return self.mainWin.settings
# shorthand ends
@staticmethod
def permissionCheck():
import re
ansiEscape = re.compile(r'\x1b[^m]*m')
import subprocess
with subprocess.Popen([constants.PERMISSIONCHECK], stdout = subprocess.PIPE, stderr = subprocess.PIPE) as proc:
output = proc.stdout.read().decode("utf-8")
output = ansiEscape.sub('', output)
lines = output.split("\n")
prevLine = None
currMount = None
result = {}
for line in lines:
if len(line.strip()) == 0:
continue
if all(map(lambda c: c == '=', line)):
if currMount:
result[currMount] = result[currMount][:-1]
result[prevLine] = []
currMount = prevLine
continue
if currMount:
if line != "正常。":
result[currMount].append(line)
prevLine = line
return result
@pyqtSlot(int)
def slotWatchClipboardToggled(self, state):
# disable pattern settings, before
# 1. complete patterns
# 2. test glib key file compatibility
self.plaintext_watchPattern.setReadOnly(True)
self.plaintext_watchPattern.setEnabled(state)
@pyqtSlot()
def setupMounts(self):
self.table_mounts.setRowCount(0)
self.table_mounts.clearContents()
#.........这里部分代码省略.........