Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ recursive-include imgui *.cpp *.h
# Additional internal ImgGui configuration
recursive-include config-cpp *.cpp *.h

# ImGui sources
# ImGui / Implot sources
recursive-include imgui-cpp *.cpp *.h
recursive-include implot-cpp *.cpp *.h

prune imgui-cpp/examples
prune imgui-cpp/extra_fonts

Expand Down
235 changes: 125 additions & 110 deletions imgui/__init__.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions imgui/ansifeed.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Notes:
`✗` marks API element as "yet to be mapped
"""

cimport cimgui
from imgui cimport cimgui

from cimgui cimport ImVec4
from imgui.cimgui cimport ImVec4

cdef extern from "../ansifeed-cpp/AnsiTextColored.h" namespace "ImGui":
void TextAnsi(const char* fmt, ...) except + # ✓
Expand Down
4 changes: 2 additions & 2 deletions imgui/cimgui.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Notes:
"""
from libcpp cimport bool

from enums cimport ImGuiKey_, ImGuiCol_, ImGuiSliderFlags_
from imgui.enums cimport ImGuiKey_, ImGuiCol_, ImGuiSliderFlags_

cdef extern from "imgui.h":
# ====
Expand Down Expand Up @@ -708,7 +708,7 @@ cdef extern from "imgui.h":
float Ascent # ✗
float Descent # ✗
int MetricsTotalSurface # ✗
ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8] # ✗
ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)//4096//8] # ✗

# Methods
const ImFontGlyph*FindGlyph(ImWchar c) except + # ✗
Expand Down
2 changes: 1 addition & 1 deletion imgui/cimplot.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Notes:
"""
from libcpp cimport bool

from cimgui cimport ImVec2, ImVec4, ImTextureID, ImGuiCond, ImGuiMouseButton, ImGuiKeyModFlags, ImGuiDragDropFlags, ImU32, ImDrawList, ImGuiContext
from imgui.cimgui cimport ImVec2, ImVec4, ImTextureID, ImGuiCond, ImGuiMouseButton, ImGuiKeyModFlags, ImGuiDragDropFlags, ImU32, ImDrawList, ImGuiContext

# Must be outside cdef extern from "implot.h" since it is not defined there
ctypedef ImPlotPoint (*ImPlotGetterCallback)(void* data, int idx)
Expand Down
2 changes: 1 addition & 1 deletion imgui/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This file provides all C/C++ definitions that need to be shared between all
extension modules. This is mostly for the `extra` submodule that provides
some additional utilities that do not belong to `core`.
"""
cimport cimgui
from imgui cimport cimgui

cdef class _Font(object):
cdef cimgui.ImFont* _ptr
Expand Down
33 changes: 17 additions & 16 deletions imgui/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ from libcpp cimport bool
FLOAT_MIN = FLT_MIN
FLOAT_MAX = FLT_MAX

cimport cimgui
cimport core
cimport enums
cimport ansifeed
cimport internal
from imgui cimport cimgui
from imgui cimport core
from imgui cimport enums
from imgui cimport ansifeed
from imgui cimport internal

from cpython.version cimport PY_MAJOR_VERSION

Expand Down Expand Up @@ -3034,7 +3034,7 @@ cdef class _InputTextSharedBuffer(object):

cdef _InputTextSharedBuffer _input_text_shared_buffer = _InputTextSharedBuffer()

cdef int _ImGuiInputTextCallback(cimgui.ImGuiInputTextCallbackData* data):
cdef int _ImGuiInputTextCallback(cimgui.ImGuiInputTextCallbackData* data) noexcept:
cdef _ImGuiInputTextCallbackData callback_data = _ImGuiInputTextCallbackData.from_ptr(data)
callback_data._require_pointer()

Expand All @@ -3046,7 +3046,7 @@ cdef int _ImGuiInputTextCallback(cimgui.ImGuiInputTextCallbackData* data):
cdef ret = (<_callback_user_info>callback_data._ptr.UserData).callback_fn(callback_data)
return ret if ret is not None else 0

cdef int _ImGuiInputTextOnlyResizeCallback(cimgui.ImGuiInputTextCallbackData* data):
cdef int _ImGuiInputTextOnlyResizeCallback(cimgui.ImGuiInputTextCallbackData* data) noexcept:
# This callback is used internally if user asks for buffer resizing but does not provide any python callback function.

