source: sasview/src/sas/qtgui/Utilities/IPythonWidget.py @ 895e7359

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 895e7359 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
RevLine 
[fef38e8]1from PyQt4 import QtCore, QtGui, QtSvg
2
[985ad94]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
[fef38e8]12from IPython.external import  qt_loaders
13from qtconsole import qt_loaders as qtconsole_qt_loaders
[985ad94]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)
[fef38e8]29        from qtconsole.inprocess import QtInProcessKernelManager
30        from IPython.lib import guisupport
[985ad94]31        app = guisupport.get_app_qt4()
32
[fef38e8]33        # Create an in-process kernel
[985ad94]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.