Show More
@@ -1,52 +1,53 b'' | |||||
1 | """ Defines a KernelClient that provides signals and slots. |
|
1 | """ Defines a KernelClient that provides signals and slots. | |
2 | """ |
|
2 | """ | |
3 |
|
3 | |||
4 | from IPython.external.qt import QtCore |
|
4 | from IPython.external.qt import QtCore | |
5 |
|
5 | |||
6 | # Local imports |
|
6 | # Local imports | |
7 | from IPython.utils.traitlets import Bool |
|
7 | from IPython.utils.traitlets import Bool, DottedObjectName | |
8 |
|
8 | |||
9 | from IPython.kernel import KernelManager |
|
9 | from IPython.kernel import KernelManager | |
10 | from IPython.kernel.restarter import KernelRestarter |
|
10 | from IPython.kernel.restarter import KernelRestarter | |
11 |
|
11 | |||
12 | from .kernel_mixins import QtKernelManagerMixin, QtKernelRestarterMixin |
|
12 | from .kernel_mixins import QtKernelManagerMixin, QtKernelRestarterMixin | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class QtKernelRestarter(KernelRestarter, QtKernelRestarterMixin): |
|
15 | class QtKernelRestarter(KernelRestarter, QtKernelRestarterMixin): | |
16 |
|
16 | |||
17 | def start(self): |
|
17 | def start(self): | |
18 | if self._timer is None: |
|
18 | if self._timer is None: | |
19 | self._timer = QtCore.QTimer() |
|
19 | self._timer = QtCore.QTimer() | |
20 | self._timer.timeout.connect(self.poll) |
|
20 | self._timer.timeout.connect(self.poll) | |
21 | self._timer.start(self.time_to_dead * 1000) |
|
21 | self._timer.start(self.time_to_dead * 1000) | |
22 |
|
22 | |||
23 | def stop(self): |
|
23 | def stop(self): | |
24 | self._timer.stop() |
|
24 | self._timer.stop() | |
25 |
|
25 | |||
26 | def poll(self): |
|
26 | def poll(self): | |
27 | super(QtKernelRestarter, self).poll() |
|
27 | super(QtKernelRestarter, self).poll() | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | class QtKernelManager(KernelManager, QtKernelManagerMixin): |
|
30 | class QtKernelManager(KernelManager, QtKernelManagerMixin): | |
31 | """A KernelManager with Qt signals for restart""" |
|
31 | """A KernelManager with Qt signals for restart""" | |
32 |
|
32 | |||
|
33 | client_class = DottedObjectName('IPython.qt.client.QtKernelClient') | |||
33 | autorestart = Bool(True, config=True) |
|
34 | autorestart = Bool(True, config=True) | |
34 |
|
35 | |||
35 | def start_restarter(self): |
|
36 | def start_restarter(self): | |
36 | if self.autorestart and self.has_kernel: |
|
37 | if self.autorestart and self.has_kernel: | |
37 | if self._restarter is None: |
|
38 | if self._restarter is None: | |
38 | self._restarter = QtKernelRestarter( |
|
39 | self._restarter = QtKernelRestarter( | |
39 | kernel_manager=self, |
|
40 | kernel_manager=self, | |
40 | parent=self, |
|
41 | parent=self, | |
41 | log=self.log, |
|
42 | log=self.log, | |
42 | ) |
|
43 | ) | |
43 | self._restarter.add_callback(self._handle_kernel_restarted) |
|
44 | self._restarter.add_callback(self._handle_kernel_restarted) | |
44 | self._restarter.start() |
|
45 | self._restarter.start() | |
45 |
|
46 | |||
46 | def stop_restarter(self): |
|
47 | def stop_restarter(self): | |
47 | if self.autorestart: |
|
48 | if self.autorestart: | |
48 | if self._restarter is not None: |
|
49 | if self._restarter is not None: | |
49 | self._restarter.stop() |
|
50 | self._restarter.stop() | |
50 |
|
51 | |||
51 | def _handle_kernel_restarted(self): |
|
52 | def _handle_kernel_restarted(self): | |
52 | self.kernel_restarted.emit() |
|
53 | self.kernel_restarted.emit() |
General Comments 0
You need to be logged in to leave comments.
Login now