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

How to get the inputs values from an open-editor-window method #72

Open
charlesneimog opened this issue Dec 5, 2022 · 4 comments
Open

Comments

@charlesneimog
Copy link

Hi Jean, I am working on the library om-py, for now I am using the OMEditor like in lisp functions to edit Python code.

My aim: I'd like to, instead of open OMEditor from like in lisp function, Open VScode when double click in in py function.

image

To do that, I need the values from inputs connected in the py boxes, for example, the value of (1 2 3).

Finally my question, how could I get this values from the open-editor-window method, with the run-py-function-editor (equivalent to run-lisp-function-editor).

Did you understand?

Thanks!!

@charlesneimog charlesneimog changed the title How to get the om-box (I want the inputs of the box) from a open-editor-window method How to get the inputs values from an open-editor-window method Dec 5, 2022
@j-bresson
Copy link
Member

j-bresson commented Feb 5, 2023

Hi Charles, sorry for the super-late reply. Did you find a solution ?

If not, and if I understand what you want to do: you should define a class in OM#, in such a way that the data connected to the input(s) would just be stored inside the box. Then you will need to simply redefine the function which opens the editor for this class. I think you could just start with

(defmethod open-editor ((self your-class))
  ;;; => do what you want 
)

@charlesneimog
Copy link
Author

Hi Jean,

I could understand this part, but I do not know how to do this now:
Using the class run-py-f-internal that is the same that OMLispFunctionInternal, how can I get the input values of connected boxes?

Hot to get, for example, the value (1 2 3) of the previous answer?

@j-bresson
Copy link
Member

You can't really get the values from the object itself; you need to get it from the box, by querying the value of the input (with omNG-box-value). That's not convenient, and not easy.

The patch evaluation mechanism evaluates a box and passes the values to another box, but the value (or function) inside a box can not know what's in the other boxes.

If your define your Py object as an OMClass (or just using defclass) you can store the connected values in the class slots, and use them when you open the editor (that's what I suggested before):

(defclass run-py-f-internal ()
  ((code :initform "" :accessor pre-delay) ;; no initarg: will not appear as an input
   (param :initform nil :accessor param :initarg :param)))

(defmethod object-has-editor ((self run-py-f-internal)) t)
(defmethod get-editor-class ((self run-py-f-internal)) 'py-editor)

(defclass py-editor (omeditor) ())

(defmethod open-editor-window ((editor py-editor))
  (print (param (object-value editor)))
  ;;; open your editor here...
  )

Or you can define your own box for this (a subclass of OMBoxAbstraction) and redefine open-editor for that type of box. There you would have an opportunity to evaluate the inputs (but it's more of a hack!).

(defclass OMBoxPy (OMBoxAbstraction) ())

(defmethod get-box-class ((self run-py-f-internal)) 'OMBoxPy)

(defmethod open-editor ((self OMBoxPy))
  (let ((param (omng-box-value (car (inputs box)))))
    (print param)
    ;;; open your editor here...
    ))

@charlesneimog
Copy link
Author

Great, thank you very much for the help!

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

No branches or pull requests

2 participants