kernel_mixins.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """Defines a KernelManager that provides signals and slots."""
  2. # Copyright (c) Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from qtpy import QtCore
  5. from traitlets import HasTraits, Type
  6. from .util import MetaQObjectHasTraits, SuperQObject
  7. from .comms import CommManager
  8. class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
  9. _timer = None
  10. class QtKernelManagerMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
  11. """ A KernelClient that provides signals and slots.
  12. """
  13. kernel_restarted = QtCore.Signal()
  14. class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
  15. """ A KernelClient that provides signals and slots.
  16. """
  17. # Emitted when the kernel client has started listening.
  18. started_channels = QtCore.Signal()
  19. # Emitted when the kernel client has stopped listening.
  20. stopped_channels = QtCore.Signal()
  21. #---------------------------------------------------------------------------
  22. # 'KernelClient' interface
  23. #---------------------------------------------------------------------------
  24. def __init__(self, *args, **kwargs):
  25. super(QtKernelClientMixin, self).__init__(*args, **kwargs)
  26. self.comm_manager = None
  27. #------ Channel management -------------------------------------------------
  28. def start_channels(self, *args, **kw):
  29. """ Reimplemented to emit signal.
  30. """
  31. super(QtKernelClientMixin, self).start_channels(*args, **kw)
  32. self.started_channels.emit()
  33. self.comm_manager = CommManager(parent=self, kernel_client=self)
  34. def stop_channels(self):
  35. """ Reimplemented to emit signal.
  36. """
  37. super(QtKernelClientMixin, self).stop_channels()
  38. self.stopped_channels.emit()
  39. self.comm_manager = None