本文整理汇总了Python中qtpy.QtWidgets.QMessageBox.exec_方法的典型用法代码示例。如果您正苦于以下问题:Python QMessageBox.exec_方法的具体用法?Python QMessageBox.exec_怎么用?Python QMessageBox.exec_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QMessageBox
的用法示例。
在下文中一共展示了QMessageBox.exec_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_password
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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: mirror_navi
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def mirror_navi(self, uisignals=None, shared_nav=False):
# Select signals
if uisignals is None:
uisignals = self.ui.get_selected_wrappers()
if len(uisignals) < 2:
mb = QMessageBox(QMessageBox.Information, tr("Select two or more"),
tr("You need to select two or more signals" +
" to mirror"), QMessageBox.Ok)
mb.exec_()
return
signals = [s.signal for s in uisignals]
# hyperspy closes, and then recreates figures when mirroring
# the navigators. To keep UI from flickering, we suspend updates.
# SignalWrapper also saves and then restores window geometry
self.ui.setUpdatesEnabled(False)
try:
if shared_nav:
navs = ["auto"]
navs.extend([None] * (len(signals)-1))
hyperspy.utils.plot.plot_signals(signals, sync=True,
navigator_list=navs)
else:
hyperspy.utils.plot.plot_signals(signals, sync=True)
finally:
self.ui.setUpdatesEnabled(True) # Continue updating UI
示例3: show_error_message
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def show_error_message(message, title, parent=None):
box = QMessageBox(parent=parent)
box.setIcon(QMessageBox.Warning)
box.setText(message)
box.setWindowTitle(title)
box.setStandardButtons(QMessageBox.Ok)
box.exec_()
示例4: display_message_box
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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_()
示例5: update_check
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def update_check(self, silent=False):
"""
Checks for updates to hyperspy and hyperspyUI.
If the packages are not source installs, it checks for a new version on
PyPI.
Parameters
----------
silent: bool
If not silent (default), a message box will appear if no
updates are available, with a message to that fact.
"""
self._check_git()
available = {}
for Name, (enabled, url) in self.packages.items():
name = Name.lower()
if enabled:
if (check_git_repo(name) and
self.settings['check_for_git_updates', bool]):
# TODO: Check for commits to pull
pass
else:
import xmlrpc.client
pypi = xmlrpc.client.ServerProxy(
'https://pypi.python.org/pypi')
found = pypi.package_releases(name)
if not found:
# Try to capitalize pkg name
if name == 'hyperspyui':
found = pypi.package_releases('hyperspyUI', True)
else:
found = pypi.package_releases(Name, True)
if found:
import pip
dist = [d for d in pip.get_installed_distributions()
if d.project_name.lower() == name]
if dist[0].version < found[0]:
available[name] = found[0]
if available:
w = self._get_update_list(available.keys())
diag = self.ui.show_okcancel_dialog("Updates available", w)
if diag.result() == QDialog.Accepted:
for chk in w.children():
if isinstance(chk, QtWidgets.QCheckBox):
name = chk.text()
if available[name]:
name += '==' + available[name]
self._perform_update(name)
elif not silent:
mb = QMessageBox(QMessageBox.Information, tr("No updates"),
tr("No new updates were found."),
parent=self.ui)
mb.exec_()
示例6: checkout_branch
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def checkout_branch(branch, stream=None):
"""
If `branch` is a string, assume it is archive url. Try to install by pip.
Otherwise `branch` is assumed by a branch object from the `git` package,
which will be attempted to be checked out.
"""
if branch is None:
return
if isinstance(branch, str):
import pip
import sys
class WrapDownloadProgressBar(pip.download.DownloadProgressBar):
def __init__(self, *args, **kwargs):
super(WrapDownloadProgressBar, self).__init__(
*args, **kwargs)
self.file = stream
class WrapDownloadProgressBarSpinner(
pip.download.DownloadProgressSpinner):
def __init__(self, *args, **kwargs):
super(WrapDownloadProgressBarSpinner, self).__init__(
*args, **kwargs)
self.file = stream
ic = pip.commands.InstallCommand()
ic.log_streams = (stream, stream)
old_classes = (pip.download.DownloadProgressBar,
pip.download.DownloadProgressSpinner)
pip.download.DownloadProgressBar = WrapDownloadProgressBar
pip.download.DownloadProgressSpinner = WrapDownloadProgressBarSpinner
stdout_set = False
if sys.__stdout__ is None:
sys.__stdout__ = sys.stdout
stdout_set = True
try:
ic.main(['--no-deps', '-I', branch])
ic.main([branch])
finally:
if stdout_set:
sys.__stdout__ = None # Let's leave things as we found them.
(pip.download.DownloadProgressBar,
pip.download.DownloadProgressSpinner) = old_classes
else:
try:
branch.checkout()
except git.GitCommandError as e:
mb = QMessageBox(QMessageBox.Critical, tr("Git checkout failed"),
e.stderr)
mb.exec_()
raise ValueError()
示例7: show_mongo_query_help
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def show_mongo_query_help(self):
"Launch a Message Box with instructions for custom queries."
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("For advanced search capability, enter a valid Mongo query.")
msg.setInformativeText("""
Examples:
{'plan_name': 'scan'}
{'proposal': 1234},
{'$and': ['proposal': 1234, 'sample_name': 'Ni']}
""")
msg.setWindowTitle("Custom Mongo Query")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
示例8: exception
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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_()
示例9: dialog
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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
示例10: save_list_to_file
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def save_list_to_file(self):
filename, filters = QFileDialog.getSaveFileName(self,
"Save connection list",
"",
"Text Files (*.txt)")
try:
with open(filename, "w") as f:
for conn in self.table_view.model().connections:
f.write(
"{p}://{a}\n".format(p=conn.protocol, a=conn.address))
self.save_status_label.setText("File saved to {}".format(filename))
except Exception as e:
msgBox = QMessageBox()
msgBox.setText("Couldn't save connection list to file.")
msgBox.setInformativeText("Error: {}".format(str(e)))
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.exec_()
示例11: exceptions
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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_()
示例12: _on_reset
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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()
示例13: get_selected_wrapper
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [as 别名]
def get_selected_wrapper(self, error_on_multiple=False):
signals = self.get_selected_wrappers()
if signals is None or len(signals) < 1:
return None
elif len(signals) == 1:
return signals[0]
else:
if error_on_multiple:
mb = QMessageBox(QMessageBox.Information,
tr("Select one signal only"),
tr("You can only select one signal at the " +
"time for this function. Currently, " +
"several are selected"),
QMessageBox.Ok)
mb.exec_()
raise RuntimeError()
w = self.main_frame.activeSubWindow()
s = [hyperspyui.util.win2sig(w, self.signals)]
if s in signals:
return s
else:
return signals[0]
示例14: permission_box_to_prepend_import
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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
示例15: confirm_dialog
# 需要导入模块: from qtpy.QtWidgets import QMessageBox [as 别名]
# 或者: from qtpy.QtWidgets.QMessageBox import exec_ [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