honix / Pyno

Python-based visual programming
MIT License
168 stars 23 forks source link

Separate patch and node's code in to files #18

Closed honix closed 5 years ago

honix commented 6 years ago

Read conversation here #17

honix commented 6 years ago

Oh, shit. This never been that easy.

image

honix commented 6 years ago

According to 1f3ca76:

image

So we get separation. Now let's create a library of nodes! :)

bilderbuchi commented 6 years ago

A question: can you clear up why you use exec() here (and elsewhere in the code) instead of importing the module? Seems to me not very pythonic, and possibly quite the security risk, and I don't see why it is done that way.

honix commented 6 years ago

Pretty pythonic i think, it uses dynamic nature of the lang. Module import may be unsecure too, as i belive it is just a form of exec. Which is parse code and evaluate it in current environment.

How do you see importing using modules? Maybe it can be better for nodes library than exec?

bilderbuchi commented 6 years ago

OK, maybe I have misunderstood what exec should do, sorry. An advantage, in any case, is that you can tweak the scope with the optional arguments of exec().

drtrigon commented 6 years ago

This closes #9 also.

drtrigon commented 6 years ago

@honix: What is the exact idea now? Should nodes only be used as shown be the nodes/identity.py example here? Or is this just one additional way of using it? I wonder as module imports from external python script have to be possible. The also have to work using import. What about putting the call = identity into the pyno node? That would allow to use one .py file for all nodes and come close to #14? (is this a scope issue?) Is the idea to always use the same code for those externals in the pyno node? (sorry for may be aking naiive questions - I try to clarify the concept)

honix commented 6 years ago

@drtrigon there is little trouble with import when i use G and S variables in some nodes, and they are not defined, so import throws exception.

But importing from external modules is possible right now! You just need to call-bind function from module. And you can hold this functions in one file. As @bilderbuchi mentioned:

image

Really i dont have any exact opinion. It is good that here many ways to do. But we need to choose one 'official' way of importing. I like import example, need to solve scope issue. :)

honix commented 6 years ago

I will reopen this issue to find best way of making node-files. I found this scheme can handle local and (if needed) global scopes. One thing i don't like is pyno code on the right: too many lines. We can introduce new binding node = w.Window as reference of class, or something smarter. :)

image

honix commented 6 years ago

If we do, this can end up with something like this in pyno. But i find this little long and complicated for users. So i prefer to take call cleanup fast binding alongside with node pro-user binding. Guys?

image

bilderbuchi commented 6 years ago

I'll have to think on this. But yes, simple/short is good, which is why I elsewhere suggested looking into decorators, this way you can hide complexity from users.

honix commented 6 years ago

Another crazy idea is to link node symbol to node itself, so user can node.call = kill_all_aliens(42) or even node.color = (0, 0, 255). Hackableeee!

By this we reduce 'service' symbols to just node.

drtrigon commented 6 years ago

The class approach reminds me to https://www.vistrails.org/usersguide/dev/html/packages.html

You want to be able to have multiple functions in one node and all the code in a python file. I can think of 2 ways:

Generally I think the call binding should may be not be part of the .py file but off the pyno patch onl

The node symbol could most probably be similar to the self we need for loop support.

bilderbuchi commented 6 years ago

OK, I have to admit I don't understand why there is GUI/windows code up there in the user-defined node code. I think you strictly have to separate three things, and then the structure will hopefully be clearer to implement (note I have not read the current code for these things):

bilderbuchi commented 6 years ago

I just fonud out that PyQtGraph also has something similiar called "flowchart": http://www.pyqtgraph.org/documentation/flowchart/index.html

drtrigon commented 6 years ago