Skip to content

PR: Show internal errors in a QMessageBox #4040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ def signal_handler(signum, frame=None):
if options.window_title is not None:
title += ' -- ' + options.window_title

if DEV or DEBUG or PYTEST:
# Show errors in internal console when developing or testing.
CONF.set('main', 'show_internal_console_if_traceback', True)


self.base_title = title
self.update_window_title()
resample = os.name != 'nt'
Expand Down Expand Up @@ -2296,7 +2301,7 @@ def show_dependencies(self):
dlg.exec_()

@Slot()
def report_issue(self):
def report_issue(self, traceback=""):
if PY3:
from urllib.parse import quote
else:
Expand All @@ -2320,6 +2325,7 @@ def report_issue(self):

**Please provide any additional information below**

%s

## Version and main components

Expand All @@ -2331,7 +2337,8 @@ def report_issue(self):
```
%s
```
""" % (versions['spyder'],
""" % (traceback,
versions['spyder'],
revision,
versions['python'],
versions['qt'],
Expand Down
4 changes: 2 additions & 2 deletions spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
'cpu_usage/timeout': 2000,
'use_custom_margin': True,
'custom_margin': 0,
'show_internal_console_if_traceback': True,
'show_internal_console_if_traceback': False,
'check_updates_on_startup': True,
'toolbars_visible': True,
# Global Spyder fonts
Expand Down Expand Up @@ -655,7 +655,7 @@
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '37.1.0'
CONF_VERSION = '37.2.0'

# Main configuration instance
try:
Expand Down
46 changes: 41 additions & 5 deletions spyder/plugins/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# Third party imports
from qtpy import PYQT5
from qtpy.compat import getopenfilename
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import QInputDialog, QLineEdit, QMenu, QVBoxLayout
from qtpy.QtCore import Signal, Slot, Qt
from qtpy.QtWidgets import (QInputDialog, QLineEdit, QMenu, QVBoxLayout,
QMessageBox)

# Local imports
from spyder.config.base import _, debug_print
Expand Down Expand Up @@ -91,7 +92,11 @@ def __init__(self, parent=None, namespace=None, commands=[], message=None,

# Accepting drops
self.setAcceptDrops(True)


# Traceback MessageBox
self.msgbox_traceback= None
self.error_traceback = ""

#------ Private API --------------------------------------------------------
def set_historylog(self, historylog):
"""Bind historylog instance to this console
Expand Down Expand Up @@ -197,13 +202,44 @@ def register_plugin(self):
# Connecting the following signal once the dockwidget has been created:
self.shell.traceback_available.connect(self.traceback_available)

def traceback_available(self):
def traceback_available(self, text):
"""Traceback is available in the internal console: showing the
internal console automatically to warn the user"""
if CONF.get('main', 'show_internal_console_if_traceback', False):
self.dockwidget.show()
self.dockwidget.raise_()

else:
if self.msgbox_traceback is None:
self.msgbox_traceback = QMessageBox(
QMessageBox.Critical,
_('Error'),
_("<b>Spyder-IDE has encountered a problem.</b>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the -IDE here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a <br> at the end.

"Sorry for the inconvenience."
"<b>Please tell us about this problem.</b>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this line.

"<br><br>"
"You can submit this error to the github issue tracker"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to

You can automatically submit this error to our Github issues tracker.

Note: You need a Github account for that.

QMessageBox.Ok,
parent=self)

self.submit_btn = self.msgbox_traceback.addButton(
_('Submit to github'), QMessageBox.YesRole)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github -> Github

self.submit_btn.pressed.connect(self.press_submit_btn)

self.msgbox_traceback.setWindowModality(Qt.NonModal)
self.error_traceback = ""
self.msgbox_traceback.show()
self.msgbox_traceback.finished.connect(self.close_msg)

self.error_traceback += text
self.msgbox_traceback.setDetailedText(self.error_traceback)

def close_msg(self):
self.msgbox_traceback = None

def press_submit_btn(self):
self.main.report_issue(self.error_traceback)
self.msgbox_traceback = None

#------ Public API ---------------------------------------------------------
@Slot()
def quit(self):
Expand Down
4 changes: 2 additions & 2 deletions spyder/widgets/sourcecode/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ class ConsoleBaseWidget(TextEditBaseWidget):
"""Console base widget"""
BRACE_MATCHING_SCOPE = ('sol', 'eol')
COLOR_PATTERN = re.compile('\x01?\x1b\[(.*?)m\x02?')
traceback_available = Signal()
traceback_available = Signal(str)
userListActivated = Signal(int, str)
completion_widget_activated = Signal(str)

Expand Down Expand Up @@ -1398,7 +1398,7 @@ def append_text_to_shell(self, text, error, prompt):
# Show error/warning messages in red
cursor.insertText(text, self.error_style.format)
if is_traceback:
self.traceback_available.emit()
self.traceback_available.emit(text)
elif prompt:
# Show prompt in green
insert_text_to(cursor, text, self.prompt_style.format)
Expand Down