From 6baf2ca1b8e56d30519d0dc738c9859fe52529b7 Mon Sep 17 00:00:00 2001 From: Jason Brewer Date: Mon, 1 Jul 2019 18:34:07 +0100 Subject: [PATCH] #25 added some notes for the pywebview->JavaScript comm links --- gui/lrpi/lrpi.py | 10 +++++----- gui/lrpi/www/js/controllers.js | 10 +++++++++- gui/lrpi/www/templates/play.html | 2 +- requirements.txt | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gui/lrpi/lrpi.py b/gui/lrpi/lrpi.py index 373744e..a349a77 100755 --- a/gui/lrpi/lrpi.py +++ b/gui/lrpi/lrpi.py @@ -2,6 +2,10 @@ import webview, threading +# Sending events from JS -> Python and back: +# https://askubuntu.com/questions/97430/connect-webkit-webview-form-to-a-python-callback +# See also: https://github.com/r0x0r/pywebview/blob/master/examples/todos/assets/script.js + class Api(): def event(self, param): print('select audio file!') @@ -10,14 +14,10 @@ def event(self, param): # t = threading.Thread(target=load_html) # t.start() - print('Begin...') + print('App start...') api = Api() webview.config.gui = "qt" webview.create_window('Lushroom Pi', 'www/index.html', js_api=api, width=400, height =600, min_size=(400, 600), confirm_quit=True, text_select=True, resizable=False, debug=True) - - # Sending events from JS -> Python and back: - # https://askubuntu.com/questions/97430/connect-webkit-webview-form-to-a-python-callback - # See also: https://github.com/r0x0r/pywebview/blob/master/examples/todos/assets/script.js diff --git a/gui/lrpi/www/js/controllers.js b/gui/lrpi/www/js/controllers.js index 8081d1c..8c75c41 100644 --- a/gui/lrpi/www/js/controllers.js +++ b/gui/lrpi/www/js/controllers.js @@ -18,12 +18,20 @@ function ($scope, $stateParams) { var vm = this; vm.selectAudioFile = selectAudioFile; + // For selecting files (from http://www.myegotraps.com/pywebview-2-0-released/): + // Other new features include: + + // When creating a window, you can now specify a relative path to a html file + // (that is without a file:// or any other protocol). This way relatively linked resources will be resolved correctly. This will work when application is frozen too. + // target='_blank' links are opened in an external browser + // Text selection on non input elements is disabled by default + // new load_css function for ahem loading custom css + function selectAudioFile() { console.log('click!'); window.pywebview.api.event() } - }]) .controller('testCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller diff --git a/gui/lrpi/www/templates/play.html b/gui/lrpi/www/templates/play.html index 9edaf69..fbf41ff 100644 --- a/gui/lrpi/www/templates/play.html +++ b/gui/lrpi/www/templates/play.html @@ -8,7 +8,7 @@
- Select Audio File +