Sciter › Forums › Sciter and C# | Rust | Go | Python › Sciter/Python › Error in python call function
- This topic has 9 replies, 3 voices, and was last updated 7 years, 5 months ago by
pravic.
-
AuthorPosts
-
-
July 26, 2018 at 3:40 pm #57423
moncef_el
Participantthis is the error that i get when i try to call a python function with two arguments from tiscript:
Traceback (most recent call last): File "C:\Users\Moncef\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sciter\event.py", line 171, in _on_script_call args = sciter.Value.unpack_from(f.argv, f.argc) File "C:\Users\Moncef\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sciter\value.py", line 645, in unpack_from return [value(args[i]).get_value() for i in range(count)] File "C:\Users\Moncef\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sciter\value.py", line 645, in <listcomp> return [value(args[i]).get_value() for i in range(count)] File "C:\Users\Moncef\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sciter\value.py", line 539, in get_value raise TypeError("%s (%s) is unsupported python type" % (str(t), str(u))) TypeError: VALUE_TYPE.T_OBJECT (UT_OBJECT_NATIVE) is unsupported python type error:tis: Error: VALUE_TYPE.T_OBJECT (UT_OBJECT_NATIVE) is unsupported python type at @47@35 (file://C:/Users/Moncef/Desktop/pysciter-master/examples/my/main.htm(50))the code executed is:
import sciter class Frame(sciter.Window): def __init__(self): super().__init__(ismain=True, uni_theme=True) pass @sciter.script def call(self): return "Pythonic window" @sciter.script def Say(self,tex1,text2): if (code == (sciter.event.BEHAVIOR_EVENTS.BUTTON_CLICK | sciter.event.PHASE_MASK.SINKING)) and he.test('#sub'): return "Hello {} {}".format(text1,text2) if __name__ == '__main__': import os htm = os.path.join(os.path.dirname(__file__), 'main.htm') frame = Frame() frame.load_file(htm) frame.run_app()with main.htm:
<script type="text/tiscript"> view.caption = $(head > title).value; $(button#sub).on("click", function() { var p1 = self.select("#input-1"); var p2 = self.select("#input-2"); var ans = view.Say(p1,p2); $(body).$append(<h1>script -> python: {ans}</h1>); }) </script> </head> <body> <form #num1> <label>First name:</label> <input#input-1 novalue="Enter the first name"> <label>Last name:</label> <input#input-2 novalue="Enter the last name"> <footer> <button|submit #sub>Submit</button> <button|reset>Reset</button> </footer> </form> -
July 26, 2018 at 9:08 pm #57424
Andrew
KeymasterThese two variables:
var p1 = self.select("#input-1"); var p2 = self.select("#input-2");will contain references to DOM elements. But your code expects values. So
1. Change your python code to this:
def Say(self,tex1,text2): return "Hello {} {}".format(text1,text2)And 2. Sciter script to this:
$(button#sub).on("click", function() { var p1 = self.select("#input-1").value; // note 'value' but not DOM element reference var p2 = self.select("#input-2").value; var ans = view.Say(p1,p2); $(body).$append(<h1>script -> python: {ans}</h1>); }) -
July 26, 2018 at 9:13 pm #57425
pravic
Moderatorvar p1 = self.select(“#input-1”);
It can be written as
var p1 = $(#input-1)if you wish.view.Say(p1,p2)
p1, p2 are elements, not values. Use
view.Say(p1.value, p2.value)instead.if (code == (sciter.event.BEHAVIOR_EVENTS.BUTTON_CLICK
Where does the
codecome from? And alsotex1vstext1typo. -
July 27, 2018 at 12:40 am #57429
moncef_el
ParticipantThank you for your response; the program works fine but when it comes to:
$(body).$append(<h1#test>script -> python: {ans}</h1>);
it doesn’t show the result returned from python, in my opinion I think that I should add anview.captionsomewhere in my tiscript to show the returned message from Python.
I can see clearly that python received the variables and did the work fine when i turnreturntoprintand that’s because of your help, Thanks! but I still want to show the returned value into the window. -
July 27, 2018 at 1:39 am #57431
pravic
ModeratorTry to add some logging in order not to be blind (check https://sciter.com/revising-assert-and-debug-statements/).
Use
stdout.printlnorstdout.printf("ans is %v\n", ans)(\nis important!) ordebug: ans. -
July 27, 2018 at 1:43 am #57432
pravic
ModeratorAnd I hope you use the correct Python code:
import sciter class Frame(sciter.Window): def __init__(self): super().__init__(ismain=True, uni_theme=True) pass @sciter.script def call(self): return "Pythonic window" @sciter.script def Say(self, text1, text2): print("Say(%s, %s)" % (text1, text2)) return "Hello {} {}".format(text1, text2) if __name__ == '__main__': import os htm = os.path.join(os.path.dirname(__file__), 'main.htm') frame = Frame() frame.load_file(htm) frame.run_app()view.caption = $(head > title).value; $(button#sub).on("click", function() { var p1 = $(#input-1).value; var p2 = $(#input-2).value; stdout.printf("calling view.Say(%v, %v)\n", p1, p2); var ans = view.Say(p1, p2); stdout.printf("the answer is: %v\n", ans); $(body).$append(<h1>script -> python: {ans}</h1>); })-
This reply was modified 7 years, 5 months ago by
pravic. Reason: Corrected selectors
-
This reply was modified 7 years, 5 months ago by
-
July 27, 2018 at 6:17 am #57433
moncef_el
ParticipantThank you #57432, this was helpful to understand things for me, but what i’m really looking for is to display the result into the frame (I mean the window) because the
$(body).$append(<h1>script -> python: {ans}</h1>);don’t do anything. Your code was good and fine but only the$(body).$append(<h1>script -> python: {ans}</h1>); -
July 27, 2018 at 6:55 am #57434
Andrew
KeymasterThis:
var p1 = $("#input-1").value; var p2 = $("#input-2").value;shows error in debug console – “bad selector”
Instead, you should use this:
<html> <head> <title>Test</title> <style></style> <script type="text/tiscript"> // emulation of corresponding method defined in Python: function view.Say(text1,text2) { return String.$(Hello {text1} {text2}); } $(button#sub).on("click", function() { var p1 = $(#input-1).value; var p2 = $(#input-2).value; stdout.printf("calling view.Say(%v, %v)\n", p1, p2); var ans = view.Say(p1, p2); stdout.printf("the answer is: %v\n", ans); $(body).$append(<h1>script -> python: {ans}</h1>); }) </script> </head> <body> <input|text #input-1 /> <input|text #input-2 /> <button#sub>Test</button> </body> </html>While testing in Python remove
function view.Say(text1,text2)definition from the above. -
July 27, 2018 at 7:08 am #57435
moncef_el
ParticipantThank you Andrew this code is working good!
-
July 27, 2018 at 8:45 am #57438
pravic
ModeratorMy bad, used the wrong selector in html.
-
-
AuthorPosts
- You must be logged in to reply to this topic.

Build RSS channel
Sciter Twitter channel