if data.EventFlag == enums.ImGuiInputTextFlags_CallbackResize:
Expand Down Expand Up @@ -3185,22 +3185,21 @@ cdef class _ImGuiInputTextCallbackData(object):
def insert_chars(self, int pos, str text):
self._require_pointer()
self._ptr.InsertChars(pos, _bytes(text))

def select_all(self):
self._require_pointer()
self._ptr.SelectAll()

def clear_selection(self):
self._require_pointer()
self._ptr.ClearSelection()

def has_selection(self):
self._require_pointer()
return self._ptr.HasSelection()



cdef void _ImGuiSizeCallback(cimgui.ImGuiSizeCallbackData* data):

cdef void _ImGuiSizeCallback(cimgui.ImGuiSizeCallbackData* data) noexcept:
cdef _ImGuiSizeCallbackData callback_data = _ImGuiSizeCallbackData.from_ptr(data)
callback_data._require_pointer()
(<_callback_user_info>callback_data._ptr.UserData).callback_fn(callback_data)
Expand Down Expand Up @@ -9239,7 +9238,7 @@ def plot_lines(
float scale_min = FLOAT_MAX,
float scale_max = FLOAT_MAX,
graph_size = (0, 0),
int stride = sizeof(float),
int stride = -1,
):

"""
Expand Down Expand Up @@ -9302,7 +9301,8 @@ def plot_lines(
"""
if values_count == -1:
values_count = <int>values.shape[0]

if stride == -1:
stride = sizeof(float)
# Would be nicer as something like
# _bytes(overlay_text) if overlay_text is not None else NULL
# but then Cython complains about either types or pointers to temporary references.
Expand Down Expand Up @@ -9331,7 +9331,7 @@ def plot_histogram(
float scale_min = FLT_MAX,
float scale_max = FLT_MAX,
graph_size = (0, 0),
int stride = sizeof(float),
int stride = -1,
):
"""
Plot a histogram of float values.
Expand Down Expand Up @@ -9394,7 +9394,8 @@ def plot_histogram(
"""
if values_count == -1:
values_count = <int>values.shape[0]

if stride == -1:
stride = sizeof(float)
# Would be nicer as something like
# _bytes(overlay_text) if overlay_text is not None else NULL
# but then Cython complains about either types or pointers to temporary references.
Expand Down
2 changes: 1 addition & 1 deletion imgui/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
but are useful in Python application.

"""
from . import core
from imgui import core

__all__ = (
"text_ansi",
Expand Down
6 changes: 3 additions & 3 deletions imgui/internal.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Notes:
"""
from libcpp cimport bool

from enums cimport ImGuiKey_, ImGuiCol_, ImGuiSliderFlags_
from imgui.enums cimport ImGuiKey_, ImGuiCol_, ImGuiSliderFlags_

cimport cimgui
cimport enums_internal
from imgui cimport cimgui
from imgui cimport enums_internal

cdef UpdateImGuiContext(cimgui.ImGuiContext* _ptr)

Expand Down
6 changes: 3 additions & 3 deletions imgui/internal.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import cython

cimport cimgui
cimport internal
cimport enums_internal
from imgui cimport cimgui
from imgui cimport internal
from imgui cimport enums_internal

from cpython.version cimport PY_MAJOR_VERSION

Expand Down
8 changes: 4 additions & 4 deletions imgui/plot.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import warnings
from libcpp cimport bool
from libc.stdlib cimport malloc, free

cimport cimplot
cimport cimgui
cimport core
cimport enums
from imgui cimport cimplot
from imgui cimport cimgui
from imgui cimport core
from imgui cimport enums

from cpython.version cimport PY_MAJOR_VERSION

Expand Down
27 changes: 26 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,36 @@ environment = { LC_ALL="en_US.UTF-8", LANG="en_US.UTF-8" }

[build-system]
requires = [
"Cython>=0.24,<0.30",
"Cython",
"PyOpenGL",
"glfw",
"wheel",
"click",
"setuptools",
]
build-backend = "setuptools.build_meta"
[tool.cython]
language_level = "3"

