Skip to content

Commit

Permalink
BF: Fixes exceptions in the console being displayed in an error dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdcutone authored and mdcutone committed Oct 8, 2020
1 parent 3954fa4 commit d44f24d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions psychopy/app/coder/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from ..utils import FileDropTarget, PsychopyToolbar, FrameSwitcher
from psychopy.projects import pavlovia
import psychopy.app.pavlovia_ui.menu
from psychopy.app.errorDlg import exceptionCallback
from psychopy.app.coder.codeEditorBase import BaseCodeEditor
from psychopy.app.coder.fileBrowser import FileBrowserPanel
from psychopy.app.coder.sourceTree import SourceTreePanel
Expand Down Expand Up @@ -103,17 +104,39 @@ def fromPickle(filename):


class PsychopyPyShell(wx.py.shell.Shell, ThemeMixin):
'''Simple class wrapper for Pyshell which uses the Psychopy ThemeMixin'''
"""Simple class wrapper for Pyshell which uses the Psychopy ThemeMixin."""
def __init__(self, coder):
msg = _translate('PyShell in PsychoPy - type some commands!')
wx.py.shell.Shell.__init__(self, coder.shelf, -1, introText=msg + '\n\n', style=wx.BORDER_NONE)
wx.py.shell.Shell.__init__(
self, coder.shelf, -1, introText=msg + '\n\n', style=wx.BORDER_NONE)
self.prefs = coder.prefs
self.paths = coder.paths
self.app = coder.app

self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

# Set theme to match code editor
self._applyAppTheme()

def OnSetFocus(self, evt=None):
"""Called when the shell gets focus."""
# Switch to the default callback when in console, prevents the PsychoPy
# error dialog from opening.
sys.excepthook = sys.__excepthook__

if evt:
evt.Skip()

def OnKillFocus(self, evt=None):
"""Called when the shell loses focus."""
# Set the callback to use the dialog when errors occur outside the
# shell.
sys.excepthook = exceptionCallback

if evt:
evt.Skip()

def GetContextMenu(self):
"""Override original method (wx.py.shell.Shell.GetContextMenu)
to localize context menu. Simply added _translate() to
Expand Down Expand Up @@ -1069,9 +1092,6 @@ def DoFindNext(self, findData, findDlg=None):
start = 0
loc = textstring.find(findstring, start)

# Adjust for offset
loc += 2

# was it still not found?
if loc == -1:
dlg = dialogs.MessageDialog(self, message=_translate(
Expand Down

0 comments on commit d44f24d

Please sign in to comment.