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
def create_checkbox(self, text, option, default=NoDefault,
tip=None, msg_warning=None, msg_info=None,
msg_if_enabled=False):
checkbox = QCheckBox(text)
if tip is not None:
checkbox.setToolTip(tip)
self.checkboxes[checkbox] = (option, default)
if msg_warning is not None or msg_info is not None:
def show_message(is_checked=False):
if is_checked or not msg_if_enabled:
if msg_warning is not None:
QMessageBox.warning(self, self.get_name(),
msg_warning, QMessageBox.Ok)
if msg_info is not None:
QMessageBox.information(self, self.get_name(),
msg_info, QMessageBox.Ok)
checkbox.clicked.connect(show_message)
return checkbox
class MessageCheckBox(QMessageBox):
"""
A QMessageBox derived widget that includes a QCheckBox aligned to the right
under the message and on top of the buttons.
"""
def __init__(self, *args, **kwargs):
super(MessageCheckBox, self).__init__(*args, **kwargs)
self._checkbox = QCheckBox()
# Set layout to include checkbox
size = 9
check_layout = QVBoxLayout()
check_layout.addItem(QSpacerItem(size, size))
check_layout.addWidget(self._checkbox, 0, Qt.AlignRight)
check_layout.addItem(QSpacerItem(size, size))
# Access the Layout of the MessageBox to add the Checkbox
layout = self.layout()
if PYQT5:
layout.addLayout(check_layout, 1, 2)
else:
layout.addLayout(check_layout, 1, 1)
# --- Public API
# Methods to access the checkbox
def is_checked(self):
return self._checkbox.isChecked()
def set_checked(self, value):
return self._checkbox.setChecked(value)
def set_check_visible(self, value):
self._checkbox.setVisible(value)
def is_check_visible(self):
self._checkbox.isVisible()
def checkbox_text(self):
self._checkbox.text()
def set_checkbox_text(self, text):
self._checkbox.setText(text)
def set_check_box(self, row, col, state):
""" function to add a new select checkbox to a cell in a table row
won't add a new checkbox if one already exists
"""
# Check input
assert isinstance(state, bool)
# Check if cellWidget exists
if self.cellWidget(row, col):
# existing: just set the value
self.cellWidget(row, col).setChecked(state)
else:
# case to add checkbox
checkbox = QCheckBox()
checkbox.setText('')
checkbox.setChecked(state)
# Adding a widget which will be inserted into the table cell
# then centering the checkbox within this widget which in turn,
# centers it within the table column :-)
self.setCellWidget(row, col, checkbox)
# END-IF-ELSE
return
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_("Spyder internal error"))
self.setModal(True)
# To save the traceback sent to the internal console
self.error_traceback = ""
# Dialog main label
self.main_label = QLabel(
_("""<b>Spyder has encountered an internal problem</b><hr>
Please enter below a step-by-step description of
your problem (in English). Issue reports without
a clear way to reproduce them will be closed.
<br><br>
<b>Note</b>: You need a Github account for this.
"""))
self.main_label.setWordWrap(True)
self.main_label.setAlignment(Qt.AlignJustify)
# Field to input the description of the problem
self.input_description = DescriptionWidget(self)
# Only allow to submit to Github if we have a long enough description
self.input_description.textChanged.connect(self._description_changed)
# Widget to show errors
self.details = ShowErrorWidget(self)
self.details.set_pythonshell_font(get_font())
self.details.hide()
# Label to show missing chars
self.initial_chars = len(self.input_description.toPlainText())
self.chars_label = QLabel(_("Enter at least {} "
"characters".format(MIN_CHARS)))
# Checkbox to dismiss future errors
self.dismiss_box = QCheckBox()
self.dismiss_box.setText(_("Don't show again during this session"))
# Labels layout
labels_layout = QHBoxLayout()
labels_layout.addWidget(self.chars_label)
labels_layout.addWidget(self.dismiss_box, 0, Qt.AlignRight)
# Dialog buttons
self.submit_btn = QPushButton(_('Submit to Github'))
self.submit_btn.setEnabled(False)
self.submit_btn.clicked.connect(self._submit_to_github)
self.details_btn = QPushButton(_('Show details'))
self.details_btn.clicked.connect(self._show_details)
self.close_btn = QPushButton(_('Close'))
# Buttons layout
buttons_layout = QHBoxLayout()
buttons_layout.addWidget(self.submit_btn)
buttons_layout.addWidget(self.details_btn)
buttons_layout.addWidget(self.close_btn)
# Main layout
vlayout = QVBoxLayout()
vlayout.addWidget(self.main_label)
vlayout.addWidget(self.input_description)
vlayout.addWidget(self.details)
vlayout.addLayout(labels_layout)
vlayout.addLayout(buttons_layout)
self.setLayout(vlayout)
self.resize(600, 420)
self.input_description.setFocus()
class SpyderErrorDialog(QDialog):
"""Custom error dialog for error reporting."""
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_("Spyder internal error"))
self.setModal(True)
# To save the traceback sent to the internal console
self.error_traceback = ""
# Dialog main label
self.main_label = QLabel(
_("""<b>Spyder has encountered an internal problem</b><hr>
Please enter below a step-by-step description of
your problem (in English). Issue reports without
a clear way to reproduce them will be closed.
<br><br>
<b>Note</b>: You need a Github account for this.
"""))
self.main_label.setWordWrap(True)
self.main_label.setAlignment(Qt.AlignJustify)
# Field to input the description of the problem
self.input_description = DescriptionWidget(self)
# Only allow to submit to Github if we have a long enough description
self.input_description.textChanged.connect(self._description_changed)
# Widget to show errors
self.details = ShowErrorWidget(self)
self.details.set_pythonshell_font(get_font())
self.details.hide()
# Label to show missing chars
self.initial_chars = len(self.input_description.toPlainText())
self.chars_label = QLabel(_("Enter at least {} "
"characters".format(MIN_CHARS)))
# Checkbox to dismiss future errors
self.dismiss_box = QCheckBox()
self.dismiss_box.setText(_("Don't show again during this session"))
# Labels layout
labels_layout = QHBoxLayout()
labels_layout.addWidget(self.chars_label)
labels_layout.addWidget(self.dismiss_box, 0, Qt.AlignRight)
# Dialog buttons
self.submit_btn = QPushButton(_('Submit to Github'))
self.submit_btn.setEnabled(False)
self.submit_btn.clicked.connect(self._submit_to_github)
self.details_btn = QPushButton(_('Show details'))
self.details_btn.clicked.connect(self._show_details)
self.close_btn = QPushButton(_('Close'))
# Buttons layout
buttons_layout = QHBoxLayout()
buttons_layout.addWidget(self.submit_btn)
buttons_layout.addWidget(self.details_btn)
buttons_layout.addWidget(self.close_btn)
# Main layout
vlayout = QVBoxLayout()
vlayout.addWidget(self.main_label)
vlayout.addWidget(self.input_description)
vlayout.addWidget(self.details)
vlayout.addLayout(labels_layout)
vlayout.addLayout(buttons_layout)
self.setLayout(vlayout)
self.resize(600, 420)
self.input_description.setFocus()
def _submit_to_github(self):
"""Action to take when pressing the submit button."""
main = self.parent().main
# Getting description and traceback
description = self.input_description.toPlainText()
traceback = self.error_traceback[:-1] # Remove last eol
# Render issue
issue_text = main.render_issue(description=description,
traceback=traceback)
# Copy issue to clipboard
QApplication.clipboard().setText(issue_text)
# Submit issue to Github
issue_body=("<!--- "
"Please paste the contents of your clipboard "
"below to complete reporting your problem. "
"--->\n\n")
main.report_issue(body=issue_body,
title="Automatic error report")
def append_traceback(self, text):
#.........这里部分代码省略.........
请发表评论