Last active
March 14, 2020 11:55
-
-
Save impshum/4c5afb12c4d8fdac57d9dcb51b162ee8 to your computer and use it in GitHub Desktop.
Change colour of screen thingy with pywebview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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