1 | from PyQt5 import QtCore |
---|
2 | from PyQt5 import QtGui |
---|
3 | from PyQt5 import QtWidgets |
---|
4 | |
---|
5 | ##from PyQt4 import QtSvg |
---|
6 | |
---|
7 | def new_load_qt(api_options): |
---|
8 | return QtCore, QtGui, QtSvg, 'pyqt' |
---|
9 | |
---|
10 | def qtconsole_new_load_qt(api_options): |
---|
11 | # Alias PyQt-specific functions for PySide compatibility. |
---|
12 | QtCore.Signal = QtCore.pyqtSignal |
---|
13 | QtCore.Slot = QtCore.pyqtSlot |
---|
14 | return QtCore, QtGui, QtSvg, 'pyqt' |
---|
15 | |
---|
16 | from IPython.external import qt_loaders |
---|
17 | from qtconsole import qt_loaders as qtconsole_qt_loaders |
---|
18 | # Do some monkey patching to satisfy pyinstaller complaining |
---|
19 | # about pyside/pyqt confusion |
---|
20 | qt_loaders.load_qt = new_load_qt |
---|
21 | qtconsole_qt_loaders.load_qt = qtconsole_new_load_qt |
---|
22 | |
---|
23 | from qtconsole.rich_jupyter_widget import RichJupyterWidget |
---|
24 | |
---|
25 | MODULES_TO_IMPORT = [ |
---|
26 | ('sas', 'sas'), |
---|
27 | ('sasmodels', 'sasmodels'), |
---|
28 | ('numpy', 'np')] |
---|
29 | |
---|
30 | class IPythonWidget(RichJupyterWidget): |
---|
31 | def __init__(self, parent=None, **kwargs): |
---|
32 | super(self.__class__, self).__init__(parent) |
---|
33 | from qtconsole.inprocess import QtInProcessKernelManager |
---|
34 | from IPython.lib import guisupport |
---|
35 | app = guisupport.get_app_qt4() |
---|
36 | |
---|
37 | # Create an in-process kernel |
---|
38 | kernel_manager = QtInProcessKernelManager() |
---|
39 | kernel_manager.start_kernel() |
---|
40 | kernel = kernel_manager.kernel |
---|
41 | kernel.gui = 'qt4' |
---|
42 | |
---|
43 | kernel_client = kernel_manager.client() |
---|
44 | kernel_client.start_channels() |
---|
45 | |
---|
46 | self.kernel_manager = kernel_manager |
---|
47 | self.kernel_client = kernel_client |
---|
48 | |
---|
49 | self.kernel_manager.kernel.shell.run_code( |
---|
50 | '\n'.join('import %s as %s' % t for t in MODULES_TO_IMPORT)) |
---|