From 28383d89ec346c77dab6b98df3beb2d28006825f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 13 Jan 2021 11:12:20 -0500 Subject: [PATCH] Make Universal Brython Functions --- fHDHR_web/brython/__init__.py | 4 ++ fHDHR_web/brython/brython.py | 1 + fHDHR_web/brython/brython_bry.py | 19 +++++++ fHDHR_web/brython/brython_code.py | 60 ++++++++++++++++++++++ fHDHR_web/brython/brython_stdlib.py | 1 + fHDHR_web/templates/base.html | 7 ++- fHDHR_web/templates/channels_editor.html | 64 ------------------------ 7 files changed, 91 insertions(+), 65 deletions(-) create mode 100644 fHDHR_web/brython/brython_bry.py create mode 100644 fHDHR_web/brython/brython_code.py diff --git a/fHDHR_web/brython/__init__.py b/fHDHR_web/brython/__init__.py index 9fdfbaf..8e9854e 100644 --- a/fHDHR_web/brython/__init__.py +++ b/fHDHR_web/brython/__init__.py @@ -3,6 +3,8 @@ from .brython import Brython from .brython_stdlib import Brython_stdlib +from .brython_bry import Brython_bry + class fHDHR_Brython(): @@ -11,3 +13,5 @@ class fHDHR_Brython(): self.brython = Brython(fhdhr) self.brython_stdlib = Brython_stdlib(fhdhr) + + self.brython_bry = Brython_bry(fhdhr) diff --git a/fHDHR_web/brython/brython.py b/fHDHR_web/brython/brython.py index 75a2f23..6e4851c 100644 --- a/fHDHR_web/brython/brython.py +++ b/fHDHR_web/brython/brython.py @@ -2,6 +2,7 @@ from flask import send_from_directory import pathlib + class Brython(): endpoints = ["/brython.js"] endpoint_name = "file_brython_js" diff --git a/fHDHR_web/brython/brython_bry.py b/fHDHR_web/brython/brython_bry.py new file mode 100644 index 0000000..9efae7e --- /dev/null +++ b/fHDHR_web/brython/brython_bry.py @@ -0,0 +1,19 @@ +from flask import send_from_directory + +import pathlib + + +class Brython_bry(): + endpoints = ["/brython.bry"] + endpoint_name = "file_brython_bry" + + def __init__(self, fhdhr): + self.fhdhr = fhdhr + self.brython_path = pathlib.Path(self.fhdhr.config.internal["paths"]["fHDHR_web_dir"]).joinpath('brython') + + def __call__(self, *args): + return self.get(*args) + + def get(self, *args): + + return send_from_directory(self.brython_path, 'brython_code.py') diff --git a/fHDHR_web/brython/brython_code.py b/fHDHR_web/brython/brython_code.py new file mode 100644 index 0000000..0012967 --- /dev/null +++ b/fHDHR_web/brython/brython_code.py @@ -0,0 +1,60 @@ +from browser import document, bind # alert, window + + +@bind("#enable_button", "click") +def enable_all(event): + for element in document.get(selector='input[type="checkbox"]'): + if element.name.endswith("enabled"): + if document["enable_button"].value == "0": + element.checked = False + element.value = False + else: + element.checked = True + element.value = True + + if document["enable_button"].value == "0": + document["enable_button"].value = "1" + document["enable_button"].text = "Enable All" + else: + document["enable_button"].value = "0" + document["enable_button"].text = "Disable All" + + +@bind("#chanSubmit", "submit") +def submit_fixup(evt): + for element in document.get(selector='input[type="checkbox"]'): + if element.name.endswith("enabled"): + if element.checked is False: + element.checked = True + element.value = False + if element.name.endswith("favorite"): + if element.checked is False: + element.checked = True + element.value = 0 + + items = document.select(".channels") + chanlist = [] + chandict = {} + + for element in items: + if element.name == "id": + if len(chandict.keys()): + chanlist.append(chandict) + chandict = {} + chandict[element.name] = element.value + element.clear() + + postForm = document.createElement('form') + postData = document.createElement('input') + postForm.method = "POST" + postForm.action = "/api/channels?method=modify&redirect=/channels_editor" + postForm.setRequestHeader = "('Content-Type', 'application/json')" + postData.name = "channels" + postData.value = chanlist + postForm.appendChild(postData) + + document.body.appendChild(postForm) + + postForm.submit() + + evt.preventDefault() diff --git a/fHDHR_web/brython/brython_stdlib.py b/fHDHR_web/brython/brython_stdlib.py index b77d8d5..ea2f628 100644 --- a/fHDHR_web/brython/brython_stdlib.py +++ b/fHDHR_web/brython/brython_stdlib.py @@ -2,6 +2,7 @@ from flask import send_from_directory import pathlib + class Brython_stdlib(): endpoints = ["/brython_stdlib.js"] endpoint_name = "file_brython_stdlib_js" diff --git a/fHDHR_web/templates/base.html b/fHDHR_web/templates/base.html index 6dab956..6f0df0a 100644 --- a/fHDHR_web/templates/base.html +++ b/fHDHR_web/templates/base.html @@ -5,9 +5,14 @@ + + + + - + +

{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} diff --git a/fHDHR_web/templates/channels_editor.html b/fHDHR_web/templates/channels_editor.html index 4ec45a8..05854b6 100644 --- a/fHDHR_web/templates/channels_editor.html +++ b/fHDHR_web/templates/channels_editor.html @@ -1,70 +1,6 @@ {% extends "base.html" %} {% block content %} - - - -

{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Channels Editor