fix to fit text into button using js and fix classname setting to not find wrong ids and update README

This commit is contained in:
2021-09-07 23:25:52 +02:00
parent 596e188c75
commit bc7a5d7239
3 changed files with 44 additions and 12 deletions

12
README
View File

@@ -1,21 +1,25 @@
Install
./setup.sh
Requirements:
- For volume buttons: libpulse
- (optionally) for volume buttons: libpulse
local:
./setup.sh
Uninstall
pip uninstall controldeck
rm ~/.local/share/application/controldeck.desktop
rm ~/.config/systemd/user/controldeck.service
Configuration
~/.config/controldeck/controldeck.conf
See example in example directory.
Start (autostart) with systemd
systemctl --user start controldeck.service
systemctl --user enable controldeck.service
journalctl --user-unit=controldeck -e
journalctl --user-unit=controldeck -f

33
controldeck.py Normal file → Executable file
View File

@@ -11,7 +11,7 @@ from os import path, sep, makedirs
from subprocess import Popen, PIPE, STDOUT
from configparser import ConfigParser
from re import search, IGNORECASE
from justpy import Div, I, WebPage, SetRoute, parse_html, justpy
from justpy import Div, I, WebPage, SetRoute, parse_html, run_task, justpy
from cairosvg import svg2svg
APP_NAME = "ControlDeck"
@@ -254,7 +254,7 @@ class Button(Div):
self.text = ''
else:
self.classes = "border-2 border-gray-700 bg-gray-800 hover:bg-gray-700 text-gray-500 w-20 h-20 m-2 p-1 rounded-lg font-bold flex items-center text-center justify-center select-none"
self.classes = "fitin border-2 border-gray-700 bg-gray-800 hover:bg-gray-700 text-gray-500 w-20 h-20 m-2 p-1 rounded-lg font-bold flex items-center text-center justify-center select-none"
self.style = f"background-color:{self.color_bg};" if ishexcolor(self.color_bg) else ''
self.style += f"color:{self.color_fg};" if ishexcolor(self.color_fg) else ''
@@ -292,9 +292,13 @@ class Button(Div):
self.inner_html = f"<i class='fa-2x {self.icon}'><i>"
else:
if self.text_alt and not search(self.state_pattern, self.state):
self.text = self.text_alt
else:
self.text = self.text_normal
# self.text = self.text_alt
# div for fitin logic
self.inner_html = f"<div>{self.text_alt}</div>"
elif self.text_normal: # only if string is not empty (for font icons)
# self.text = self.text_normal
# div for fitin logic
self.inner_html = f"<div>{self.text_normal}</div>"
self.update_state()
class ButtonsSound(Div):
@@ -531,6 +535,25 @@ def application(request):
icon=j['icon'], icon_alt=j['icon-alt'],
image=j['image'], image_alt=j['image-alt'], a=eval(var))
# fit text of button
javascript_string = """
function fitin() {
var fitindiv = document.querySelectorAll(".fitin");
var i;
for (i = 0; i < fitindiv.length; i++) {
// inner div needed to see if inner div is larger in height to reduce the font-size
fitindivdiv = fitindiv[i].firstElementChild;
while( fitindivdiv.clientHeight > fitindiv[i].clientHeight ) {
fitindivdiv.style.fontSize = (parseInt(window.getComputedStyle(fitindivdiv).fontSize) - 1) + "px";
}
}
};
fitin();
"""
async def page_ready(self, msg):
run_task(self.run_javascript(javascript_string, request_id='fitin_logic', send=False))
wp.on('page_ready', page_ready)
if not wp.components:
# config not found or empty, therefore insert an empty div to not get an error
Div(text="add elements in controldeck.conf", classes="flex flex-wrap", a=wp)

11
controldeck_gui.py Normal file → Executable file
View File

@@ -12,14 +12,19 @@ def thread_function(name):
# print("Thread %s: starting", name)
for i in range(10):
# print("Thread %s: finishing", name)
p = process("xdotool search --name 'ControlDeck'")
# p = process("xdotool search --name 'ControlDeck'")
# intersection of ControlDeck window name and empty classname
p = process("comm -12 <(xdotool search --name 'ControlDeck' | sort) <(xdotool search --classname '^$' | sort)")
if p:
# print(p)
# process("xdotool search --name 'ControlDeck' set_window --class 'controldeck'", output=False)
process("xdotool search --name 'ControlDeck' set_window --classname 'controldeck' --class 'ControlDeck' windowunmap windowmap", output=False)
# process("xdotool search --name 'ControlDeck' set_window --classname 'controldeck' --class 'ControlDeck' windowunmap windowmap", output=False) # will find to many wrong ids
process(f"xdotool set_window --classname 'controldeck' --class 'ControlDeck' {p} windowunmap {p} windowmap {p}", output=False)
time.sleep(0.1)
def main(args, pid=-1):
controldeck_process = process("ps --no-headers -C controldeck")
#controldeck_process = process("ps --no-headers -C controldeck")
controldeck_process = process("ps --no-headers -C controldeck || ps aux | grep -e 'python.*controldeck.py' | grep -v grep")
if args.start and controldeck_process == "":
process("controldeck &", output=False)