Skip to content

Instantly share code, notes, and snippets.

@impshum
Last active March 14, 2020 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save impshum/4c5afb12c4d8fdac57d9dcb51b162ee8 to your computer and use it in GitHub Desktop.
Save impshum/4c5afb12c4d8fdac57d9dcb51b162ee8 to your computer and use it in GitHub Desktop.
Change colour of screen thingy with pywebview
import webview
class Api:
def __init__(self):
self.recording = False
def record(self):
if not self.recording:
self.recording = True
print('start recording')
else:
self.recording = False
print('stop recording')
def evaluate_js(window):
result = window.evaluate_js("""
function colourChanger() {
var screen = document.body;
if (screen.className !== 'black') {
screen.style.backgroundColor= '#000';
screen.className = 'black'
}
else {
screen.style.backgroundColor = "#fff";
screen.className = '';
}
}
function startStop() {
pywebview.api.record();
}
document.body.onkeyup = function(e){
if (e.keyCode == 32) { // HIT SPACEBAR
colourChanger();
} else if (e.keyCode == 83) { // HIT S KEY
startStop();
}
}
""")
if __name__ == '__main__':
api = Api()
window = webview.create_window('Colour Thingy', js_api=api, fullscreen=False)
webview.start(evaluate_js, window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment