本文整理汇总了Python中qtpy.QtWidgets.QMessageBox.setDefaultButton方法的典型用法代码示例。如果您正苦于以下问题:Python QMessageBox.setDefaultButton方法的具体用法?Python QMessageBox.setDefaultButton怎么用?Python QMessageBox.setDefaultButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QMessageBox
的用法示例。
在下文中一共展示了QMessageBox.setDefaultButton方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_password
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def validate_password(self):
"""
If the widget is ```passwordProtected```, this method will propmt
the user for the correct password.
Returns
-------
bool
True in case the password was correct of if the widget is not
password protected.
"""
if not self._password_protected:
return True
pwd, ok = QInputDialog().getText(None, "Authentication", "Please enter your password:",
QLineEdit.Password, "")
pwd = str(pwd)
if not ok or pwd == "":
return False
sha = hashlib.sha256()
sha.update(pwd.encode())
pwd_encrypted = sha.hexdigest()
if pwd_encrypted != self._protected_password:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText("Invalid password.")
msg.setWindowTitle("Error")
msg.setStandardButtons(QMessageBox.Ok)
msg.setDefaultButton(QMessageBox.Ok)
msg.setEscapeButton(QMessageBox.Ok)
msg.exec_()
return False
return True
示例2: dialog
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def dialog(title, text, icon, setting=None, default=None):
if not getattr(settings, setting.upper()):
return True
check = QCheckBox()
check.setText('Dont show this message again (can be reset via the preferences)')
info = QMessageBox()
info.setIcon(icon)
info.setText(title)
info.setInformativeText(text)
info.setCheckBox(check)
info.setStandardButtons(info.Cancel | info.Ok)
if default == 'Cancel':
info.setDefaultButton(info.Cancel)
result = info.exec_()
if result == info.Cancel:
return False
if check.isChecked():
setattr(settings, setting.upper(), False)
save_settings()
return True
示例3: display_message_box
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def display_message_box(self, title, message, details):
msg = QMessageBox(self)
msg.setIcon(QMessageBox.Warning)
msg.setText(message)
msg.setWindowTitle(title)
msg.setDetailedText(details)
msg.setStandardButtons(QMessageBox.Ok)
msg.setDefaultButton(QMessageBox.Ok)
msg.setEscapeButton(QMessageBox.Ok)
msg.exec_()
示例4: _on_reset
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def _on_reset(self):
"""
Callback for reset button. Prompts user for confirmation, then proceeds
to reset settings to default values if confirmed, before updating
controls and applying any changes (emits change signal if any changes).
"""
mb = QMessageBox(QMessageBox.Warning,
tr("Reset all settings"),
tr("This will reset all settings to their default " +
"values. Are you sure you want to continue?"),
QMessageBox.Yes | QMessageBox.No)
mb.setDefaultButton(QMessageBox.No)
dr = mb.exec_()
if dr == QMessageBox.Yes:
# This clears all settings, and recreates only those values
# initialized with set_default this session.
Settings.restore_from_defaults()
# Now we update controls:
s = QSettings(self.ui)
keys = list(self._initial_values.keys()) # Use copy, as we may modify
for k in keys:
# Check if setting is still present
if s.contains(k):
# Present, update to new value (triggers _on_change)
v = s.value(k)
w = self._lut[k]
if isinstance(w, QLineEdit):
w.setText(v)
elif isinstance(w, QCheckBox):
w.setChecked(v.lower() == "true")
elif isinstance(w, (QSpinBox, QDoubleSpinBox)):
w.setValue(v)
else:
# Setting was removed, remove editor
w = self._lut[k]
layout = w.parent().layout()
label = layout.labelForField(w)
layout.removeWidget(w)
w.close()
if label is not None:
layout.removeWidget(label)
label.close()
del self._lut[k]
del self._initial_values[k]
self._changes[k] = None
# Check whether all editors for tab was removed
if layout.count() == 0:
wrap = w.parent()
self.tabs.removeTab(self.tabs.indexOf(wrap))
# Finally apply changes (update _initial_values, and emit signal)
self.apply_changes()
示例5: permission_box_to_prepend_import
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def permission_box_to_prepend_import():
msg_box = QMessageBox()
msg_box.setWindowTitle("Mantid Workbench")
msg_box.setWindowIcon(QIcon(':/images/MantidIcon.ico'))
msg_box.setText("It looks like this python file uses a Mantid "
"algorithm but does not import the Mantid API.")
msg_box.setInformativeText("Would you like to add a line to import "
"the Mantid API?")
msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msg_box.setDefaultButton(QMessageBox.Yes)
permission = msg_box.exec_()
if permission == QMessageBox.Yes:
return True
return False
示例6: exception
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def exception(parent, ex, buttons=QMessageBox.Ok,
defaultButton=QMessageBox.NoButton):
title = type(ex).__name__
message = str(ex)
tb = StringIO()
if hasattr(ex, '__traceback__'):
exc_traceback = ex.__traceback__
else:
exc_traceback = sys.exc_info()[2]
traceback.print_tb(exc_traceback, file=tb)
msgbox = QMessageBox(QMessageBox.Critical, title, message, buttons, parent)
msgbox.setDefaultButton(defaultButton)
msgbox.setDetailedText(tb.getvalue())
msgbox.exec_()
示例7: exceptions
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def exceptions(parent, exs, buttons=QMessageBox.Ok,
defaultButton=QMessageBox.NoButton):
title = 'Exception(s)'
message = '\n'.join(map(str, exs))
tracebacks = []
for ex in exs:
tb = StringIO()
if not hasattr(ex, '__traceback__'):
continue
exc_traceback = ex.__traceback__
traceback.print_tb(exc_traceback, file=tb)
tracebacks.append(tb.getvalue())
msgbox = QMessageBox(QMessageBox.Critical, title, message, buttons, parent)
msgbox.setDefaultButton(defaultButton)
msgbox.setDetailedText('\n'.join(tracebacks))
msgbox.exec_()
示例8: confirm_dialog
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import setDefaultButton [as 别名]
def confirm_dialog(self):
"""
Show the confirmation dialog with the proper message in case
```showConfirmMessage``` is True.
Returns
-------
bool
True if the message was confirmed or if ```showCofirmMessage```
is False.
"""
if self._show_confirm_dialog:
if self._confirm_message == "":
self._confirm_message = PyDMPushButton.DEFAULT_CONFIRM_MESSAGE
msg = QMessageBox()
msg.setIcon(QMessageBox.Question)
msg.setText(self._confirm_message)
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msg.setDefaultButton(QMessageBox.No)
ret = msg.exec_()
if ret == QMessageBox.No:
return False
return True