Skip to content

Commit

Permalink
#25 added some notes for the pywebview->JavaScript comm links
Browse files Browse the repository at this point in the history
  • Loading branch information
InBrewJ committed Jul 1, 2019
1 parent 4c0a827 commit 6baf2ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions gui/lrpi/lrpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
Expand All @@ -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
10 changes: 9 additions & 1 deletion gui/lrpi/www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gui/lrpi/www/templates/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<div ng-controller="playCtrl as vm" id="play-container1">
<form id="play-form4" class="list">
<input type="file" ng-click="vm.selectAudioFile();" id="play-button9" style="border-radius:0px 0px 0px 0px;" class="button button-dark button-block icon-left ion-music-note">Select Audio File</input>
<button type="file" ng-click="vm.selectAudioFile();" id="play-button9" style="border-radius:0px 0px 0px 0px;" class="button button-dark button-block icon-left ion-music-note">Select Audio File</button>
<label class="item item-input" id="play-input7" name="play_audio_filename">
<span class="input-label">File name</span>
<input type="text" placeholder="Choose an audio file ">
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ python-osc
pyfiglet
PyQt5
PyQtWebEngine
pywebview
pywebview>=2.0
sip
py2app

0 comments on commit 6baf2ca

Please sign in to comment.