本文整理汇总了Python中guidata.qt.QtGui.QMessageBox.critical方法的典型用法代码示例。如果您正苦于以下问题:Python QMessageBox.critical方法的具体用法?Python QMessageBox.critical怎么用?Python QMessageBox.critical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类guidata.qt.QtGui.QMessageBox
的用法示例。
在下文中一共展示了QMessageBox.critical方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_image_open_dialog
# 需要导入模块: from guidata.qt.QtGui import QMessageBox [as 别名]
# 或者: from guidata.qt.QtGui.QMessageBox import critical [as 别名]
def exec_image_open_dialog(parent, basedir='', app_name=None,
to_grayscale=True, dtype=None):
"""
Executes an image open dialog box (QFileDialog.getOpenFileName)
* parent: parent widget (None means no parent)
* basedir: base directory ('' means current directory)
* app_name (opt.): application name (used as a title for an eventual
error message box in case something goes wrong when saving image)
* to_grayscale (default=True): convert image to grayscale
Returns (filename, data) tuple if dialog is accepted, None otherwise
"""
saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
sys.stdout = None
filename, _filter = getopenfilename(parent, _("Open"), basedir,
io.iohandler.get_filters('load', dtype=dtype))
sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
filename = to_text_string(filename)
try:
data = io.imread(filename, to_grayscale=to_grayscale)
except Exception as msg:
import traceback
traceback.print_exc()
QMessageBox.critical(parent,
_('Error') if app_name is None else app_name,
(_("%s could not be opened:") % osp.basename(filename))+\
"\n"+str(msg))
return
return filename, data
示例2: exec_image_save_dialog
# 需要导入模块: from guidata.qt.QtGui import QMessageBox [as 别名]
# 或者: from guidata.qt.QtGui.QMessageBox import critical [as 别名]
def exec_image_save_dialog(parent, data, template=None,
basedir='', app_name=None):
"""
Executes an image save dialog box (QFileDialog.getSaveFileName)
* parent: parent widget (None means no parent)
* data: image pixel array data
* template: image template (pydicom dataset) for DICOM files
* basedir: base directory ('' means current directory)
* app_name (opt.): application name (used as a title for an eventual
error message box in case something goes wrong when saving image)
Returns filename if dialog is accepted, None otherwise
"""
saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
sys.stdout = None
filename, _filter = getsavefilename(parent, _("Save as"), basedir,
io.iohandler.get_filters('save', dtype=data.dtype, template=template))
sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
if filename:
filename = to_text_string(filename)
kwargs = {}
if osp.splitext(filename)[1].lower() == '.dcm':
kwargs['template'] = template
try:
io.imwrite(filename, data, **kwargs)
return filename
except Exception as msg:
import traceback
traceback.print_exc()
QMessageBox.critical(parent,
_('Error') if app_name is None else app_name,
(_("%s could not be written:") % osp.basename(filename))+\
"\n"+str(msg))
return