def _warn_existing_output_dir(self, path):
path = os.path.abspath(path)
reply = QMessageBox.question(self, "Reuse previous data",
"Intermediate files were found at\n{0}\nDo you want to reuse them?".format(path),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
reuse = int(reply) == QMessageBox.Yes
if not reuse:
shutil.rmtree(path)
python类question()的实例源码
def confirm_on_empty(self, name):
if not self._has_data:
reply = QMessageBox.question(self, "Confirm Save Plot",
"{0} plot is empty\nAre you sure you want to save it?".format(name),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
return int(reply) == QMessageBox.Yes
return True
def closeEvent(self, event):
'''
Closing endPlate window.
'''
ui_input = self.getuser_inputs()
self.save_inputs(ui_input)
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.Yes:
self.closed.emit()
event.accept()
else:
event.ignore()
# ********************************* Help Action *********************************************************************************************
def delete_object(self):
indexes = self.get_selected_rows()
if not len(indexes):
return
confirm = QMessageBox.question(self.get_main_window(),
_('Question'),
_('Please confirm'),
QMessageBox.Yes | QMessageBox.No)
if confirm == QMessageBox.No:
return
tab = self.get_current_tab_index()
if tab == 0:
race().delete_persons(indexes)
# recalculate places
ResultCalculation().process_results()
self.get_main_window().refresh()
elif tab == 1:
race().delete_results(indexes)
# recalculate places
ResultCalculation().process_results()
self.get_main_window().refresh()
elif tab == 2:
try:
race().delete_groups(indexes)
except NotEmptyException as e:
logging.warning(str(e))
QMessageBox.question(self.get_group_table(),
_('Error'),
_('Cannot remove group'))
self.get_main_window().refresh()
elif tab == 3:
try:
race().delete_courses(indexes)
except NotEmptyException as e:
logging.warning(str(e))
QMessageBox.question(self.get_course_table(),
_('Error'),
_('Cannot remove course'))
self.get_main_window().refresh()
elif tab == 4:
try:
race().delete_organizations(indexes)
except NotEmptyException as e:
logging.warning(str(e))
QMessageBox.question(self.get_organization_table(),
_('Error'),
_('Cannot remove organization'))
self.get_main_window().refresh()
def set_decoding(self, decoding: Encoding, messages=None):
"""
:param decoding:
:param messages: None = set for all messages
:return:
"""
if decoding is None:
self.show_decoding_clicked.emit()
else:
if messages is None:
messages = self.proto_analyzer.messages
if len(messages) > 10:
reply = QMessageBox.question(self, "Set decoding",
"Do you want to apply the selected decoding to {} messages?".format(
len(messages)), QMessageBox.Yes | QMessageBox.No)
if reply != QMessageBox.Yes:
self.ui.cbDecoding.blockSignals(True)
self.ui.cbDecoding.setCurrentText("...")
self.ui.cbDecoding.blockSignals(False)
return
self.show_all_cols()
for msg in messages:
msg.decoder = decoding
self.clear_search()
selected = self.ui.tblViewProtocol.selectionModel().selection()
if not selected.isEmpty() and self.isVisible() and self.proto_analyzer.num_messages > 0:
min_row = min(rng.top() for rng in selected)
min_row = min_row if min_row < len(self.proto_analyzer.messages) else -1
try:
msg = self.proto_analyzer.messages[min_row]
except IndexError:
msg = None
self.__set_decoding_error_label(msg)
else:
self.__set_decoding_error_label(None)
self.protocol_model.update()
self.protocol_label_list_model.update()
self.label_value_model.update()
for lbl in self.proto_analyzer.protocol_labels:
self.set_protocol_label_visibility(lbl)
self.ui.tblViewProtocol.resize_columns()
def yes_no_cancel_dlg(parent,text):
if parent!=None:
msgBox = QMessageBox(parent)
msgBox.setIcon(QMessageBox.Question)
msgBox.setText("Question")
msgBox.setInformativeText(text)
msgBox.setStandardButtons(QMessageBox.Yes| QMessageBox.No| QMessageBox.Cancel )
msgBox.setDefaultButton(QMessageBox.No)
reply = msgBox.exec_()
if reply == QMessageBox.Yes:
return "yes"
elif reply == QMessageBox.No:
return "no"
else:
return "cancel"
else:
reply = input(text+"y/n/c")
if reply == "y":
return "yes"
elif reply == "n":
return "no"
else:
return "cancel"
def my_close(self):
settings = constants.SETTINGS
not_show = settings.value('not_show_close_dialog', False, type=bool)
if not not_show:
cb = QCheckBox("Do not show this again.")
msgbox = QMessageBox(QMessageBox.Question, "Confirm close", "Are you sure you want to close?")
msgbox.addButton(QMessageBox.Yes)
msgbox.addButton(QMessageBox.No)
msgbox.setDefaultButton(QMessageBox.No)
msgbox.setCheckBox(cb)
reply = msgbox.exec()
not_show_again = bool(cb.isChecked())
settings.setValue("not_show_close_dialog", not_show_again)
self.not_show_again_changed.emit()
if reply != QMessageBox.Yes:
return
self.closed.emit(self)
def process_delete(self, process):
"""
Handle the removal of a B3 process.
"""
msgbox = QMessageBox()
msgbox.setIcon(QMessageBox.Question)
msgbox.setWindowTitle('CONFIRM')
msgbox.setText('Are you sure?')
msgbox.setInformativeText('Do you want to remove %s?' % process.name)
msgbox.setStandardButtons(QMessageBox.No|QMessageBox.Yes)
msgbox.setDefaultButton(QMessageBox.No)
msgbox.layout().addItem(QSpacerItem(300, 0, QSizePolicy.Minimum, QSizePolicy.Expanding),
msgbox.layout().rowCount(), 0, 1, msgbox.layout().columnCount())
msgbox.exec_()
if msgbox.result() == QMessageBox.Yes:
if process.state() != QProcess.NotRunning:
self.process_shutdown(process)
process.delete()
self.repaint()
def yes_no_dlg(parent,text):
msgBox = QMessageBox(parent)
msgBox.setIcon(QMessageBox.Question)
msgBox.setText("Question")
msgBox.setInformativeText(text)
msgBox.setStandardButtons(QMessageBox.Yes| QMessageBox.No )
msgBox.setDefaultButton(QMessageBox.No)
reply = msgBox.exec_()
if reply == QMessageBox.Yes:
return True
else:
return False
def yes_no_cancel_dlg(parent,text):
msgBox = QMessageBox(parent)
msgBox.setIcon(QMessageBox.Question)
msgBox.setText("Question")
msgBox.setInformativeText(text)
msgBox.setStandardButtons(QMessageBox.Yes| QMessageBox.No| QMessageBox.Cancel )
msgBox.setDefaultButton(QMessageBox.No)
reply = msgBox.exec_()
if reply == QMessageBox.Yes:
return "yes"
elif reply == QMessageBox.No:
return "no"
else:
return "cancel"
NetworkPrinterOutputDevice.py 文件源码
项目:UM3NetworkPrintingPlugin
作者: Ultimaker
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def materialHotendChangedMessage(self, callback):
Application.getInstance().messageBox(i18n_catalog.i18nc("@window:title", "Changes on the Printer"),
i18n_catalog.i18nc("@label",
"Would you like to update your current printer configuration into Cura?"),
i18n_catalog.i18nc("@label",
"The PrintCores and/or materials on your printer were changed. For the best result, always slice for the PrintCores and materials that are inserted in your printer."),
buttons=QMessageBox.Yes + QMessageBox.No,
icon=QMessageBox.Question,
callback=callback
)
def save_all(self):
if self.num_frames == 0:
return
settings = constants.SETTINGS
try:
not_show = settings.value('not_show_save_dialog', type=bool, defaultValue=False)
except TypeError:
not_show = False
if not not_show:
cb = QCheckBox("Don't ask me again.")
msg_box = QMessageBox(QMessageBox.Question, self.tr("Confirm saving all signals"),
self.tr("All changed signal files will be overwritten. OK?"))
msg_box.addButton(QMessageBox.Yes)
msg_box.addButton(QMessageBox.No)
msg_box.setCheckBox(cb)
reply = msg_box.exec()
not_show_again = cb.isChecked()
settings.setValue("not_show_save_dialog", not_show_again)
self.not_show_again_changed.emit()
if reply != QMessageBox.Yes:
return
for f in self.signal_frames:
if f.signal is None or f.signal.filename == "":
continue
f.signal.save()
def shutdown(self):
"""
Perform cleanup operation before the application exits.
This is executed when the `aboutToQuit` signal is emitted, before `quit()
or when the user shutdown the Desktop session`.
"""
LOG.debug('shutdown requested')
is_something_running = False
for process in self.processes:
if process.state() == QProcess.Running:
is_something_running = True
break
if is_something_running:
# ask the use if he wants to quit for real
LOG.debug('some processes are still running: asking the user if he wants to terminate them...')
msgbox = QMessageBox()
msgbox.setIcon(QMessageBox.Question)
msgbox.setText('Are you sure you want to quit?')
msgbox.setInformativeText('NOTE: all the running B3 will be stopped!')
msgbox.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
msgbox.setDefaultButton(QMessageBox.No)
msgbox.exec_()
if msgbox.result() == QMessageBox.Yes:
LOG.debug('user agreed to terminate all the running processes and quit the application')
else:
LOG.debug('shutdown aborted')
return
self.shutdown_requested = True
self.stop_all()
## REMOVE LOG HANDLERS
for handler in LOG.handlers:
handler.close()
LOG.removeHandler(handler)
## HIDE SYSTEM TRAY (ON WINDOWS IT STAYS VISIBLE SOMETIME)
if b3.getPlatform() != 'linux':
# linux has no system tray
self.main_window.system_tray.hide()
## QUIT THE APPLICATION
self.quit()
############################################## OTHER METHODS #######################################################