@@ -1,106 +1,107 | |||
|
1 | 1 | # This Python file uses the following encoding: utf-8 |
|
2 | 2 | import os |
|
3 | import os | |
|
4 | os.environ['QT_API'] = 'pyside2' | |
|
3 | 5 | print(os.getcwd()) |
|
4 | 6 | import sys |
|
5 | 7 | from PySide2.QtWidgets import QApplication, QMainWindow, QDockWidget |
|
6 | 8 | from PySide2.QtCore import QSize, Qt |
|
7 | 9 | from PySide2 import QtGui |
|
8 | import os | |
|
9 | 10 | sys.path.append(os.getcwd()) |
|
10 | 11 | from SciQLopBindings import SqpApplication, MainWindow, init_resources, load_plugins, SqpApplication_ctor |
|
11 | 12 | from qtconsole.rich_ipython_widget import RichJupyterWidget |
|
12 | 13 | from qtconsole.inprocess import QtInProcessKernelManager |
|
13 | 14 | |
|
14 | 15 | |
|
15 | 16 | class IPythonWidget(RichJupyterWidget): |
|
16 | 17 | """Live IPython console widget. |
|
17 | 18 | |
|
18 | 19 | .. image:: img/IPythonWidget.png |
|
19 | 20 | |
|
20 | 21 | :param custom_banner: Custom welcome message to be printed at the top of |
|
21 | 22 | the console. |
|
22 | 23 | """ |
|
23 | 24 | |
|
24 | 25 | def __init__(self, parent=None, custom_banner=None, *args, **kwargs): |
|
25 | 26 | if parent is not None: |
|
26 | 27 | kwargs["parent"] = parent |
|
27 | 28 | super(IPythonWidget, self).__init__(*args, **kwargs) |
|
28 | 29 | if custom_banner is not None: |
|
29 | 30 | self.banner = custom_banner |
|
30 | 31 | self.setWindowTitle(self.banner) |
|
31 | 32 | self.kernel_manager = kernel_manager = QtInProcessKernelManager() |
|
32 | 33 | kernel_manager.start_kernel() |
|
33 | 34 | self.kernel_client = kernel_client = self._kernel_manager.client() |
|
34 | 35 | kernel_client.start_channels() |
|
35 | 36 | |
|
36 | 37 | def stop(): |
|
37 | 38 | kernel_client.stop_channels() |
|
38 | 39 | kernel_manager.shutdown_kernel() |
|
39 | 40 | self.exit_requested.connect(stop) |
|
40 | 41 | |
|
41 | 42 | def sizeHint(self): |
|
42 | 43 | """Return a reasonable default size for usage in :class:`PlotWindow`""" |
|
43 | 44 | return QSize(500, 300) |
|
44 | 45 | |
|
45 | 46 | def pushVariables(self, variable_dict): |
|
46 | 47 | """ Given a dictionary containing name / value pairs, push those |
|
47 | 48 | variables to the IPython console widget. |
|
48 | 49 | |
|
49 | 50 | :param variable_dict: Dictionary of variables to be pushed to the |
|
50 | 51 | console's interactive namespace (```{variable_name: object, …}```) |
|
51 | 52 | """ |
|
52 | 53 | self.kernel_manager.kernel.shell.push(variable_dict) |
|
53 | 54 | |
|
54 | 55 | |
|
55 | 56 | class IPythonDockWidget(QDockWidget): |
|
56 | 57 | """Dock Widget including a :class:`IPythonWidget` inside |
|
57 | 58 | a vertical layout. |
|
58 | 59 | |
|
59 | 60 | .. image:: img/IPythonDockWidget.png |
|
60 | 61 | |
|
61 | 62 | :param available_vars: Dictionary of variables to be pushed to the |
|
62 | 63 | console's interactive namespace: ``{"variable_name": object, …}`` |
|
63 | 64 | :param custom_banner: Custom welcome message to be printed at the top of |
|
64 | 65 | the console |
|
65 | 66 | :param title: Dock widget title |
|
66 | 67 | :param parent: Parent :class:`qt.QMainWindow` containing this |
|
67 | 68 | :class:`qt.QDockWidget` |
|
68 | 69 | """ |
|
69 | 70 | def __init__(self, parent=None, available_vars=None, custom_banner=None, |
|
70 | 71 | title="Console"): |
|
71 | 72 | super(IPythonDockWidget, self).__init__(title, parent) |
|
72 | 73 | |
|
73 | 74 | self.ipyconsole = IPythonWidget(custom_banner=custom_banner) |
|
74 | 75 | |
|
75 | 76 | self.layout().setContentsMargins(0, 0, 0, 0) |
|
76 | 77 | self.setWidget(self.ipyconsole) |
|
77 | 78 | |
|
78 | 79 | if available_vars is not None: |
|
79 | 80 | self.ipyconsole.pushVariables(available_vars) |
|
80 | 81 | self.ipyconsole.pushVariables({"blah":self}) |
|
81 | 82 | |
|
82 | 83 | def showEvent(self, event): |
|
83 | 84 | """Make sure this widget is raised when it is shown |
|
84 | 85 | (when it is first created as a tab in PlotWindow or when it is shown |
|
85 | 86 | again after hiding). |
|
86 | 87 | """ |
|
87 | 88 | self.raise_() |
|
88 | 89 | |
|
89 | 90 | def print_process_id(): |
|
90 | 91 | print ('Process ID is:', os.getpid()) |
|
91 | 92 | |
|
92 | 93 | |
|
93 | 94 | if __name__ == "__main__": |
|
94 | 95 | init_resources() |
|
95 | 96 | app = SqpApplication_ctor(sys.argv) |
|
96 | 97 | QtGui.qApp = app |
|
97 | 98 | load_plugins(app) |
|
98 | 99 | main_window = MainWindow() |
|
99 | 100 | term = IPythonDockWidget(available_vars={"app":app, "main_window":main_window}, custom_banner="SciQLop IPython Console ") |
|
100 | 101 | main_window.addDockWidget(Qt.BottomDockWidgetArea, term) |
|
101 | 102 | main_window.show() |
|
102 | 103 | for file in os.listdir('plugins'): |
|
103 | 104 | if os.path.isfile(f"plugins/{file}"): |
|
104 | 105 | exec(open(f"plugins/{file}").read()) |
|
105 | 106 | sys.exit(app.exec_()) |
|
106 | 107 |
@@ -1,50 +1,50 | |||
|
1 | 1 | shiboken2 = find_program('shiboken2') |
|
2 | 2 | qmake = find_program('qmake-qt5','qmake') |
|
3 | 3 | |
|
4 | 4 | pymod = import('python') |
|
5 | 5 | python3 = pymod.find_installation('python3', modules:['PySide2','shiboken2', 'shiboken2_generator', 'numpy']) |
|
6 | python3_dep = python3.dependency() | |
|
6 | python3_dep = python3.dependency(embed:true) | |
|
7 | 7 | numpy_inc = run_command(python3, '-c', 'import numpy;print(numpy.get_include())').stdout().strip('\n') |
|
8 | 8 | |
|
9 | 9 | qt5_modules = ['QtCore','QtGui','QtWidgets'] |
|
10 | 10 | |
|
11 | 11 | qt_headers_path = run_command(qmake, '-query', 'QT_INSTALL_HEADERS').stdout().strip('\n') |
|
12 | 12 | generated_srcs = run_command(python3, 'src_list.py', 'meson').stdout().split(';') |
|
13 | 13 | |
|
14 | 14 | modules_arg = '--modules=@0@'.format(','.join(qt5_modules)) |
|
15 | 15 | |
|
16 | 16 | shiboken2_build_flags = run_command(python3, 'shiboken-helper.py', '--includes', modules_arg).stdout().strip('\n').split(' ') |
|
17 | 17 | shiboken2_link_flags = run_command(python3, 'shiboken-helper.py', '--libs', modules_arg).stdout().strip('\n').split(' ') |
|
18 | 18 | shiboken2_typesystem = run_command(python3, 'shiboken-helper.py', '--typesystem').stdout().strip('\n') |
|
19 | 19 | |
|
20 | 20 | sciqlop_bindings_incs = shiboken2_build_flags + [ |
|
21 | 21 | '-I'+meson.current_source_dir()+'/../../gui/include', |
|
22 | 22 | '-I'+meson.current_source_dir()+'/../../core/include', |
|
23 | 23 | '-I'+meson.current_source_dir()+'/../../subprojects/TimeSeries/include', |
|
24 | 24 | '-I'+meson.current_source_dir()+'/../../subprojects/cpp_utils/include', |
|
25 | 25 | '-I'+python3.get_path('include'), |
|
26 | 26 | '-I'+qt_headers_path, |
|
27 | 27 | '-I'+numpy_inc |
|
28 | 28 | ] |
|
29 | 29 | |
|
30 | 30 | foreach mod:qt5_modules |
|
31 | 31 | sciqlop_bindings_incs += ['-I'+qt_headers_path+'/'+mod] |
|
32 | 32 | endforeach |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | sciqlop_bindings_src = files('bindings.h', 'PyDataProvider.h', 'numpy_wrappers.h', 'numpy_wrappers.cpp') |
|
36 | 36 | |
|
37 | 37 | subdir('SciQLopBindings') |
|
38 | 38 | subdir('plugins') |
|
39 | 39 | |
|
40 | 40 | shiboken_dep = declare_dependency(compile_args: shiboken2_build_flags, link_args: shiboken2_link_flags) |
|
41 | 41 | |
|
42 | 42 | sciqlop_bindings = python3.extension_module('SciQLopBindings',sciqlop_bindings_src,shiboken2_generator_out, |
|
43 | 43 | dependencies : [sciqlop_app_dep, python3_dep, shiboken_dep, cpp_utils_dep], |
|
44 | 44 | include_directories : numpy_inc |
|
45 | 45 | ) |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | configure_file(input:'main.py', output:'main.py', copy:true) |
|
49 | 49 | |
|
50 |
executable('sciqlop', 'main.cpp', dependencies :python3 |
|
|
50 | executable('sciqlop', 'main.cpp', dependencies :python3_dep) |
General Comments 0
You need to be logged in to leave comments.
Login now