|
39 | 39 | from ..utils import FileDropTarget, PsychopyToolbar, FrameSwitcher |
40 | 40 | from psychopy.projects import pavlovia |
41 | 41 | import psychopy.app.pavlovia_ui.menu |
| 42 | +from psychopy.app.errorDlg import exceptionCallback |
42 | 43 | from psychopy.app.coder.codeEditorBase import BaseCodeEditor |
43 | 44 | from psychopy.app.coder.fileBrowser import FileBrowserPanel |
44 | 45 | from psychopy.app.coder.sourceTree import SourceTreePanel |
@@ -103,17 +104,39 @@ def fromPickle(filename): |
103 | 104 |
|
104 | 105 |
|
105 | 106 | class PsychopyPyShell(wx.py.shell.Shell, ThemeMixin): |
106 | | - '''Simple class wrapper for Pyshell which uses the Psychopy ThemeMixin''' |
| 107 | + """Simple class wrapper for Pyshell which uses the Psychopy ThemeMixin.""" |
107 | 108 | def __init__(self, coder): |
108 | 109 | msg = _translate('PyShell in PsychoPy - type some commands!') |
109 | | - wx.py.shell.Shell.__init__(self, coder.shelf, -1, introText=msg + '\n\n', style=wx.BORDER_NONE) |
| 110 | + wx.py.shell.Shell.__init__( |
| 111 | + self, coder.shelf, -1, introText=msg + '\n\n', style=wx.BORDER_NONE) |
110 | 112 | self.prefs = coder.prefs |
111 | 113 | self.paths = coder.paths |
112 | 114 | self.app = coder.app |
113 | 115 |
|
| 116 | + self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) |
| 117 | + self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) |
| 118 | + |
114 | 119 | # Set theme to match code editor |
115 | 120 | self._applyAppTheme() |
116 | 121 |
|
| 122 | + def OnSetFocus(self, evt=None): |
| 123 | + """Called when the shell gets focus.""" |
| 124 | + # Switch to the default callback when in console, prevents the PsychoPy |
| 125 | + # error dialog from opening. |
| 126 | + sys.excepthook = sys.__excepthook__ |
| 127 | + |
| 128 | + if evt: |
| 129 | + evt.Skip() |
| 130 | + |
| 131 | + def OnKillFocus(self, evt=None): |
| 132 | + """Called when the shell loses focus.""" |
| 133 | + # Set the callback to use the dialog when errors occur outside the |
| 134 | + # shell. |
| 135 | + sys.excepthook = exceptionCallback |
| 136 | + |
| 137 | + if evt: |
| 138 | + evt.Skip() |
| 139 | + |
117 | 140 | def GetContextMenu(self): |
118 | 141 | """Override original method (wx.py.shell.Shell.GetContextMenu) |
119 | 142 | to localize context menu. Simply added _translate() to |
@@ -1069,9 +1092,6 @@ def DoFindNext(self, findData, findDlg=None): |
1069 | 1092 | start = 0 |
1070 | 1093 | loc = textstring.find(findstring, start) |
1071 | 1094 |
|
1072 | | - # Adjust for offset |
1073 | | - loc += 2 |
1074 | | - |
1075 | 1095 | # was it still not found? |
1076 | 1096 | if loc == -1: |
1077 | 1097 | dlg = dialogs.MessageDialog(self, message=_translate( |
|
0 commit comments