Skip to content

Adding begin/end with support - #264

Merged
KinoxKlark merged 2 commits into
pyimgui:dev/version-2.0from
mCodingLLC:withsupport
Mar 4, 2022
Merged

KinoxKlark merged 2 commits into
pyimgui:dev/version-2.0from
mCodingLLC:withsupport

Conversation

@mCodingLLC

@mCodingLLC mCodingLLC commented Feb 27, 2022 •

Copy link
Copy Markdown

See: #255

I've added context manager support for all 18 begin/end pairs. I don't see this as a replacement for the old style, but as a complementary style. Old code should continue to work as is. New code that wants/needs to handle exceptions can use the context managers to ensure the imgui stack is not corrupted.

The changes are backwards compatible in the following sense:

  1. Changes were implemented using raw Cython cdef classes, so they should be compatible with all supported Python versions (even 2.7, which I personally would drop support for wink).
  2. Return values that were tuples have getitem and iter methods that return tuple getitem and tuple iter.
  3. Return values that were bools have bool that returns the old return value.
  4. Return values that were None were assumed to not be used previously, so nothing was done to make them backwards compatible.

I've added extensive testing for all of the things added/changed. The biggest thing missing would be to update the documentation, but I'd like to get feedback before attempting to do that.

Edit: See https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#fast-instantiation for why I use the cinit + new trick.

See: pyimgui#255

The 18 begin_* functions now return Cython classes that have __enter__ and __exit__ methods to guarantee the corresponding end_* function is called.

Note: documentation still needs to be added.
@KinoxKlark

Copy link
Copy Markdown
Member

This is awesome, thanks a lot!

For me, it looks very great like that. I am willing to merge it. Let me know when you think it is ready to be merged (w.r.t. the documentation etc). If you want to let the documentation part for later as another PR it is possible, we'll create an issue tagged as 'todo'.

(support for 2.7 will be dropped in pyimgui 2.0)

@KinoxKlark KinoxKlark mentioned this pull request Mar 3, 2022
2 tasks
@mCodingLLC

Copy link
Copy Markdown
Author

I just pushed another commit with eq methods for all the return values that were bool or tuples since some existing code may do things like

if begin(...) == (True, False):
    pass

Other than that I think it's ready to merge and make a todo issue for the docs.

@KinoxKlark
KinoxKlark merged commit ca0c387 into pyimgui:dev/version-2.0 Mar 4, 2022
@KinoxKlark

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants