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