mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 07:56:57 -05:00
Make Universal Brython Functions
This commit is contained in:
parent
51b9a85597
commit
28383d89ec
@ -3,6 +3,8 @@
|
|||||||
from .brython import Brython
|
from .brython import Brython
|
||||||
from .brython_stdlib import Brython_stdlib
|
from .brython_stdlib import Brython_stdlib
|
||||||
|
|
||||||
|
from .brython_bry import Brython_bry
|
||||||
|
|
||||||
|
|
||||||
class fHDHR_Brython():
|
class fHDHR_Brython():
|
||||||
|
|
||||||
@ -11,3 +13,5 @@ class fHDHR_Brython():
|
|||||||
|
|
||||||
self.brython = Brython(fhdhr)
|
self.brython = Brython(fhdhr)
|
||||||
self.brython_stdlib = Brython_stdlib(fhdhr)
|
self.brython_stdlib = Brython_stdlib(fhdhr)
|
||||||
|
|
||||||
|
self.brython_bry = Brython_bry(fhdhr)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ from flask import send_from_directory
|
|||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
class Brython():
|
class Brython():
|
||||||
endpoints = ["/brython.js"]
|
endpoints = ["/brython.js"]
|
||||||
endpoint_name = "file_brython_js"
|
endpoint_name = "file_brython_js"
|
||||||
|
|||||||
19
fHDHR_web/brython/brython_bry.py
Normal file
19
fHDHR_web/brython/brython_bry.py
Normal file
@ -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')
|
||||||
60
fHDHR_web/brython/brython_code.py
Normal file
60
fHDHR_web/brython/brython_code.py
Normal file
@ -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()
|
||||||
@ -2,6 +2,7 @@ from flask import send_from_directory
|
|||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
|
||||||
class Brython_stdlib():
|
class Brython_stdlib():
|
||||||
endpoints = ["/brython_stdlib.js"]
|
endpoints = ["/brython_stdlib.js"]
|
||||||
endpoint_name = "file_brython_stdlib_js"
|
endpoint_name = "file_brython_stdlib_js"
|
||||||
|
|||||||
@ -5,9 +5,14 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="style.css" rel="stylesheet">
|
<link href="style.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/brython.js"></script>
|
||||||
|
<script type="text/javascript" src="/brython_stdlib.js"></script>
|
||||||
|
<script type="text/python" src="brython.bry"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body onload="brython({debug: 1, indexedDB: false})">
|
||||||
|
|
||||||
<h1 class="center" style="text-align:center">
|
<h1 class="center" style="text-align:center">
|
||||||
<span style="text-decoration: underline;"><strong><em>{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }}</em></strong>
|
<span style="text-decoration: underline;"><strong><em>{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }}</em></strong>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@ -1,70 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<body onload="brython({debug: 1, indexedDB: false})">
|
|
||||||
<script type="text/javascript" src="/brython.js"></script>
|
|
||||||
<script type="text/javascript" src="/brython_stdlib.js"></script>
|
|
||||||
<script type="text/python" id="enable0">
|
|
||||||
from browser import document, alert, window, bind
|
|
||||||
|
|
||||||
@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 == False:
|
|
||||||
element.checked = True
|
|
||||||
element.value = False
|
|
||||||
if element.name.endswith("favorite"):
|
|
||||||
if element.checked == 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()
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h4 style="text-align: center;">{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Channels Editor</h4>
|
<h4 style="text-align: center;">{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Channels Editor</h4>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user