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

Python function not triggered using JS #458

Closed
aayusharora opened this issue Jan 22, 2020 · 7 comments
Closed

Python function not triggered using JS #458

aayusharora opened this issue Jan 22, 2020 · 7 comments

Comments

@aayusharora
Copy link

aayusharora commented Jan 22, 2020

Specification

  • pywebview version: 3.1
  • platform / version: MacOS 10.14.6

Description

Like the serverless architecture, the code snippet is unable to trigger the defined python code function open_file_dialog using JS.
HTML with JS
i.e inside assets folder

<html lang="en" data-framework="javascript">
	<head>
		<meta charset="utf-8">
		<title>Aftershoot</title>
		<link rel="stylesheet" href="styles.css">
	</head>
	<body>
		<section class="logo">
			<img src="logo.jpg" alt="maumaumau">
		</section>
		<section class="todoapp">
			<header class="header">
				<h1>Aftershoot</h1>
				<button class="new-todo" onClick='chooseDir()'>Upload</button>
			</header>
		</section>
		<script>
		function chooseDir() {
			alert('hello')
			pywebview.api.open_file_dialog(window)
		}
		</script>
	</body>
</html>

Python Implementation

import os
import webview


class Api():

    def open_file_dialog(self, window):
        print('Hello')
        result = window.create_file_dialog(webview.FOLDER_DIALOG, directory='')
        return result


if __name__ == '__main__':
    api = Api()
    webview.create_window('Aftershoot', 'assets/index.html', js_api=api, min_size=(600, 450))
    webview.start()


Practicalities

  • YES I am willing to work on this issue myself.

  • NO I am prepared to support this issue financially.

Reference Docs: https://pywebview.flowrl.com/examples/js_api.html

@aayusharora aayusharora changed the title Python function is not triggered using JS Python function not triggered using JS Jan 22, 2020
@r0x0r
Copy link
Owner

r0x0r commented Jan 22, 2020 via email

@aayusharora
Copy link
Author

aayusharora commented Jan 23, 2020

Hi @r0x0r
The input box does not work.
Only the JS code works, but the JS is unable to execute any python function in examples/js_api.py

@aayusharora
Copy link
Author

On Inspecting further, this is the error on console
Screenshot 2020-01-23 at 3 13 23 PM

@r0x0r
Copy link
Owner

r0x0r commented Jan 23, 2020 via email

@aayusharora
Copy link
Author

Can you please elaborate a bit?
The version of pywebview that we are using is 3.1
The code snippet which I tested is the latest one from master:
https://github.com/r0x0r/pywebview/blob/master/examples/js_api.py

@r0x0r
Copy link
Owner

r0x0r commented Jan 23, 2020 via email

@aayusharora
Copy link
Author

Thanks for the quick reply.
Everything works now :)

Closing the issue.

@r0x0r r0x0r mentioned this issue Jun 27, 2020
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