Skip to content

Python function not triggered using JS #458

Description

@aayusharora

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions