mirror of
https://github.com/FAUSheppy/config
synced 2025-12-06 15:11:35 +01:00
various fixes and migration to python
This commit is contained in:
@@ -14,7 +14,7 @@ xsetroot -solid '#5A8E3A'
|
|||||||
hc keyunbind --all
|
hc keyunbind --all
|
||||||
pkill dunst
|
pkill dunst
|
||||||
pkill xautolock
|
pkill xautolock
|
||||||
pkill -s 15 hl_pracct_deamon #send SIGTERM for correct termination during write
|
pkill -s 15 hl_pracct #send SIGTERM for correct termination during write
|
||||||
|
|
||||||
#variables
|
#variables
|
||||||
Mod=Mod4 # Use the super key as the main modifier
|
Mod=Mod4 # Use the super key as the main modifier
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from hl_utils import error, is_cip, shexec, color_remove
|
from hl_utils import error, is_cip, shexec, color_remove, hlpath
|
||||||
|
|
||||||
#Druckerguthaben
|
#Druckerguthaben
|
||||||
if is_cip():
|
if is_cip():
|
||||||
while(True):
|
while(True):
|
||||||
|
path = hlpath("pracct.log")
|
||||||
out = color_remove(shexec("pr_acct").split("\n")[0]).split(' ')[-1]
|
out = color_remove(shexec("pr_acct").split("\n")[0]).split(' ')[-1]
|
||||||
with open("pracct.log",'w') as f :
|
with open(path,'w+') as f:
|
||||||
f.write(out)
|
f.write(out)
|
||||||
time.sleep(60)
|
time.sleep(30)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import subprocess
|
|||||||
import shlex
|
import shlex
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
def hlpath(addition=""):
|
||||||
|
return os.path.join(os.path.expanduser("~"),".config/herbstluftwm/"+addition)
|
||||||
|
|
||||||
def color_remove(s):
|
def color_remove(s):
|
||||||
'''removes colorcodes from inputstring'''
|
'''removes colorcodes from inputstring'''
|
||||||
return re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]').sub('',s)
|
return re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]').sub('',s)
|
||||||
@@ -14,7 +17,11 @@ def shexec(s):
|
|||||||
|
|
||||||
def is_cip():
|
def is_cip():
|
||||||
u = os.uname()
|
u = os.uname()
|
||||||
return "cip" in u.release or "faui" in u.name or "ircbox" in u.name
|
return "cip" in u.release or "faui" in u.nodename or "ircbox" in u.nodename
|
||||||
|
|
||||||
|
def is_laptop():
|
||||||
|
u = os.uname()
|
||||||
|
return "laptop" in u.nodename or "atlantismedion" in u.nodename
|
||||||
|
|
||||||
def error(s):
|
def error(s):
|
||||||
with open("herbstlog",'a') as f:
|
with open("herbstlog",'a') as f:
|
||||||
|
|||||||
@@ -118,21 +118,18 @@ hc pad $monitor $panel_height
|
|||||||
echo -n "^bg()^fg() ${windowtitle//^/^^}"
|
echo -n "^bg()^fg() ${windowtitle//^/^^}"
|
||||||
# small adjustments
|
# small adjustments
|
||||||
|
|
||||||
#powersupply
|
powersupply
|
||||||
pwr="NO BATTERY"
|
#pwr="NO BATTERY"
|
||||||
if [ $HOSTNAME == atlantislaptop ] || [$HOSTNAME == atlantismedion ] ; then
|
#if [ $HOSTNAME == atlantislaptop ] || [$HOSTNAME == atlantismedion ] ; then
|
||||||
pwr="$(acpi -b | sed -r 's/Battery [0-9]+: //')"
|
# pwr="$(acpi -b | sed -r 's/Battery [0-9]+: //')"
|
||||||
fi
|
#fi
|
||||||
pracct=""
|
|
||||||
if [ $HOSTNAME~="faui*" ]; then
|
|
||||||
pracct="$(pr_acct | head -n 1 | sed -r 's/.*: //' | sed -r 's/\x1b\[[0-9]+m//' | sed -r 's/\x1b\[[0-9]+m//')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
right="^fg(#32CD32) Druckerguthaben: $pracct Euro^bg() ^fg(#ff0000) $pwr $separator^bg() $date $separator"
|
right="$($HOME/.config/herbstluftwm/panel_content.py) $date"
|
||||||
|
#right="^fg(#32CD32) Druckerguthaben: -256 Euro^bg() ^fg(#ff0000) $separator^bg() $date $separator"
|
||||||
right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
|
right_text_only=$(echo -n "$right" | sed 's.\^[^(]*([^)]*)..g')
|
||||||
# get width of right aligned text.. and add some space..
|
# get width of right aligned text.. and add some space..
|
||||||
width=$($textwidth "$font" "$right_text_only ")
|
width=$($textwidth "$font" "$right_text_only ")
|
||||||
echo -n "^pa($(($panel_width - $width)))$right"
|
echo -n "^pa($(($panel_width - $width - 20)))$right"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
### Data handling ###
|
### Data handling ###
|
||||||
|
|||||||
@@ -1 +1,77 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import hl_utils
|
import hl_utils
|
||||||
|
|
||||||
|
final = ""
|
||||||
|
date = ""
|
||||||
|
sep = " | "
|
||||||
|
|
||||||
|
RED = 0xff0000
|
||||||
|
GREEN = 0x32CD32
|
||||||
|
GREY = 0x909090
|
||||||
|
WHITE = 0xefefef
|
||||||
|
DEFAULT_FG = 0x476243
|
||||||
|
COLOR_BORDER = 5.0
|
||||||
|
|
||||||
|
def color_panel(s,hex_code,seper=True):
|
||||||
|
if type(hex_code)==int:
|
||||||
|
hex_code = hex(hex_code)
|
||||||
|
hex_code = hex_code.lstrip('0x')
|
||||||
|
if seper:
|
||||||
|
sep=color_panel('|',DEFAULT_FG,False)
|
||||||
|
else:
|
||||||
|
sep = ""
|
||||||
|
return "^fg(#" + hex_code + ") " + s + "^bg()"+sep
|
||||||
|
|
||||||
|
def get_color(nr,start,end):
|
||||||
|
if end == start or nr > end:
|
||||||
|
return hex(GREEN)
|
||||||
|
else:
|
||||||
|
r,g,b = 0,0,0
|
||||||
|
interval = 256 + 256
|
||||||
|
custom_interval = abs(start-end)
|
||||||
|
div = float(interval)/float(custom_interval)
|
||||||
|
if div >= interval/3:
|
||||||
|
error("Interval for coloring too small, using default")
|
||||||
|
return WHITE
|
||||||
|
nr = nr*div
|
||||||
|
if custom_interval > interval:
|
||||||
|
custom_interval = interval
|
||||||
|
if nr > 256:
|
||||||
|
g = 0xFF
|
||||||
|
r = int(abs(nr - (256+256))) #counts down reverse to nr
|
||||||
|
b = 0
|
||||||
|
elif nr > 0:
|
||||||
|
g = int(nr - 256)
|
||||||
|
r = 0xFF
|
||||||
|
b = 0
|
||||||
|
else:
|
||||||
|
error("Negative interval value???")
|
||||||
|
r = r << 16
|
||||||
|
g = g << 8
|
||||||
|
tmp_col = r + g + b
|
||||||
|
if tmp_col > 0xFFFF00:
|
||||||
|
error("color value too high")
|
||||||
|
return hex(tmp_col)
|
||||||
|
|
||||||
|
|
||||||
|
def guthaben():
|
||||||
|
if hl_utils.is_cip():
|
||||||
|
tmp = -1
|
||||||
|
with open(hl_utils.hlpath("pracct.log")) as f:
|
||||||
|
tmp = float(f.read());
|
||||||
|
guthaben = "Druckerguthaben: " + str(tmp) + " Euro"
|
||||||
|
col = get_color(tmp,0,COLOR_BORDER)
|
||||||
|
guthaben = color_panel(guthaben,col)
|
||||||
|
return guthaben;
|
||||||
|
|
||||||
|
def battery():
|
||||||
|
if hl_utils.is_laptop():
|
||||||
|
try:
|
||||||
|
return color_panel(hl_utils.shexec("acpi -b | sed -r 's/Battery [0-9]+: //"),RED)
|
||||||
|
except(ValueError):
|
||||||
|
return color_panel("acpi or sed not in path",RED)
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
print(guthaben(),battery())
|
||||||
|
|||||||
Reference in New Issue
Block a user