From bc7a5d7239d6cf83811ff30dae058dabd3ce2434 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Tue, 7 Sep 2021 23:25:52 +0200 Subject: [PATCH] fix to fit text into button using js and fix classname setting to not find wrong ids and update README --- README | 12 ++++++++---- controldeck.py | 33 ++++++++++++++++++++++++++++----- controldeck_gui.py | 11 ++++++++--- 3 files changed, 44 insertions(+), 12 deletions(-) mode change 100644 => 100755 controldeck.py mode change 100644 => 100755 controldeck_gui.py diff --git a/README b/README index 810f9da..123c5e3 100644 --- a/README +++ b/README @@ -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 diff --git a/controldeck.py b/controldeck.py old mode 100644 new mode 100755 index 30999ae..238fc13 --- a/controldeck.py +++ b/controldeck.py @@ -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"" 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"
{self.text_alt}
" + 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"
{self.text_normal}
" 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) diff --git a/controldeck_gui.py b/controldeck_gui.py old mode 100644 new mode 100755 index 0d38b7f..67fb531 --- a/controldeck_gui.py +++ b/controldeck_gui.py @@ -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)