Skip to content

Move configure_pygui into a Scene method and remove manim.gui #4314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chopan050
Copy link
Contributor

@chopan050 chopan050 commented Jun 27, 2025

Overview: What does this pull request change?

I took the manim.gui.gui.configure_pygui function, which is used in Scene.interactive_embed(), and transformed it into a Scene method. Since that function was the only thing in manim.gui, I deleted this module as well.

Motivation and Explanation: Why and how do your changes improve the library?

  • configure_pygui was only used by Scene.interactive_embed().
  • Its parameters were:
    • A renderer, although configure_pygui only accesses the scene referenced by the renderer, so why not just pass the scene itself instead...?
    • A sequence of widget configurations. Scene.interactive_embed() is the only code which calls configure_pygui and it passes the Scene.widgets to it, so, again, the reference to the scene is enough.
    • A bool.
  • Internally, configure_pygui also accesses the Scene.queue of actions to do during Scene.interact(). This Scene is the referenced by the passed renderer... so, again, just pass the scene instead.
  • It depends on whether dearpygui is imported, in which case dearpygui_import = True. Otherwise, dearpygui_import = False. This exact same thing also already happens in manim.scene.scene.

Because of the reasons above, I believe that this belongs better as a method of Scene. No need to pass a renderer (or scene), nor a list of widgets, because self is a Scene which already has the widgets attribute, as well as the queue.

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent change, thank you very much!

Left one question/suggestion that would cause a bit more work; we can just merge the current version as is if you don't think that this would be a good idea.

@@ -25,6 +26,8 @@
import dearpygui.dearpygui as dpg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving the dearpygui import down and into the scene __init__ to get rid of the weird dearpygui_imported variable?

Copy link
Contributor Author

@chopan050 chopan050 Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although that variable is weird, I believe that this import is better placed where it is right now. The dpg module is used in .interactive_embed(), .interact() and the new ._configure_pygui(). If we imported it inside __init__, it would probably have to be stored as a Scene attribute.

Copy link
Contributor Author

@chopan050 chopan050 Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I remembered a related discussion on Discord where I mentioned that it would probably be good to have a reference to dpg from Scene:

It would be nice to have an enum of all possible widgets

After giving it some thoughts, I believe that it's not intuitive to append a dictionary to Scene.widgets if you wanna add a widget and it's a bit prone to errors

There could be a dedicated method Scene.add_gui_widget(), but you still get no type hints for the kwargs
One could make one Scene method for each of the functions of Dear PyGui which adds a widget... but, in that case, it's much more straightforward to simply get a reference to Dear PyGui and directly use its functions instead

In my opinion, this requires a larger refactor which should be done in a subsequent PR...

@github-project-automation github-project-automation bot moved this from 🆕 New to 👍 To be merged in Dev Board Jul 10, 2025
@behackl behackl added the refactor Refactor or redesign of existing code label Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor or redesign of existing code
Projects
Status: 👍 To be merged
Development

Successfully merging this pull request may close these issues.

2 participants