source: sasview/src/sas/qtgui/Utilities/IPythonWidget.py @ 6138f73

Last change on this file since 6138f73 was fbfc488, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

More Qt5 related fixes.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1from PyQt5 import QtCore
2from PyQt5 import QtGui
3from PyQt5 import QtWidgets
4
5from PyQt5 import QtSvg
6
7def new_load_qt(api_options):
8    return QtCore, QtGui, QtSvg, 'pyqt'
9
10def 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
16from IPython.external import  qt_loaders
17from 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
23from qtconsole.rich_jupyter_widget import RichJupyterWidget
24
25MODULES_TO_IMPORT = [
26    ('sas', 'sas'),
27    ('sasmodels', 'sasmodels'),
28    ('numpy', 'np')]
29
30class 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))
Note: See TracBrowser for help on using the repository browser.