QPython3 webViewShow - Script doesn't receivin

2019-07-18 18:39发布

问题:

  • I am trying to do simple program in QPython3 using the webViewShow method.
  • I have a problem with receiving data from HTML file to QPython3 script.
  • as you can see I am using droid.eventPost() method in HTML file but when i am trying to print the result to the console, nothing shows.

The code of QPython3 script:

#-*-coding:utf8;-*- 
#qpy:3 
#qpy:console 

from android import Android 

droid = Android() 
droid.webViewShow('/storage/sdcard0/com.hipipal.qpyplus/scripts3/Bluetooth/btLED.html') 

while True: 
    result = droid.eventWait().result 
    print(result['data'])
    droid.eventClearBuffer() 

The code of HTML file:

<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8' />
    <meta name="author" content="Jiri" /> 
    <title>blLED.py</title>         

<style>

body{
    background: white;
    margin: 0;
    padding-top: 3%;
    overflow: hidden;
    width: 100%;
    height: 95%; 
    text-align: center;  
}

button{
    margin-top: 1%;
    width: 22%;
    padding-top: 2%;
    padding-bottom: 2%;
    }           

hr{
    width: 75%;
    border-top: 2% solid black;
}

</style>
</head>


<body>

<script>  
    var droid = new Android();
</script>

    <div>LED | OFF</div>

    <hr>

    <button onclick="droid.eventPost('name', '1');">LED ON</button>
    <button onclick="droid.eventPost('name', '0');">LED OFF</button>

    <br>
    <hr>  

    <button onclick="droid.eventPost('name', 'Close');">Close</button>

    <br>  
    <hr>                   

</body>
</html>

What I tried:

I tried to send a data to QPython script from QPython script so the code looked like this:

while True:
    droid.eventPost('name', '1')
    result = droid.eventWait().result
    print(result['data'])
    droid.eventClearBuffer()
  • But still the console didnt print anything.
  • I really played with the code and I thing that is simple and it shouldnt be wrong, so I dont know where is the problem (maybe some missing libraries? or something like that .... I am beginner in QPython and the programs for Android)

So the question is: Do you have any idea, why the qpython doesn´t receiving data from HTML file? Please help....

Thank You (and sorry for my English)

Jirka