[project]
name='pyplotgui' # name on PyPi; still imported as 'imgui'
version='2.0.0' # separate versioning from pyimgui

authors = [
{name = 'Erik Härkönen', email = '[email protected]'}
]

description="Cython-based Python bindings for dear imgui and implot"
readme = "README.md"

classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Cython",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Topic :: Games/Entertainment",
]
[project.urls]
Repository = "https://github.com/harskish/pyplotgui"
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[tool:pytest]
filterwarnings = ignore::DeprecationWarning:docutils
addopts = --ignore=tests/test_crazy_callbacks.py
[options]
packages = find:
[flake8]
extend-ignore = E501
exclude = .git,__pycache__,build,dist
58 changes: 6 additions & 52 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import os
import sys
from itertools import chain

from setuptools import setup, Extension, find_packages
from setuptools import setup, Extension

try:
from Cython.Build import cythonize
Expand All @@ -16,7 +14,8 @@
USE_CYTHON = True


_CYTHONIZE_WITH_COVERAGE = False #os.environ.get("_CYTHONIZE_WITH_COVERAGE", False)
_CYTHONIZE_WITH_COVERAGE = False
# os.environ.get("_CYTHONIZE_WITH_COVERAGE", False)

if _CYTHONIZE_WITH_COVERAGE and not USE_CYTHON:
raise RuntimeError(
Expand All @@ -30,19 +29,6 @@ def read(filename):
return file_handle.read()


def get_version(version_tuple):
if not isinstance(version_tuple[-1], int):
return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
return '.'.join(map(str, version_tuple))


init = os.path.join(os.path.dirname(__file__), 'imgui', '__init__.py')
version_line = list(filter(lambda l: l.startswith('VERSION'), open(init)))[0]

#VERSION = get_version(eval(version_line.split('=')[-1]))
README = os.path.join(os.path.dirname(__file__), 'README.md')


if sys.platform in ('cygwin', 'win32'): # windows
# note: `/FI` means forced include in VC++/VC
# note: may be obsoleted in future if ImGui gets patched
Expand Down Expand Up @@ -73,7 +59,6 @@ def get_version(version_tuple):

def extension_sources(path):
sources = ["{0}{1}".format(path, '.pyx' if USE_CYTHON else '.cpp')]

if not USE_CYTHON:
# note: Cython will pick these files automatically but when building
# a plain C++ sdist without Cython we need to explicitly mark
Expand All @@ -97,13 +82,13 @@ def extension_sources(path):

def backend_extras(*requirements):
"""Construct list of requirements for backend integration.

All built-in backends depend on PyOpenGL so add it as default requirement.
"""
return ["PyOpenGL"] + list(requirements)


EXTRAS_REQUIRE = {
'Cython': ['Cython>=0.24,<0.30'],
'Cython': ['Cython>=3.16,'],
'cocos2d': backend_extras(
"cocos2d",
"pyglet>=1.5.6; sys_platform == 'darwin'",
Expand Down Expand Up @@ -131,6 +116,7 @@ def backend_extras(*requirements):
('PYIMGUI_CUSTOM_EXCEPTION', None)
] + os_specific_macros + general_macros,
include_dirs=['imgui', 'config-cpp', 'imgui-cpp', 'ansifeed-cpp'],
language="c++"
),
Extension(
"imgui.internal", extension_sources("imgui/internal"),
Expand All @@ -154,41 +140,9 @@ def backend_extras(*requirements):


setup(
name='pyplotgui', # name on PyPi; still imported as 'imgui'
version='1.0.0', # separate versioning from pyimgui
packages=find_packages('.'),

author=u'Erik Härkönen',
author_email='[email protected]',

description="Cython-based Python bindings for dear imgui and implot",
long_description=read(README),
long_description_content_type="text/markdown",

url="https://github.com/harskish/pyplotgui",

ext_modules=cythonize(
EXTENSIONS,
compiler_directives=compiler_directives, **cythonize_opts
),
extras_require=EXTRAS_REQUIRE,
include_package_data=True,

license='BSD',
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',

'Programming Language :: Cython',
'Programming Language :: Python :: 3',

'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Cython',

'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',

'Topic :: Games/Entertainment',
],
)