source: sasview/src/sas/qtgui/Utilities/IPythonWidget.py @ 6b43c58

Last change on this file since 6b43c58 was fef38e8, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Startup time improvements - hiding expensive imports and such

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