本文整理汇总了Python中AnyQt.QtWidgets.QMessageBox类的典型用法代码示例。如果您正苦于以下问题:Python QMessageBox类的具体用法?Python QMessageBox怎么用?Python QMessageBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMessageBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_to_clipboard
def copy_to_clipboard(self):
img = self.get_selection()
if img.isNull():
QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!'))
return
QApplication.clipboard().setPixmap(img)
self.reject()
示例2: save_image_as
def save_image_as(self):
img = self.get_selection().toImage()
if img.isNull():
QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!'))
return
self.hide()
formats = {
self.tr('Portable Network Graphics (*.png)'): 'png',
self.tr('Joint Photographic Experts Group (*.jpg *.jpeg)'): 'jpg',
self.tr('Graphics Interchange Format (*.gif)'): 'gif',
self.tr('Bitmap (*.bmp)'): 'bmp',
self.tr('All Images (*.png *.jpg *.gif *.bmp)'): 'all'
}
file_format = None
destination = QFileDialog.getSaveFileName(self, 'Save image', '', ';;'.join(formats.keys()))
if isinstance(destination, tuple):
destination, file_format = destination
file_format = formats[file_format]
if file_format == 'all':
file_format = None
if not file_format:
file_format = destination.rsplit('.', 1)[-1]
if destination:
if file_format not in formats.values():
file_format = 'png'
if not destination.endswith('.' + file_format):
destination += '.' + file_format
img.save(destination, file_format, 0 if file_format == 'png' else 90)
self.reject()
示例3: track_user_stats
def track_user_stats():
reply = get_usage_track_conf()
if reply=='ask later':
m = QMessageBox(
QMessageBox.Question,
"User tracking",
"Do you give us permission to track which country you are from and how many times you use this application? " \
"This will contribute to the support of this software.",
QMessageBox.Yes | QMessageBox.No | QMessageBox.NoRole
)
ask_later_btn = m.addButton("Ask me later", QMessageBox.NoRole)
m.setEscapeButton(ask_later_btn)
reply = m.exec_()
if reply == QMessageBox.No:
set_usage_track_conf('no-track')
elif reply == QMessageBox.Yes:
set_usage_track_conf('track')
reply = 'track'
elif reply == QMessageBox.NoButton:
set_usage_track_conf('ask later')
if reply=='track':
register_access()
示例4: save_plot
def save_plot(data, file_formats, filename=""):
_LAST_DIR_KEY = "directories/last_graph_directory"
_LAST_FILTER_KEY = "directories/last_graph_filter"
settings = QSettings()
start_dir = settings.value(_LAST_DIR_KEY, filename)
if not start_dir or \
(not os.path.exists(start_dir) and
not os.path.exists(os.path.split(start_dir)[0])):
start_dir = os.path.expanduser("~")
last_filter = settings.value(_LAST_FILTER_KEY, "")
filename, writer, filter = \
filedialogs.open_filename_dialog_save(start_dir, last_filter, file_formats)
if not filename:
return
try:
writer.write(filename, data)
except OSError as e:
mb = QMessageBox(
None,
windowTitle="Error",
text='Error occurred while saving file "{}": {}'.format(filename, e),
detailedText=traceback.format_exc(),
icon=QMessageBox.Critical)
mb.exec_()
else:
settings.setValue(_LAST_DIR_KEY, os.path.split(filename)[0])
settings.setValue(_LAST_FILTER_KEY, filter)
示例5: onDictyExpressLink
def onDictyExpressLink(self, link):
if not self.data:
return
selectedIndexes = self.treeWidget.selectedIndexes()
if not len(selectedIndexes):
QMessageBox.information(
self, "No gene ids selected",
"Please select some genes and try again."
)
return
model = self.treeWidget.model()
mapToSource = model.mapToSource
selectedRows = self.treeWidget.selectedIndexes()
selectedRows = [mapToSource(index).row() for index in selectedRows]
model = model.sourceModel()
selectedGeneids = [self.row2geneinfo[row] for row in selectedRows]
selectedIds = [self.geneinfo[i][0] for i in selectedGeneids]
selectedIds = set(selectedIds)
def fix(ddb):
if ddb.startswith("DDB"):
if not ddb.startswith("DDB_G"):
ddb = ddb.replace("DDB", "DDB_G")
return ddb
return None
genes = [fix(gene) for gene in selectedIds if fix(gene)]
url = str(link) % " ".join(genes)
QDesktopServices.openUrl(QUrl(url))
示例6: share_clipboard
def share_clipboard(self):
mime = QApplication.clipboard().mimeData()
try:
wnd = ShareDialog(self, mime=mime)
except ValueError as e:
QMessageBox.critical(self, self.tr('Error'), str(e))
return
else:
wnd.show()
wnd.exec_()
示例7: save_project
def save_project(self, project_path=None):
try:
if project_path is None:
project_path = QFileDialog.getExistingDirectory(self, "Select the project directory")
if project_path is not None and str(project_path)!='':
project_path = str(project_path)
self.save({}, project_path)
except Exception as e:
QMessageBox.critical(self, "Error", str(e))
示例8: show_survey
def show_survey():
# If run for the first time, open a browser tab with a survey
settings = QSettings()
show_survey = settings.value("startup/show-survey", True, type=bool)
if show_survey:
question = QMessageBox(
QMessageBox.Question,
'Orange Survey',
'We would like to know more about how our software is used.\n\n'
'Would you care to fill our short 1-minute survey?',
QMessageBox.Yes | QMessageBox.No)
question.setDefaultButton(QMessageBox.Yes)
later = question.addButton('Ask again later', QMessageBox.NoRole)
question.setEscapeButton(later)
def handle_response(result):
if result == QMessageBox.Yes:
success = QDesktopServices.openUrl(
QUrl("https://orange.biolab.si/survey/short.html"))
settings.setValue("startup/show-survey", not success)
else:
settings.setValue("startup/show-survey", result != QMessageBox.No)
question.finished.connect(handle_response)
question.show()
return question
示例9: message
def message(icon, text, title=None, informative_text=None, details=None,
buttons=None, default_button=None, exc_info=False, parent=None):
"""Show a message helper function.
"""
if title is None:
title = "Message"
if not text:
text = "I am neither a postman nor a doctor."
if buttons is None:
buttons = QMessageBox.Ok
if details is None and exc_info:
details = traceback.format_exc(limit=20)
mbox = QMessageBox(icon, title, text, buttons, parent)
if informative_text:
mbox.setInformativeText(informative_text)
if details:
mbox.setDetailedText(details)
if default_button is not None:
mbox.setDefaultButton(default_button)
return mbox.exec_()
示例10: get_save_filename
def get_save_filename(self): # pragma: no cover
if sys.platform == "darwin":
def remove_star(filt):
return filt.replace(" (*.", " (.")
else:
def remove_star(filt):
return filt
no_ext_filters = {remove_star(f): f for f in self._valid_filters()}
filename = self._initial_start_dir()
while True:
dlg = QFileDialog(
None, "Save File", filename, ";;".join(no_ext_filters))
dlg.setAcceptMode(dlg.AcceptSave)
dlg.selectNameFilter(remove_star(self._default_valid_filter()))
dlg.setOption(QFileDialog.DontConfirmOverwrite)
if dlg.exec() == QFileDialog.Rejected:
return "", ""
filename = dlg.selectedFiles()[0]
selected_filter = no_ext_filters[dlg.selectedNameFilter()]
filename = self._replace_extension(
filename, self._extension_from_filter(selected_filter))
if not os.path.exists(filename) or QMessageBox.question(
self, "Overwrite file?",
f"File {os.path.split(filename)[1]} already exists.\n"
"Overwrite?") == QMessageBox.Yes:
return filename, selected_filter
示例11: browse_file
def browse_file(self, in_demos=False):
if in_demos:
start_file = get_sample_datasets_dir()
if not os.path.exists(start_file):
QMessageBox.information(
None, "File",
"Cannot find the directory with documentation data sets")
return
else:
start_file = self.last_path() or os.path.expanduser("~/")
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Distance File', start_file, "(*.dst)")
if not filename:
return
self.add_path(filename)
self.open_file()
示例12: browse_file
def browse_file(self, in_demos=False):
if in_demos:
start_file = get_sample_datasets_dir()
if not os.path.exists(start_file):
QMessageBox.information(
None, "File",
"Cannot find the directory with documentation data sets")
return
else:
start_file = self.last_path() or os.path.expanduser("~/")
filename, _ = QFileDialog.getOpenFileName(
self, 'Open Orange Data File', start_file, dialog_formats())
if not filename:
return
self.add_path(filename)
self.source = self.LOCAL_FILE
self.load_data()
示例13: register_hotkeys
def register_hotkeys(self):
if self._hotkey is not None:
self.rebuild_menu()
self._hotkey.unregister(winid=self.winId())
hotkey_bindings = {
settings['hotkey/clipboard']: (self.share_clipboard, self._action_clip),
settings['hotkey/screenshot']: (self.capture_screen, self._action_screen)
}
for hotkey, (callback, action) in hotkey_bindings.items():
if hotkey:
if self._hotkey.register(hotkey, callback, self.winId()):
sequence = QKeySequence(hotkey) if hotkey else QKeySequence()
action.setShortcut(sequence)
else:
QMessageBox.critical(self, 'Error', 'Could not bind {} hotkey!\n'
'Key combination {} is probably already in use.'
.format(const.APP_NAME, hotkey))
else:
qDebug('Hotkeys are not supported on this platform')
示例14: message_restart
def message_restart(parent):
icon = QMessageBox.Information
buttons = QMessageBox.Ok | QMessageBox.Cancel
title = 'Information'
text = 'Orange needs to be restarted for the changes to take effect.'
msg_box = QMessageBox(icon, title, text, buttons, parent)
msg_box.setDefaultButton(QMessageBox.Ok)
msg_box.setInformativeText('Press OK to close Orange now.')
msg_box.button(QMessageBox.Cancel).setText('Close later')
return msg_box.exec_()
示例15: save_plot
def save_plot(data, file_formats, filename=""):
_LAST_DIR_KEY = "directories/last_graph_directory"
_LAST_FILTER_KEY = "directories/last_graph_filter"
settings = QSettings()
start_dir = settings.value(_LAST_DIR_KEY, filename)
if not start_dir or \
(not os.path.exists(start_dir) and
not os.path.exists(os.path.split(start_dir)[0])):
start_dir = os.path.expanduser("~")
last_filter = settings.value(_LAST_FILTER_KEY, "")
filename, writer, filter = \
filedialogs.get_file_name(start_dir, last_filter, file_formats)
if not filename:
return
try:
writer.write(filename, data)
except Exception as e:
QMessageBox.critical(
None, "Error", 'Error occurred while saving file "{}": {}'.format(filename, e))
else:
settings.setValue(_LAST_DIR_KEY, os.path.split(filename)[0])
settings.setValue(_LAST_FILTER_KEY, filter)