leon-thomm / Ryven

Flow-based visual scripting for Python
https://ryven.org
MIT License
3.8k stars 443 forks source link

Decorator for Node GUIs and GUI deferred loading #174

Closed HeftyCoder closed 11 months ago

HeftyCoder commented 11 months ago

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

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

leon-thomm commented 11 months ago

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 commented 11 months ago

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.

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

leon-thomm commented 11 months ago

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?

HeftyCoder commented 11 months ago

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 commented 11 months ago

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.