various fixes and migration to python

This commit is contained in:
Sheppy
2017-02-24 23:03:35 +01:00
parent 61d9ea1fc7
commit a8f64b3229
5 changed files with 97 additions and 16 deletions

View File

@@ -14,7 +14,7 @@ xsetroot -solid '#5A8E3A'
hc keyunbind --all
pkill dunst
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
Mod=Mod4 # Use the super key as the main modifier

View File

@@ -2,13 +2,14 @@
import os
import sys
import time
from hl_utils import error, is_cip, shexec, color_remove
from hl_utils import error, is_cip, shexec, color_remove, hlpath
#Druckerguthaben
if is_cip():
while(True):
path = hlpath("pracct.log")
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)
time.sleep(60)
time.sleep(30)
sys.exit()

View File

@@ -5,6 +5,9 @@ import subprocess
import shlex
import re
def hlpath(addition=""):
return os.path.join(os.path.expanduser("~"),".config/herbstluftwm/"+addition)
def color_remove(s):
'''removes colorcodes from inputstring'''
return re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]').sub('',s)
@@ -14,7 +17,11 @@ def shexec(s):
def is_cip():
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):
with open("herbstlog",'a') as f:

View File

@@ -118,21 +118,18 @@ hc pad $monitor $panel_height
echo -n "^bg()^fg() ${windowtitle//^/^^}"
# small adjustments
#powersupply
pwr="NO BATTERY"
if [ $HOSTNAME == atlantislaptop ] || [$HOSTNAME == atlantismedion ] ; then
pwr="$(acpi -b | sed -r 's/Battery [0-9]+: //')"
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
powersupply
#pwr="NO BATTERY"
#if [ $HOSTNAME == atlantislaptop ] || [$HOSTNAME == atlantismedion ] ; then
# pwr="$(acpi -b | sed -r 's/Battery [0-9]+: //')"
#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')
# get width of right aligned text.. and add some space..
width=$($textwidth "$font" "$right_text_only ")
echo -n "^pa($(($panel_width - $width)))$right"
echo -n "^pa($(($panel_width - $width - 20)))$right"
echo
### Data handling ###

View File

@@ -1 +1,77 @@
#!/usr/bin/python3
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())