Eel icon indicating copy to clipboard operation
Eel copied to clipboard

JS: form eel.expose(fct,name) throw a python exception

Open manatlan opened this issue 7 years ago • 6 comments

Just diving into eel ;-) BUt there is something wrong (i'm trying to call a js method, from python, in a vuejs app ... and I want to callback a component method ... so I'm trying differents approach : and found a bug)

in a vue component, in the created() event : (this works as expected )

  var self=this;
  function say_hello_js(x) {
    self.test2(x);
  }
  eel.expose(say_hello_js);  

it calls the component method (test2)

but this won't work :

  var self=this;
  function say_hello_js(x) {
    self.test2(x);
  }
  eel.expose(say_hello_js, 'say_hello_js'); 

and python side, when starting, throw :

Traceback (most recent call last):
  File "t.py", line 13, in <module>
    eel.init('web')
  File "/home/manatlan/.local/lib/python3.6/site-packages/eel/__init__.py", line 86, in init
    _mock_js_function(js_function)
  File "/home/manatlan/.local/lib/python3.6/site-packages/eel/__init__.py", line 213, in _mock_js_function
    exec('%s = lambda *args: _mock_call("%s", args)' % (f, f), globals())
  File "<string>", line 1
SyntaxError: can't assign to literal

I wanna to try to call back a component's method, from py sides ... and wanted to rename it using the eel.expose with 2 parameters ... but no luck (perhaps there is a better way ?)

If I found a patch, will push you a PR .... but I'm just evaluating eel (btw : it's really great !)

manatlan avatar Jul 19 '18 16:07 manatlan

I've uploaded my tests here : https://manatlan.alwaysdata.net/test_eel.zip It's a vuejs/eel thing ... but the problem should be the same for a pure js app ;-) the regex (in the init method, line 58) should be aware of this kind of form.

manatlan avatar Jul 19 '18 16:07 manatlan

If we could do something like

  eel.expose( this.say_hello_js );  

without naming explicitly ; it could be marvelous

manatlan avatar Jul 19 '18 16:07 manatlan

@manatlan thanks for your interest!

I think this naming of methods was only half implemented on the js side, thanks for pointing it out - it needs to be fixed.

In your final example, what do you think the method should be called on the Python side? Just take the final part after the last . maybe...?

ChrisKnott avatar Jul 19 '18 20:07 ChrisKnott

Yes I think it should as simple as possible. So, taking the method name should be the simplest ... Just removing the "this." Is the way to go.

But, you have never needed to call back a component method from py side ?

manatlan avatar Jul 19 '18 21:07 manatlan

BTW, I've started to make a "eel-like" for python3, with asyncio/aiohttp ... sadly named "wuy" https://github.com/manatlan/wuy

manatlan avatar Jul 21 '18 14:07 manatlan

Just diving into eel ;-) BUt there is something wrong (i'm trying to call a js method, from python, in a vuejs app ... and I want to callback a component method ... so I'm trying differents approach : and found a bug)

in a vue component, in the created() event : (this works as expected )

  var self=this;
  function say_hello_js(x) {
    self.test2(x);
  }
  eel.expose(say_hello_js);  

it calls the component method (test2)

but this won't work :

  var self=this;
  function say_hello_js(x) {
    self.test2(x);
  }
  eel.expose(say_hello_js, 'say_hello_js'); 

and python side, when starting, throw :

Traceback (most recent call last):
  File "t.py", line 13, in <module>
    eel.init('web')
  File "/home/manatlan/.local/lib/python3.6/site-packages/eel/__init__.py", line 86, in init
    _mock_js_function(js_function)
  File "/home/manatlan/.local/lib/python3.6/site-packages/eel/__init__.py", line 213, in _mock_js_function
    exec('%s = lambda *args: _mock_call("%s", args)' % (f, f), globals())
  File "<string>", line 1
SyntaxError: can't assign to literal

I wanna to try to call back a component's method, from py sides ... and wanted to rename it using the eel.expose with 2 parameters ... but no luck (perhaps there is a better way ?)

If I found a patch, will push you a PR .... but I'm just evaluating eel (btw : it's really great !)

I think you should use eel._expose(func, "myfunc") instead of expose.

nricciardi avatar May 12 '23 06:05 nricciardi