kernel_mixins.py
94 lines
| 2.8 KiB
| text/x-python
|
PythonLexer
|
r16567 | """Defines a KernelManager that provides signals and slots.""" | ||
# Copyright (c) IPython Development Team. | ||||
# Distributed under the terms of the Modified BSD License. | ||||
|
r8408 | |||
from IPython.external.qt import QtCore | ||||
|
r8456 | from IPython.utils.traitlets import HasTraits, Type | ||
|
r13347 | from .util import MetaQObjectHasTraits, SuperQObject | ||
|
r8408 | |||
class ChannelQObject(SuperQObject): | ||||
# Emitted when the channel is started. | ||||
started = QtCore.Signal() | ||||
# Emitted when the channel is stopped. | ||||
stopped = QtCore.Signal() | ||||
|
r19210 | # Emitted when any message is received. | ||
message_received = QtCore.Signal(object) | ||||
|
r8408 | def start(self): | ||
""" Reimplemented to emit signal. | ||||
""" | ||||
super(ChannelQObject, self).start() | ||||
self.started.emit() | ||||
def stop(self): | ||||
""" Reimplemented to emit signal. | ||||
""" | ||||
super(ChannelQObject, self).stop() | ||||
self.stopped.emit() | ||||
def call_handlers_later(self, *args, **kwds): | ||||
""" Call the message handlers later. | ||||
""" | ||||
do_later = lambda: self.call_handlers(*args, **kwds) | ||||
QtCore.QTimer.singleShot(0, do_later) | ||||
|
r19222 | def call_handlers(self, msg): | ||
self.message_received.emit(msg) | ||||
|
r8408 | def process_events(self): | ||
""" Process any pending GUI events. | ||||
""" | ||||
QtCore.QCoreApplication.instance().processEvents() | ||||
|
r19222 | def flush(self): | ||
""" Reimplemented to ensure that signals are dispatched immediately. | ||||
""" | ||||
super(ChannelQObject, self).flush() | ||||
self.process_events() | ||||
|
r8408 | |||
|
r13359 | class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | ||
|
r10308 | |||
_timer = None | ||||
|
r13359 | class QtKernelManagerMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | ||
|
r10308 | """ A KernelClient that provides signals and slots. | ||
""" | ||||
kernel_restarted = QtCore.Signal() | ||||
|
r13359 | class QtKernelClientMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): | ||
|
r10288 | """ A KernelClient that provides signals and slots. | ||
|
r8408 | """ | ||
|
r10288 | # Emitted when the kernel client has started listening. | ||
|
r8408 | started_channels = QtCore.Signal() | ||
|
r10288 | # Emitted when the kernel client has stopped listening. | ||
|
r8408 | stopped_channels = QtCore.Signal() | ||
#--------------------------------------------------------------------------- | ||||
|
r10288 | # 'KernelClient' interface | ||
|
r8408 | #--------------------------------------------------------------------------- | ||
#------ Channel management ------------------------------------------------- | ||||
def start_channels(self, *args, **kw): | ||||
""" Reimplemented to emit signal. | ||||
""" | ||||
|
r10288 | super(QtKernelClientMixin, self).start_channels(*args, **kw) | ||
|
r8408 | self.started_channels.emit() | ||
def stop_channels(self): | ||||
""" Reimplemented to emit signal. | ||||
""" | ||||
|
r10288 | super(QtKernelClientMixin, self).stop_channels() | ||
|
r8408 | self.stopped_channels.emit() | ||