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