Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit 09964a3

Browse files
committed
Initial import
0 parents  commit 09964a3

25 files changed

+7345
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png filter=lfs diff=lfs merge=lfs -text

.gitignore

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.dll
6+
7+
# os-specific stuff
8+
.DS_Store
9+
10+
# imgui runtime configuration
11+
imgui.ini
12+
13+
# C extensions
14+
*.so
15+
16+
# Cython related
17+
cython_debug/
18+
implot/*.cpp
19+
implot/*.h
20+
implot/*.c
21+
22+
# Distribution / packaging
23+
.Python
24+
env/
25+
build/
26+
develop-eggs/
27+
dist/
28+
downloads/
29+
eggs/
30+
.eggs/
31+
lib/
32+
lib64/
33+
parts/
34+
sdist/
35+
var/
36+
*.egg-info/
37+
.installed.cfg
38+
*.egg
39+
completion.svg
40+
41+
# Visual Studio stuff
42+
.vs/
43+
44+
45+
# PyInstaller
46+
# Usually these files are written by a python script from a template
47+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
48+
*.manifest
49+
*.spec
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# Unit test / coverage reports
56+
htmlcov/
57+
.tox/
58+
.coverage
59+
.coverage.*
60+
.cache
61+
nosetests.xml
62+
coverage.xml
63+
*,cover
64+
.hypothesis/
65+
66+
# Translations
67+
*.mo
68+
*.pot
69+
70+
# Django stuff:
71+
*.log
72+
local_settings.py
73+
74+
# Flask stuff:
75+
instance/
76+
.webassets-cache
77+
78+
# Scrapy stuff:
79+
.scrapy
80+
81+
# Sphinx documentation
82+
doc/_build/
83+
doc/build
84+
85+
# following is autogenerated
86+
doc/source/readme.rst
87+
88+
# PyBuilder
89+
target/
90+
91+
# IPython Notebook
92+
.ipynb_checkpoints
93+
94+
# pyenv
95+
.python-version
96+
97+
# celery beat schedule file
98+
celerybeat-schedule
99+
100+
# dotenv
101+
.env
102+
103+
# virtualenv
104+
venv/
105+
ENV/
106+
107+
# Spyder project settings
108+
.spyderproject
109+
110+
# Rope project settings
111+
.ropeproject
112+
113+
# Pycharm project settings
114+
.idea/
115+
116+
# Visual Studio Code project settings
117+
.vscode/
118+
119+
# Bootstrap marker
120+
.bootstrapped
121+
122+
# Fonts
123+
*.ttf
124+
*.otf

.gitmodules

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[submodule "imgui-cpp"]
2+
path = imgui-cpp
3+
url = https://github.com/ocornut/imgui.git
4+
5+
[submodule "implot-cpp"]
6+
path = implot-cpp
7+
url = https://github.com/epezent/implot.git

LICENSE

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2016, Michał Jaworski
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of pyimgui nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+

MANIFEST.in

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include README.md
2+
include LICENSE
3+
4+
# Cython sources
5+
recursive-include implot *.pyx *.pxd
6+
7+
# Cython-generated C++ sources
8+
recursive-include implot *.cpp *.h
9+
10+
# Additional internal ImgGui configuration
11+
recursive-include config-cpp *.cpp *.h
12+
13+
# ImGui sources
14+
recursive-include imgui-cpp *.cpp *.h
15+
prune imgui-cpp/examples
16+
prune imgui-cpp/extra_fonts
17+
18+
# ImPlot sources
19+
recursive-include implot-cpp *.cpp *.h
20+
21+
# ansifeed sources
22+
recursive-include ansifeed-cpp *.cpp *.h

Makefile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.PHONY: help
2+
help:
3+
@echo "Please use \`make <target>' where <target> is one of"
4+
@echo " clean to clean local environment from stale build files"
5+
@echo " build to build and install for development"
6+
@echo " rebuild to rebuild from scratch"
7+
@echo " livedoc to serve live documentation"
8+
@echo " bootstrap to bootstrap whole development environment"
9+
@echo " completion to get detailed overview on completion progress"
10+
@echo " coverage to run tests with coverage"
11+
12+
13+
# note: empty recipe as alias for .bootstrapped target
14+
bootstrap: .bootstrapped ;
15+
16+
.bootstrapped:
17+
@echo "Bootstrapping project environment ..."
18+
git submodule update --init
19+
pip install -r doc/requirements-dev.txt
20+
@touch .bootstrapped
21+
22+
23+
.PHONY: clean
24+
clean:
25+
rm -rf implot/*.cpp implot/*.c implot/*.h implot/*.so build/*
26+
27+
28+
.PHONY: build
29+
build: bootstrap
30+
_CYTHONIZE_WITH_COVERAGE=1 python -m pip install -e . -v
31+
# python ci/completion.py -o README.md with-pxd implot/cimplot.pxd
32+
33+
34+
.PHONY: rebuild
35+
rebuild: clean build
36+
@echo 'Done!'
37+
38+
39+
# .PHONY: livedoc
40+
# livedoc: build
41+
# sphinx-autobuild doc/source/ doc/build/html
42+
43+
44+
# .PHONY: coverage
45+
# coverage: build
46+
# coverage run --source imgui -m pytest
47+
# coverage report
48+
# coverage html
49+
50+
51+
# .PHONY: completion
52+
# completion:
53+
# _CYTHONIZE_WITH_COVERAGE=1 python -m pip install -e . -v
54+
# @python ci/completion.py missing `find build/ -name imgui.o -print -quit` `find build/ -name core.o -print -quit`
55+
# @python ci/completion.py with-nm `find build/ -name imgui.o -print -quit` `find build/ -name core.o -print -quit`
56+
57+
# .PHONY: ditribute
58+
# distribute: clean
59+
# pip install -U Cython setuptools twine
60+
# python setup.py build
61+
# python setup.py sdist

PROGRESS.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 2021-03-24
2+
3+
Started isolating the ImPlot parts from the pyimgui.
4+
We still need the complete ImGui C++ source to create a functional pyimplot binding.
5+
Creating just `implot` module at the moment.
6+
Still using all the pyimgui *.pxd, except for core.pxd.
7+
8+
## Results 1
9+
10+
$ python3
11+
Python 3.9.2 (default, Mar 12 2021, 13:13:11)
12+
[GCC 7.5.0] on linux
13+
Type "help", "copyright", "credits" or "license" for more information.
14+
>>> import implot
15+
>>> dir(implot)
16+
['AXIS_FLAGS_AUTO_FIT', 'AXIS_FLAGS_INVERT', 'AXIS_FLAGS_LOCK', 'AXIS_FLAGS_LOCK_MAX', 'AXIS_FLAGS_LOCK_MIN', 'AXIS_FLAGS_LOD_SCALE', 'AXIS_FLAGS_NONE', 'AXIS_FLAGS_NO_DECORATIONS', 'AXIS_FLAGS_NO_GRID_LINES', 'AXIS_FLAGS_NO_LABEL', 'AXIS_FLAGS_NO_TICK_LABELS', 'AXIS_FLAGS_NO_TICK_MARKS', 'AXIS_FLAGS_TIME', 'COLOR_COUNT', 'IMPLOT_AUTO', 'IMPLOT_AUTO_COL', 'IMPLOT_VERSION', 'ImGuiError', 'PLOT_FLAGS_ANTI_ALIASED', 'PLOT_FLAGS_CANVAS_ONLY', 'PLOT_FLAGS_CROSSHAIRS', 'PLOT_FLAGS_EQUAL', 'PLOT_FLAGS_NONE', 'PLOT_FLAGS_NO_BOX_SELECT', 'PLOT_FLAGS_NO_CHILD', 'PLOT_FLAGS_NO_HIGHLIGHT', 'PLOT_FLAGS_NO_LEGEND', 'PLOT_FLAGS_NO_MENUS', 'PLOT_FLAGS_NO_MOUSE_POS', 'PLOT_FLAGS_NO_TITLE', 'PLOT_FLAGS_QUERY', 'PLOT_FLAGS_YAXIS2', 'PLOT_FLAGS_YAXIS3', 'PlotStyle', 'VERSION', 'Vec2', 'Vec4', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'add_colormap', 'annotate', 'annotate_clamped', 'annotate_clamped_color', 'annotate_color', 'begin_drag_drop_source', 'begin_drag_drop_source_item', 'begin_drag_drop_source_x', 'begin_drag_drop_source_y', 'begin_drag_drop_target', 'begin_drag_drop_target_legend', 'begin_drag_drop_target_x', 'begin_drag_drop_target_y', 'begin_legend_popup', 'begin_plot', 'bust_color_cache', 'colormap_button', 'colormap_icon', 'colormap_scale', 'colormap_slider', 'create_context', 'destroy_context', 'drag_line_x', 'drag_line_y', 'drag_point', 'end_drag_drop_source', 'end_drag_drop_target', 'end_legend_popup', 'end_plot', 'fit_next_plot_axes', 'get_colormap_color', 'get_colormap_count', 'get_colormap_index', 'get_colormap_name', 'get_colormap_size', 'get_current_context', 'get_last_item_color', 'get_marker_name', 'get_plot_limits', 'get_plot_mouse_pos', 'get_plot_pos', 'get_plot_query', 'get_plot_size', 'get_style', 'get_style_color_name', 'hide_next_item', 'is_legend_entry_hovered', 'is_plot_hovered', 'is_plot_queried', 'is_plot_x_axis_hovered', 'is_plot_y_axis_hovered', 'item_icon_idx', 'item_icon_rgba', 'namedtuple', 'next_colormap_color', 'pixels_to_plot', 'plot', 'plot_bars1', 'plot_bars2', 'plot_barsg', 'plot_barsh1', 'plot_barsh2', 'plot_barshg', 'plot_digital', 'plot_digitalg', 'plot_dummy', 'plot_error_bars1', 'plot_error_bars2', 'plot_error_barsh1', 'plot_error_barsh2', 'plot_heatmap', 'plot_histogram', 'plot_histogram_2d', 'plot_hlines1', 'plot_image', 'plot_line1', 'plot_line2', 'plot_lineg', 'plot_pie_chart', 'plot_scatter1', 'plot_scatter2', 'plot_scatterg', 'plot_shaded1', 'plot_shaded2', 'plot_shaded3', 'plot_shadedg', 'plot_stairs1', 'plot_stairs2', 'plot_stairsg', 'plot_stems1', 'plot_stems2', 'plot_text', 'plot_to_pixels', 'plot_vlines1', 'pop_colormap', 'pop_plot_clip_rect', 'pop_style_color', 'pop_style_var', 'push_colormap', 'push_colormap_name', 'push_plot_clip_rect', 'push_style_color', 'push_style_var', 'sample_colormap', 'set_current_context', 'set_imgui_context', 'set_legend_location', 'set_mouse_pos_location', 'set_next_error_bar_style', 'set_next_fill_style', 'set_next_line_style', 'set_next_marker_style', 'set_next_plot_limits', 'set_next_plot_limits_x', 'set_next_plot_limits_y', 'set_next_plot_ticks_x', 'set_next_plot_ticks_x_range', 'set_next_plot_ticks_y', 'set_next_plot_ticks_y_range', 'set_plot_y_axis', 'show_colormap_selector', 'show_demo_window', 'show_metrics_window', 'show_style_editor', 'show_style_selector', 'show_user_guide', 'style_colors_auto', 'style_colors_classic', 'style_colors_dark', 'style_colors_light', 'warnings']
17+
>>>
18+

README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# pyimplot
2+
3+
Python bindings for the amazing
4+
[ImPlot](https://github.com/ocornut/imgui), GPU accelerated plotting library for
5+
[Dear ImGui](https://github.com/ocornut/imgui).
6+
7+
Warning: This is alpha quality code.
8+
9+
Documentation: TODO
10+
11+
# ImPlot
12+
13+
NOTES from the time when this was introduced into the pyimgui codebase!
14+
15+
It is not clear to me if this is the best place for ImPlot python binding. The
16+
question remains if it would be better to place this code into a separate project,
17+
or provide it as part of pyimgui. As of now the latter has been chosen due to my
18+
laziness, poor undestanding of cython and also due to some obstacles
19+
encountered during the process of creating this binding.
20+
21+
Read on if you are interested in couple of details.
22+
23+
As per ImGui and ImPlot documentation using them both as shared library is not recomended.
24+
In case of python binding this is exactly what is being done. The ImGui part ends up being
25+
a shared library and plot becomes a separate shared library. Creating a single shared library
26+
(with ImGui and ImPlot) does not sound like a good idea at all so lets not go there. Not going
27+
with shared library is also something that we can not do; AFAICT due to the way cypthon does
28+
its business (I might be wrong).
29+
30+
At the level of C++ that cython wraps into python module and functions, ImPlot want access
31+
to `imgui.h` and `imgui_internal.h`. For example ImPlot uses `ImTextureID`, `ImGuiCond`,
32+
`ImGuiMouseButton`, `ImGuiKeyModFlags`, `ImGuiDragDropFlags`, `ImU32`, `ImDrawList`, `ImGuiContext`,
33+
`ImVec2`, `ImVec4` and alike. These need to be exposed a cython level, too. Currently,
34+
these come from `cimgui` and `internal` modules provided by pyimgui binding. Using them is
35+
as simple as adding a `cimport` line to a `cimplot.pxd`. pyimgui (c)imports were requiered for
36+
`plot.pyx` as well:
37+
38+
cimport cimplot
39+
cimport cimgui
40+
cimport core
41+
cimport enums
42+
43+
If the ImPlot is placed in a separate project/repo these would need to be redefined.
44+
45+
46+
When I tried to compile the ImPlot C++ code for cython binding (without adding ImGui sources)
47+
for that shared library, doing `import imgui` in a user script fails with `GImGui` being undefined.
48+
Have I missed something there during the library build?! I don't know.
49+
50+
If the ImPlot binding is separate from ImGui binding (cleanest approach), I'm not sure how
51+
the user script would behave if pyimgui and pyimplot would be based of different ImGui C++ code.
52+
Might be a non-issue, but I just do not know.
53+
54+
Have any ideas or suggestions on the above topics? Bring them up, please!
55+
56+
57+
# Development tips
58+
59+
In order to build and install project locally ,ake sure you have created and
60+
activated virtual environment using `virtualenv` or `python -m venv` (for newer
61+
Python releases). Then you can just run:
62+
63+
make build
64+
65+
This command will bootstrap whole environment (pull git submodules, install
66+
dev requirements etc.) and build the project. `make` will automatically install
67+
`implot` in the *development/editable* mode.

config-cpp/py_imconfig.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "py_imconfig.h"
2+
#include "plot.h"
3+
4+
// note: error type can be controlled during compilation
5+
#ifndef PYIMGUI_CUSTOM_EXCEPTION
6+
#define PYIMGUI_EXC_TYPE PyExc_RuntimeError
7+
#else
8+
#define PYIMGUI_EXC_TYPE ImGuiError
9+
#endif
10+
11+
12+
// ImGui does not throw exceptions whenever error occurs. The only way to add
13+
// error handling is to provide custom IM_ASSERT definition. Here we can
14+
// set Python interpreter exception and also throw C++ exception to interrupt
15+
// any function call in order to avoid any memory corruption.
16+
void __py_assert(const char* msg) {
17+
// At first, set the Python exception state so we don't need to provide
18+
// custom exception translation function everywhere in Cython code
19+
PyErr_SetString(PYIMGUI_EXC_TYPE, msg);
20+
21+
// Throw anything so on the Cython side we can can catch it with
22+
// something like:
23+
//
24+
// cdef extern from "imgui.h" namespace "ImGui":
25+
// void PopStyleVar(int) except +
26+
throw msg;
27+
}

0 commit comments

Comments
 (0)