##// END OF EJS Templates
* Added ability to interrupt a kernel to FrontendWidget...
epatters -
Show More
@@ -11,7 +11,7 b' class CallTipWidget(QtGui.QLabel):'
11 """
11 """
12
12
13 #--------------------------------------------------------------------------
13 #--------------------------------------------------------------------------
14 # 'QWidget' interface
14 # 'QObject' interface
15 #--------------------------------------------------------------------------
15 #--------------------------------------------------------------------------
16
16
17 def __init__(self, parent):
17 def __init__(self, parent):
@@ -34,12 +34,23 b' class CallTipWidget(QtGui.QLabel):'
34 self.setWindowOpacity(self.style().styleHint(
34 self.setWindowOpacity(self.style().styleHint(
35 QtGui.QStyle.SH_ToolTipLabel_Opacity, None, self) / 255.0)
35 QtGui.QStyle.SH_ToolTipLabel_Opacity, None, self) / 255.0)
36
36
37 #--------------------------------------------------------------------------
38 # 'QWidget' interface
39 #--------------------------------------------------------------------------
40
37 def hideEvent(self, event):
41 def hideEvent(self, event):
38 """ Reimplemented to disconnect the cursor movement handler.
42 """ Reimplemented to disconnect the cursor movement handler.
39 """
43 """
40 QtGui.QLabel.hideEvent(self, event)
44 QtGui.QLabel.hideEvent(self, event)
41 self.parent().cursorPositionChanged.disconnect(self._update_tip)
45 self.parent().cursorPositionChanged.disconnect(self._update_tip)
42
46
47 def keyPressEvent(self, event):
48 """ Reimplemented to hide on certain key presses.
49 """
50 if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return,
51 QtCore.Qt.Key_Escape):
52 self.hide()
53
43 def paintEvent(self, event):
54 def paintEvent(self, event):
44 """ Reimplemented to paint the background panel.
55 """ Reimplemented to paint the background panel.
45 """
56 """
@@ -123,6 +123,8 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
123 QtCore.Qt.Key_P : QtCore.Qt.Key_Up,
123 QtCore.Qt.Key_P : QtCore.Qt.Key_Up,
124 QtCore.Qt.Key_N : QtCore.Qt.Key_Down,
124 QtCore.Qt.Key_N : QtCore.Qt.Key_Down,
125 QtCore.Qt.Key_D : QtCore.Qt.Key_Delete, }
125 QtCore.Qt.Key_D : QtCore.Qt.Key_Delete, }
126 _shortcuts = set(_ctrl_down_remap.keys() +
127 [ QtCore.Qt.Key_C, QtCore.Qt.Key_V ])
126
128
127 #---------------------------------------------------------------------------
129 #---------------------------------------------------------------------------
128 # 'QObject' interface
130 # 'QObject' interface
@@ -170,7 +172,7 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
170 sys.platform != 'darwin' and \
172 sys.platform != 'darwin' and \
171 event.type() == QtCore.QEvent.ShortcutOverride and \
173 event.type() == QtCore.QEvent.ShortcutOverride and \
172 self._control_down(event.modifiers()) and \
174 self._control_down(event.modifiers()) and \
173 event.key() in self._ctrl_down_remap:
175 event.key() in self._shortcuts:
174 event.accept()
176 event.accept()
175 return True
177 return True
176 else:
178 else:
@@ -220,6 +222,9 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
220 cursor.removeSelectedText()
222 cursor.removeSelectedText()
221 intercepted = True
223 intercepted = True
222
224
225 elif key == QtCore.Qt.Key_X:
226 intercepted = True
227
223 elif key == QtCore.Qt.Key_Y:
228 elif key == QtCore.Qt.Key_Y:
224 self.paste()
229 self.paste()
225 intercepted = True
230 intercepted = True
@@ -1,3 +1,6 b''
1 # Standard library imports
2 import signal
3
1 # System library imports
4 # System library imports
2 from pygments.lexers import PythonLexer
5 from pygments.lexers import PythonLexer
3 from PyQt4 import QtCore, QtGui
6 from PyQt4 import QtCore, QtGui
@@ -77,14 +80,18 b' class FrontendWidget(HistoryConsoleWidget):'
77 """ Reimplemented to hide calltips.
80 """ Reimplemented to hide calltips.
78 """
81 """
79 self._call_tip_widget.hide()
82 self._call_tip_widget.hide()
80 return super(FrontendWidget, self).focusOutEvent(event)
83 super(FrontendWidget, self).focusOutEvent(event)
81
84
82 def keyPressEvent(self, event):
85 def keyPressEvent(self, event):
83 """ Reimplemented to hide calltips.
86 """ Reimplemented to allow calltips to process events and to send
87 signals to the kernel.
84 """
88 """
85 if event.key() == QtCore.Qt.Key_Escape:
89 if self._executing and event.key() == QtCore.Qt.Key_C and \
86 self._call_tip_widget.hide()
90 self._control_down(event.modifiers()):
87 return super(FrontendWidget, self).keyPressEvent(event)
91 self._interrupt_kernel()
92 else:
93 self._call_tip_widget.keyPressEvent(event)
94 super(FrontendWidget, self).keyPressEvent(event)
88
95
89 #---------------------------------------------------------------------------
96 #---------------------------------------------------------------------------
90 # 'ConsoleWidget' abstract interface
97 # 'ConsoleWidget' abstract interface
@@ -168,6 +175,10 b' class FrontendWidget(HistoryConsoleWidget):'
168 xreq.complete_reply.disconnect(self._handle_complete_reply)
175 xreq.complete_reply.disconnect(self._handle_complete_reply)
169 xreq.object_info_reply.disconnect(self._handle_object_info_reply)
176 xreq.object_info_reply.disconnect(self._handle_object_info_reply)
170
177
178 # Handle the case where the old kernel manager is still listening.
179 if self._kernel_manager.is_listening:
180 self._stopped_listening()
181
171 # Set the new kernel manager.
182 # Set the new kernel manager.
172 self._kernel_manager = kernel_manager
183 self._kernel_manager = kernel_manager
173 if kernel_manager is None:
184 if kernel_manager is None:
@@ -240,6 +251,15 b' class FrontendWidget(HistoryConsoleWidget):'
240 text = unicode(cursor.selectedText())
251 text = unicode(cursor.selectedText())
241 return self._completion_lexer.get_context(text)
252 return self._completion_lexer.get_context(text)
242
253
254 def _interrupt_kernel(self):
255 """ Attempts to the interrupt the kernel.
256 """
257 if self.kernel_manager.has_kernel:
258 self.kernel_manager.signal_kernel(signal.SIGINT)
259 else:
260 self.appendPlainText('Kernel process is either remote or '
261 'unspecified. Cannot interrupt.\n')
262
243 #------ Signal handlers ----------------------------------------------------
263 #------ Signal handlers ----------------------------------------------------
244
264
245 def _document_contents_change(self, position, removed, added):
265 def _document_contents_change(self, position, removed, added):
General Comments 0
You need to be logged in to leave comments. Login now