Skip to content
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

Decorator for Node GUIs and GUI deferred loading #174

Merged
merged 8 commits into from
Nov 25, 2023

Conversation

HeftyCoder
Copy link
Contributor

@HeftyCoder HeftyCoder commented Nov 24, 2023

This PR introduces a new way to assign Node GUIs to Nodes. Specifically:

  • It introduces a decorator called node_gui which accepts a Node as a parameter. Assigning a gui to a node happens in the gui.py file and not the nodes.py, allowing for IDE hinting and deprecating the need for the import_guis and export_guis functions.
  • Introduces a on_gui_load function which can be applied to any function in the imported nodes.py file. This function will then be called after package loading in import_nodes_package.
  • Adds a api.py file in the ryven folder. Might not be needed, but thought it was a good idea. Bad idea, read the conversation for details.

The built_in package and the pkg_test package (which has linalg and std subpackages) have been changed to use this new utility. The older linalg and std packages haven't been altered and are working with the "deprecated" functions.

CC: these ideas were first discussed in #171 as a result of investigating sub-packages

HeftyCoder and others added 6 commits November 25, 2023 00:59
commit 783f371
Merge: c8e1147 3043123
Author: George Papadoulis <[email protected]>
Date:   Fri Nov 24 23:11:25 2023 +0200

    Merge remote-tracking branch 'upstream/master' into gui_dev

commit 3043123
Merge: 998e552 af91367
Author: Leon Thomm <[email protected]>
Date:   Fri Nov 24 22:02:44 2023 +0100

    Merge pull request leon-thomm#171 from HeftyCoder/master

    This PR

    - adds sub-package functionality (`export_sub_nodes()`) (WIP)
    - adds a tree view for (sub-)packages
    - introduces dockable widgets
    - adds project-persistent window geometry
    - makes connections selectable

commit c8e1147
Author: George Papadoulis <[email protected]>
Date:   Fri Nov 24 19:06:28 2023 +0200

    Update utils.py

commit 39fa412
Author: George Papadoulis <[email protected]>
Date:   Fri Nov 24 18:58:39 2023 +0200

    Defer GUI loading

    -Implemented a on_gui_load decorator which defers Node GUI loading
    -Added a protection mechanism for when defining a GUI for the same node twice

commit 00427cf
Merge: caf6f88 1e9ddd0
Author: George Papadoulis <[email protected]>
Date:   Fri Nov 24 14:41:44 2023 +0200

    Merge branch 'master' into gui_dev

commit caf6f88
Author: George Papadoulis <[email protected]>
Date:   Mon Nov 20 15:45:17 2023 +0200

    Implemented decorator GUI import

    -Defined a node_gui decorator in gui_env that allows for connecting the node to the gui
    -Defined a function in gui_env that returns if Ryven is in gui mode
    -Re-factored the packages to work with the new decorator system
    -Added a decorator to defer gui functions for package importing
    -Added a api.py for convenience. Might not be needed later
-Added in_gui_mode in api.py
-Fixed a type hint for 3.9+ in main_window.py
-Fixed styling
@leon-thomm
Copy link
Owner

Please correct me if I'm missing something but I think your api.py compromises the whole point of separating nodes dependencies and UI dependencies in the first place, which is that Ryven has a headless mode in which it runs without any Qt dependencies (only ryvencore).

@leon-thomm
Copy link
Owner

Clarifying the previous comment: Ryven can run in environments where Qt is not even installed (because it can't without desktop environment). That's why ryven.main is separate from ryven.gui. 1 ryven.main.Ryven.run() runs with the editor, ryven.main.RyvenConsole.run() runs without.

Footnotes

  1. config.py imports something from gui but it doesn't cause Qt import

- fixes Qt imports
- fixes circular imports
- improve structure
- improves help docstrings

tested headless on basic example
@leon-thomm
Copy link
Owner

I took the liberty to fix the imports and remove api. If I messed up your local branch I can rollback re-commit later. Looks good to me now, anything else from your side?

-Fixed wrong type hinting in consume_last_exported_package. Also cleaned the code and probably made the function a bit more performant.
@HeftyCoder
Copy link
Contributor Author

I think your api.py compromises the whole point of separating nodes dependencies and UI dependencies in the first place

I was (and probably still am) confused about how python importing works. I thought that by calling from ryven.api import in_gui_mode only that function would be imported, ignoring the rest. Didn't account that in_gui_mode was also imported in gui_env. I thought one could bundle everything that way. My bad.

I made minor changes to the consume_last_exported_package function. Other than that, I'm good!

@leon-thomm leon-thomm merged commit 2b3beb4 into leon-thomm:master Nov 25, 2023
@leon-thomm
Copy link
Owner

Importing a module just means running it. A module-level expression such as def foo makes the foo symbol available. A module-level expression such as import ryven.gui_env runs ryven.gui_env at the point where the import is stated. A from import is actually no different, from ryven.api import in_gui_mode will first run ryven.api and then make in_gui_mode available locally. That's why it matters how imports are placed.

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.

2 participants