panel improvements

This commit is contained in:
Sheppy
2017-10-25 16:55:34 +02:00
parent 307a2a928b
commit bd0719e4f9
3 changed files with 113 additions and 156 deletions

View File

@@ -1,74 +1,14 @@
#!/usr/bin/python3
import hl_utils
from hl_constants import *
import string
import re
sep = " | "
RED = 0xff0000
GREEN = 0x32CD32
GREY = 0x909090
WHITE = 0xefefef
DEFAULT_FG = 0x476243
COLOR_BORDER = 5.0
BAT_COLOR_OFFSET = 10
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 nr == 88:
return hex(GREEN)
elif end == start or nr >= end:
return hex(GREEN)
elif nr <= 0:
return hex(RED)
else:
r,g,b = 0,0,0
interval = 256 + 256
custom_interval = abs(start-end)
div = float(interval)/float(custom_interval)
if div >= interval:
hl_utils.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
#aaah fuck my life
if r == 0x100:
r = 0xFF
b = 0
elif nr >= 0:
g = int(nr)
r = 0xFF
b = 0
else:
hl_utils.error("Negative interval value???")
return(WHITE)
r = r << 16
g = g << 8
tmp_col = r + g + b
if tmp_col > 0xFFFF00:
hl_utils.error("color value too high")
return hex(tmp_col)
def guthaben():
guthaben = ''
if hl_utils.is_cip():
raw = ""
with open(hl_utils.hlpath("pracct.log")) as f:
with open(hl_utils.hlpath(PRINT_LOG)) as f:
raw = f.read();
guthaben = "Druckerguthaben: " + raw + " Euro"
col = get_color(float(raw),0,COLOR_BORDER)
@@ -80,14 +20,13 @@ def vpn():
if hl_utils.is_cip():
return ''
else:
tmp = -1
with open(hl_utils.hlpath("vpn_status.log")) as f:
with open(hl_utils.hlpath(VPN_LOG)) as f:
tmp = f.read()
tmp = ' '+tmp
return tmp;
return tmp;
def ip():
with open(hl_utils.hlpath("ip.log")) as f:
with open(hl_utils.hlpath(IP_LOG)) as f:
tmp = f.read()
tmp = ' '+tmp
return tmp;
@@ -95,15 +34,17 @@ def ip():
def battery():
if hl_utils.is_laptop():
try:
with open(hl_utils.hlpath("battery.log")) as f:
with open(hl_utils.hlpath(BATTERY_LOG)) as f:
tmp = f.read()
tmp = ' '+tmp+' | '
tmp = ' '+tmp
return tmp;
except Exception as e:
return color_panel(str(e),RED)
else:
return ""
def date():
return hl_utils.shexec("date +' ^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'")
if __name__ == "__main__":
print(ip(),vpn(),guthaben(),battery(),sep='',end='')
print(ip(),vpn(),guthaben(),battery(),date(),sep='',end='')