From affb79173433f2991cb3fa4a4b06e0ab5a95a87a Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Sat, 16 Jun 2012 21:17:35 +0300 Subject: [PATCH 01/11] python3 compatible --- dzen_python/colors.py | 9 ++++++--- dzen_python/config_mod.py | 15 +++++++-------- dzen_python/dzen_python.py | 7 ++++--- dzen_python/dzen_size.py | 3 ++- dzen_python/keyboard_mod.py | 11 ++++------- dzen_python/weather.py | 4 ++-- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/dzen_python/colors.py b/dzen_python/colors.py index fafa2e0..829060b 100644 --- a/dzen_python/colors.py +++ b/dzen_python/colors.py @@ -5,8 +5,9 @@ def parse_rgb(color): b = int(int(color[5:7],16)*100/256.) return (r,g,b) -def unparse_rgb((newR,newG,newB)): - r = "%X" % int(newR*256/100.) +def unparse_rgb(nRGB): + (newR,newG,newB) = nRGB + r = "%02X".format(int(newR*256/100.)) if len(r)==1: r="0"+r g = "%X" % int(newG*256/100.) @@ -17,7 +18,9 @@ def unparse_rgb((newR,newG,newB)): b="0"+b return "#"+r+g+b -def mix_colors((lowR,lowG,lowB),(highR,highG,highB),perc): +def mix_colors(low, high, perc): + (lowR,lowG,lowB) = low + (highR,highG,highB) = high lowPerc = 100 - perc newR = (lowR*lowPerc+highR*perc)/100. newG = (lowG*lowPerc+highG*perc)/100. diff --git a/dzen_python/config_mod.py b/dzen_python/config_mod.py index a1dfda0..ddfd314 100644 --- a/dzen_python/config_mod.py +++ b/dzen_python/config_mod.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*-s -from ConfigParser import RawConfigParser +from configparser import RawConfigParser from os import getenv -from string import maketrans,translate config = RawConfigParser() config.readfp(open(getenv('HOME')+'/.dzen_pythonrc')) @@ -121,13 +120,13 @@ def replace_p(p): a = p for couple in findandreplace: a=a.replace(couple[0],couple[1]) - text = a.decode('utf-8', 'ignore') - text = text.encode('iso-8859-7', 'ignore') + #text = a.decode('utf-8', 'ignore') + #text = text.encode('iso-8859-7', 'ignore') - from_chars = u'áâãäåæçèéêëìíîïðñóòôõö÷øùÜÝÞßúÀüýûàþÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶¸¹ºÚ¼¾Û¿'.encode('latin1') - to_chars = u'abgdezh8iklmn3oprsstufxywaehiiiouuuwABGDEZH8IKLMNJOPRSTYFXCWAEHIIOUUW'.encode('latin1') - trantab = maketrans( from_chars, to_chars ) - text = translate( text, trantab ) + from_chars = 'áâãäåæçèéêëìíîïðñóòôõö÷øùÜÝÞßúÀüýûàþÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶¸¹ºÚ¼¾Û¿'.encode('latin1') + to_chars = 'abgdezh8iklmn3oprsstufxywaehiiiouuuwABGDEZH8IKLMNJOPRSTYFXCWAEHIIOUUW'.encode('latin1') + trantab = bytes.maketrans( from_chars, to_chars ) + text = a.translate(trantab) return text diff --git a/dzen_python/dzen_python.py b/dzen_python/dzen_python.py index 320e7cb..1ad8678 100755 --- a/dzen_python/dzen_python.py +++ b/dzen_python/dzen_python.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- from signal import signal, alarm, SIGALRM from subprocess import Popen,PIPE @@ -80,6 +80,7 @@ def get_data(p): 'keyboard' : "keyboard.layout()" } for i in RUN_ORDER: + print(i) j = eval(data_dict[i]) data_list.append(j) data = " ".join(data_list) @@ -111,11 +112,11 @@ def main(): p=SysStdin.readline() p=p.replace('\n','') data=get_data(p) - child_stdin.write(data) + child_stdin.write(data.encode('latin1')) continue except: data=get_data(p) - child_stdin.write(data) + child_stdin.write(data.encode('latin1')) continue if __name__ == "__main__": diff --git a/dzen_python/dzen_size.py b/dzen_python/dzen_size.py index 3ca993c..8019282 100644 --- a/dzen_python/dzen_size.py +++ b/dzen_python/dzen_size.py @@ -6,7 +6,8 @@ def resolution(): res_proc= Popen("xrandr | awk -F' ' '/current/ { print $8 $9 $10}'",shell=True,stdout=PIPE) res = res_proc.stdout inp = res.read()[:-1] - return inp.split('x') + b = inp.decode().split('x') + return b diff --git a/dzen_python/keyboard_mod.py b/dzen_python/keyboard_mod.py index ca43909..6602697 100644 --- a/dzen_python/keyboard_mod.py +++ b/dzen_python/keyboard_mod.py @@ -14,12 +14,9 @@ class get_layout(Thread): def run(self): global LAYOUT while True: - try: - res_proc= Popen("setxkbmap -print | grep xkb_symbols",shell=True,stdout=PIPE) - res = res_proc.stdout - inp = res.read().strip() - LAYOUT = set_colors(KB_COLOR, KB_BACKGROUND_COLOR)+inp.split('+')[1].upper()+set_normal_color() - except: - print "keyboard_mod error" + res_proc= Popen("setxkbmap -print | grep xkb_symbols",shell=True,stdout=PIPE) + res = res_proc.stdout + inp = res.read().decode().strip() + LAYOUT = set_colors(KB_COLOR, KB_BACKGROUND_COLOR)+inp.split('+')[1].upper()+set_normal_color() sleep(1) diff --git a/dzen_python/weather.py b/dzen_python/weather.py index 3e7af4e..88aca50 100644 --- a/dzen_python/weather.py +++ b/dzen_python/weather.py @@ -1,7 +1,7 @@ from time import sleep from threading import Thread from re import search -from urllib2 import Request, urlopen, URLError +from urllib.request import Request, urlopen, URLError from config_mod import WEATHER_BACKGROUND_COLOR, WEATHER_COLOR, WEATHER_SLEEP, REQ from colors import set_colors,set_normal_color WEATHER_COND=set_colors(WEATHER_COLOR,WEATHER_BACKGROUND_COLOR)+"n/a"+set_normal_color() @@ -16,7 +16,7 @@ def run ( self ): try: request = Request(REQ) response = urlopen(request) - the_page = response.read() + the_page = response.read().decode() result= search('e:.*?C',the_page) result_sum = search('"summary">.*?<',the_page) WEATHER_COND=set_colors(WEATHER_COLOR,WEATHER_BACKGROUND_COLOR)+result_sum.group(0)[10:len(result_sum.group(0))-2]+ result.group(0)[2:len(result.group(0))-6]+"C"+set_normal_color() From d5d43797bf002dd6e4a798bfb9a8e565e4e1fcc9 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Sat, 16 Jun 2012 21:44:44 +0300 Subject: [PATCH 02/11] python3 seems ready --- dzen_python/colors.py | 19 ++++++++++--------- dzen_python/dzen_python.py | 24 +++++++++++++++++++++--- dzen_python/ram.py | 2 +- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/dzen_python/colors.py b/dzen_python/colors.py index 829060b..e64f331 100644 --- a/dzen_python/colors.py +++ b/dzen_python/colors.py @@ -1,19 +1,19 @@ from config_mod import MEASURE_NORMAL_COLOR, MEASURE_MEDI_COLOR, MEASURE_HIGH_COLOR def parse_rgb(color): - r = int(int(color[1:3],16)*100/256.) - g = int(int(color[3:5],16)*100/256.) - b = int(int(color[5:7],16)*100/256.) + r = int(int(color[1:3],16)*100/256) + g = int(int(color[3:5],16)*100/256) + b = int(int(color[5:7],16)*100/256) return (r,g,b) def unparse_rgb(nRGB): (newR,newG,newB) = nRGB - r = "%02X".format(int(newR*256/100.)) + r = "{0:02X}".format(int(newR*256/100)) if len(r)==1: r="0"+r - g = "%X" % int(newG*256/100.) + g = "{0:02X}".format(int(newG*256/100)) if len(g)==1: g="0"+g - b = "%X" % int(newB*256/100.) + b = "{0:02X}".format(int(newB*256/100)) if len(b)==1: b="0"+b return "#"+r+g+b @@ -22,9 +22,9 @@ def mix_colors(low, high, perc): (lowR,lowG,lowB) = low (highR,highG,highB) = high lowPerc = 100 - perc - newR = (lowR*lowPerc+highR*perc)/100. - newG = (lowG*lowPerc+highG*perc)/100. - newB = (lowB*lowPerc+highB*perc)/100. + newR = (lowR*lowPerc+highR*perc)/100 + newG = (lowG*lowPerc+highG*perc)/100 + newB = (lowB*lowPerc+highB*perc)/100 return unparse_rgb((newR,newG,newB)) @@ -34,6 +34,7 @@ def set_gradient_color(percentage): colorMix = mix_colors(parse_rgb(MEASURE_NORMAL_COLOR),parse_rgb(MEASURE_MEDI_COLOR),percentage*2) else: colorMix = mix_colors(parse_rgb(MEASURE_MEDI_COLOR),parse_rgb(MEASURE_HIGH_COLOR),(percentage-50)*2) + print(colorMix) return '^fg('+colorMix+')' diff --git a/dzen_python/dzen_python.py b/dzen_python/dzen_python.py index 1ad8678..23d254a 100755 --- a/dzen_python/dzen_python.py +++ b/dzen_python/dzen_python.py @@ -3,8 +3,10 @@ from signal import signal, alarm, SIGALRM from subprocess import Popen,PIPE from sys import stdin as SysStdin,stdout as SysStdout,stderr as SysStderr -from os import system,getenv +from os import system,getenv, O_NONBLOCK +#from fcntl import fcntl, F_GETFL, F_SETFL from re import sub +from time import sleep from config_mod import replace_p,XMONAD_PERCENTAGE, TEXT_COLOR, BACKGROUND_COLOR, FONT, TIME_COLOR, TIME_BACKGROUND_COLOR, SCREEN_PERCENTAGE, RUN_ORDER import dzen_size #import torrentflux @@ -15,6 +17,14 @@ + +class Timeout(Exception): + def __init__(self): + pass + def __str__(self): + return "Timeout" + + def initialize(): global cpu,ram,hddtemp,battery,time_mod,weather,mpd_mod,dmesg,gmail_check,cputemp,statusnet,volume_mod,keyboard @@ -57,6 +67,13 @@ def initialize(): keyboard=__import__('keyboard_mod',globals(),locals(),['layout','get_layout'],-1) keyboard.get_layout().start() + + + ## make stdin a non-blocking file + #fd = SysStdin.fileno() + #fl = fcntl(fd, F_GETFL) + #fcntl(fd, F_SETFL, fl | O_NONBLOCK) + def split(): return "^pa("+str(float(dzen_size.DZEN_SIZE)*float(XMONAD_PERCENTAGE))+")" @@ -88,6 +105,7 @@ def get_data(p): return '^tw()'+data+"\n" def handler(signum,frame): + raise Timeout return @@ -110,11 +128,11 @@ def main(): alarm(1) try: p=SysStdin.readline() - p=p.replace('\n','') + p=p.rstrip() data=get_data(p) child_stdin.write(data.encode('latin1')) continue - except: + except Timeout: data=get_data(p) child_stdin.write(data.encode('latin1')) continue diff --git a/dzen_python/ram.py b/dzen_python/ram.py index 27370a0..d550865 100644 --- a/dzen_python/ram.py +++ b/dzen_python/ram.py @@ -43,7 +43,7 @@ def buffers(): return int(line.split()[1]) * 1024 def bytes_to_mb(byte): - return byte/1048576 + return byte//1048576 RAM="" TOTAL_RAM=total_mem() TOTAL_RAM_MB=bytes_to_mb(TOTAL_RAM) From d01d86e845e8894518e985501940c1f64a4d21ba Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Sat, 16 Jun 2012 21:47:10 +0300 Subject: [PATCH 03/11] removed a couple of debug prints --- dzen_python/colors.py | 1 - dzen_python/dzen_python.py | 1 - 2 files changed, 2 deletions(-) diff --git a/dzen_python/colors.py b/dzen_python/colors.py index e64f331..4c682b9 100644 --- a/dzen_python/colors.py +++ b/dzen_python/colors.py @@ -34,7 +34,6 @@ def set_gradient_color(percentage): colorMix = mix_colors(parse_rgb(MEASURE_NORMAL_COLOR),parse_rgb(MEASURE_MEDI_COLOR),percentage*2) else: colorMix = mix_colors(parse_rgb(MEASURE_MEDI_COLOR),parse_rgb(MEASURE_HIGH_COLOR),(percentage-50)*2) - print(colorMix) return '^fg('+colorMix+')' diff --git a/dzen_python/dzen_python.py b/dzen_python/dzen_python.py index 23d254a..d84a036 100755 --- a/dzen_python/dzen_python.py +++ b/dzen_python/dzen_python.py @@ -97,7 +97,6 @@ def get_data(p): 'keyboard' : "keyboard.layout()" } for i in RUN_ORDER: - print(i) j = eval(data_dict[i]) data_list.append(j) data = " ".join(data_list) From 935acc417d90863cb2e89cf37caca58c956fe161 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Sat, 30 Jun 2012 16:15:55 +0300 Subject: [PATCH 04/11] fixed greek bug --- dzen_python/config_mod.py | 6 +++--- dzen_python/dzen_python.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dzen_python/config_mod.py b/dzen_python/config_mod.py index ddfd314..dec9a18 100644 --- a/dzen_python/config_mod.py +++ b/dzen_python/config_mod.py @@ -121,12 +121,12 @@ def replace_p(p): for couple in findandreplace: a=a.replace(couple[0],couple[1]) #text = a.decode('utf-8', 'ignore') - #text = text.encode('iso-8859-7', 'ignore') + text = a.encode('iso-8859-7', 'ignore') from_chars = 'áâãäåæçèéêëìíîïðñóòôõö÷øùÜÝÞßúÀüýûàþÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶¸¹ºÚ¼¾Û¿'.encode('latin1') to_chars = 'abgdezh8iklmn3oprsstufxywaehiiiouuuwABGDEZH8IKLMNJOPRSTYFXCWAEHIIOUUW'.encode('latin1') trantab = bytes.maketrans( from_chars, to_chars ) - text = a.translate(trantab) - return text + text = text.translate(trantab) + return text.decode('utf-8', 'ignore') diff --git a/dzen_python/dzen_python.py b/dzen_python/dzen_python.py index d84a036..eedaff8 100755 --- a/dzen_python/dzen_python.py +++ b/dzen_python/dzen_python.py @@ -129,11 +129,11 @@ def main(): p=SysStdin.readline() p=p.rstrip() data=get_data(p) - child_stdin.write(data.encode('latin1')) + child_stdin.write(data.encode('latin1','ignore')) continue except Timeout: data=get_data(p) - child_stdin.write(data.encode('latin1')) + child_stdin.write(data.encode('latin1','ignore')) continue if __name__ == "__main__": From aa5b293885496c81e1e46f67522b485b74e7cc45 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Mon, 10 Sep 2012 21:23:48 +0300 Subject: [PATCH 05/11] added notifications on gmail --- dzen_python/config_mod.py | 1 + dzen_python/gmail_check.py | 31 +++++++++++++++++++++++++++++-- dzen_python/weather.py | 7 ++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/dzen_python/config_mod.py b/dzen_python/config_mod.py index dec9a18..6f034dd 100644 --- a/dzen_python/config_mod.py +++ b/dzen_python/config_mod.py @@ -82,6 +82,7 @@ STATUSNET_BACKGROUND_COLOR=config.get('main_config','STATUSNET_BACKGROUND_COLOR') +GMAIL_NOTIFIER=config.get('main_config','GMAIL_NOTIFIER') GMAIL_BACKGROUND_COLOR=config.get('main_config','GMAIL_BACKGROUND_COLOR') GMAIL_COLOR=config.get('main_config','GMAIL_COLOR') GMAIL_UNREAD_COLOR=config.get('main_config','GMAIL_UNREAD_COLOR') diff --git a/dzen_python/gmail_check.py b/dzen_python/gmail_check.py index 098cdf3..4cd4357 100644 --- a/dzen_python/gmail_check.py +++ b/dzen_python/gmail_check.py @@ -1,14 +1,39 @@ from time import sleep from threading import Thread -from config_mod import GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_USERNAME,GMAIL_PASSWORD,ICON_PATH +from config_mod import GMAIL_NOTIFIER,GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_USERNAME,GMAIL_PASSWORD,ICON_PATH from colors import set_colors,set_normal_color from imaplib import IMAP4_SSL UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+"n/a"+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() + +from gi.repository import Notify, GLib, Gtk def unread(): return UNREAD + +class gmail_notifier(object): + def __init__(self): + self._unread = 0 + Notify.init("Gmail Notifier") + def check(self, unread): + if GMAIL_NOTIFIER == "ON" and self._unread < unread: + self.notifyme(unread) + self._unread = unread + def notifyme(self, unread, icon="mail", transient=True, urgency=Notify.Urgency.NORMAL): + summary = "You got mail" + body = "You got {0} unread emails :)".format(unread) + #im-message-new is not a standard icon name, neither is user-*, but they are present + #in many themes that support empathy. lookup the supplied icon and fallback to skype + #if missing + if not Gtk.IconTheme.get_default().has_icon(icon): + icon = "mail" + n = Notify.Notification.new(summary, body, icon) + n.set_hint("transient", GLib.Variant.new_boolean(transient)) + n.set_urgency(urgency) + n.show() + class get_gmail_check(Thread): def run(self): global UNREAD + notifier = gmail_notifier() while True: try: srv = IMAP4_SSL("imap.gmail.com") @@ -17,7 +42,9 @@ def run(self): srv.select() status,count=srv.search(None,'UnSeen') #unseen= len(c.get_inbox_conversations(is_unread=True)) - UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+str(len(count[0][1:].split()))+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() + unseen = len(count[0][1:].split()) + notifier.check(unseen) + UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+str(unseen)+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() srv.close() srv.logout() sleep(60) diff --git a/dzen_python/weather.py b/dzen_python/weather.py index 88aca50..68215e0 100644 --- a/dzen_python/weather.py +++ b/dzen_python/weather.py @@ -17,9 +17,10 @@ def run ( self ): request = Request(REQ) response = urlopen(request) the_page = response.read().decode() - result= search('e:.*?C',the_page) - result_sum = search('"summary">.*?<',the_page) - WEATHER_COND=set_colors(WEATHER_COLOR,WEATHER_BACKGROUND_COLOR)+result_sum.group(0)[10:len(result_sum.group(0))-2]+ result.group(0)[2:len(result.group(0))-6]+"C"+set_normal_color() + #result= search('e:.*?C',the_page) + #result_sum = search('"summary">.*?<',the_page) + result = search('Weather ::.*?<', the_page) + WEATHER_COND=set_colors(WEATHER_COLOR,WEATHER_BACKGROUND_COLOR)+result.group(0)[11:-1]+set_normal_color() sleep(float(WEATHER_SLEEP)) continue except (URLError,AttributeError): From 1a8f7421c2a976472209964ad6c0975402be3b54 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Mon, 10 Sep 2012 21:36:21 +0300 Subject: [PATCH 06/11] updated sample config file --- dzen_pythonrc | 1 + 1 file changed, 1 insertion(+) diff --git a/dzen_pythonrc b/dzen_pythonrc index 25461a2..7f029ef 100755 --- a/dzen_pythonrc +++ b/dzen_pythonrc @@ -70,6 +70,7 @@ GMAIL_UNREAD_COLOR= #ff0000 +GMAIL_NOTIFIER = ON STATUSNET_BACKGROUND_COLOR = #000000 GMAIL_USERNAME=username GMAIL_PASSWORD=pass From 5ded50f985e1c8520086141bfe03c064d4ba0e7b Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Mon, 10 Sep 2012 21:40:35 +0300 Subject: [PATCH 07/11] updated sample config file --- dzen_pythonrc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dzen_pythonrc b/dzen_pythonrc index 7f029ef..1d150c0 100755 --- a/dzen_pythonrc +++ b/dzen_pythonrc @@ -31,7 +31,7 @@ TIME_BACKGROUND_COLOR = #000000 -RUN_ORDER=xmonad,cpu,cputemp,ram,time,weather,gmail,mpd_song,statusnet,break_line +RUN_ORDER=xmonad,split,cpu,cputemp,ram,time,weather,keyboard,gmail,mpd_song,statusnet,volume MEASURE_NORMAL_COLOR = #00FF00 @@ -39,12 +39,15 @@ MEASURE_MEDI_COLOR = #FFFF00 MEASURE_HIGH_COLOR= #FF0000 CPU_BAR_COLOR = #000000 +CPU_CORES = 2 FONT = -misc-fixed-medium-r-semicondensed--13-90-100-100-c-60-iso8859-1 +KB_COLOR = #f2f200 +KB_BACKGROUND_COLOR = #101010 -REQ = http://www.rssweather.com/icao/lgav/wx.php +REQ = http://www.rssweather.com/wx/gr/athinai/rss.php WEATHER_SLEEP = 3600 HDDTEMP_SLEEP = 10 CPU_SLEEP = 1 From 88e520ea6065d8dffbc4222ada23081566159500 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Fri, 21 Sep 2012 21:24:47 +0300 Subject: [PATCH 08/11] added mailboxes support for gmail notifications| --- dzen_python/config_mod.py | 2 +- dzen_python/cpu.py | 2 +- dzen_python/gmail_check.py | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dzen_python/config_mod.py b/dzen_python/config_mod.py index 6f034dd..a03b686 100644 --- a/dzen_python/config_mod.py +++ b/dzen_python/config_mod.py @@ -87,8 +87,8 @@ GMAIL_COLOR=config.get('main_config','GMAIL_COLOR') GMAIL_UNREAD_COLOR=config.get('main_config','GMAIL_UNREAD_COLOR') +GMAIL_MAILBOXES=config.get('main_config','GMAIL_MAILBOXES') GMAIL_USERNAME=config.get('main_config','GMAIL_USERNAME') - GMAIL_PASSWORD=config.get('main_config','GMAIL_PASSWORD') #TF_ADD=config.get('main_config','TF_ADD') diff --git a/dzen_python/cpu.py b/dzen_python/cpu.py index df255aa..bfc3328 100644 --- a/dzen_python/cpu.py +++ b/dzen_python/cpu.py @@ -31,5 +31,5 @@ def run(self): fpercentage=100*(freq-MIN_FREQ)/(MAX_FREQ-MIN_FREQ) cpu_frequencies=" @ "+set_gradient_color(fpercentage)+str(round(freq/1000.,1))+set_normal_color()+"GHz" percentage=round(cpu_percent(), 1) - CPU="^i("+ICON_PATH+"/cpu.xbm) "+set_gradient_color(percentage)+"^r("+str(ceil(float(percentage/2)))+"x8)"+set_color(CPU_BAR_COLOR)+"^r("+str(50-ceil(float(percentage/2)))+"x8)"+set_normal_color()+cpu_frequencies + CPU="^i("+ICON_PATH+"/cpu.xbm) "+set_gradient_color(percentage)+"^r("+str(int(ceil(float(percentage/2))))+"x8)"+set_color(CPU_BAR_COLOR)+"^r("+str(int(50-ceil(float(percentage/2))))+"x8)"+set_normal_color()+cpu_frequencies sleep(int(CPU_SLEEP)) diff --git a/dzen_python/gmail_check.py b/dzen_python/gmail_check.py index 4cd4357..3537945 100644 --- a/dzen_python/gmail_check.py +++ b/dzen_python/gmail_check.py @@ -1,6 +1,6 @@ from time import sleep from threading import Thread -from config_mod import GMAIL_NOTIFIER,GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_USERNAME,GMAIL_PASSWORD,ICON_PATH +from config_mod import GMAIL_NOTIFIER,GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_MAILBOXES,GMAIL_USERNAME,GMAIL_PASSWORD,ICON_PATH from colors import set_colors,set_normal_color from imaplib import IMAP4_SSL UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+"n/a"+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() @@ -39,10 +39,13 @@ def run(self): srv = IMAP4_SSL("imap.gmail.com") count=[] srv.login(GMAIL_USERNAME,GMAIL_PASSWORD) - srv.select() - status,count=srv.search(None,'UnSeen') - #unseen= len(c.get_inbox_conversations(is_unread=True)) - unseen = len(count[0][1:].split()) + unseen = 0 + for i in GMAIL_MAILBOXES.split(','): + srv.select(i) + status,count=srv.search(None,'UnSeen') + #unseen= len(c.get_inbox_conversations(is_unread=True)) + unseen += len(count[0][1:].split()) + notifier.check(unseen) UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+str(unseen)+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() srv.close() From 2a1a65a6cd107b5eab3831ed391fea237ae68848 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Mon, 15 Oct 2012 13:56:50 +0300 Subject: [PATCH 09/11] added wifi on wpa supplicant --- dzen_python/config_mod.py | 2 ++ dzen_python/dzen_python.py | 8 ++++-- dzen_python/wifi.py | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 dzen_python/wifi.py diff --git a/dzen_python/config_mod.py b/dzen_python/config_mod.py index a03b686..02f3814 100644 --- a/dzen_python/config_mod.py +++ b/dzen_python/config_mod.py @@ -91,6 +91,8 @@ GMAIL_USERNAME=config.get('main_config','GMAIL_USERNAME') GMAIL_PASSWORD=config.get('main_config','GMAIL_PASSWORD') +WIFI_SLEEP=config.get('main_config','WIFI_SLEEP') +WIFI_IFACE=config.get('main_config','WIFI_IFACE') #TF_ADD=config.get('main_config','TF_ADD') #TF_USER=config.get('main_config','TF_USER') #TF_PASS=config.get('main_config','TF_PASS') diff --git a/dzen_python/dzen_python.py b/dzen_python/dzen_python.py index eedaff8..cfdfa2f 100755 --- a/dzen_python/dzen_python.py +++ b/dzen_python/dzen_python.py @@ -26,7 +26,7 @@ def __str__(self): def initialize(): - global cpu,ram,hddtemp,battery,time_mod,weather,mpd_mod,dmesg,gmail_check,cputemp,statusnet,volume_mod,keyboard + global cpu,ram,hddtemp,battery,time_mod,weather,mpd_mod,dmesg,gmail_check,cputemp,statusnet,volume_mod,keyboard,wifi if 'cpu' in RUN_ORDER: cpu=__import__('cpu',globals(),locals(),['cpu','get_cpu'],-1) @@ -63,6 +63,9 @@ def initialize(): if 'volume' in RUN_ORDER: volume_mod=__import__('volume_mod',globals(),locals(),['volume','get_volume'],-1) volume_mod.get_volume().start() + if 'wifi' in RUN_ORDER: + wifi=__import__('wifi',globals(),locals(),['wifi','get_wifi'],-1) + wifi.wifi().start() if 'keyboard' in RUN_ORDER: keyboard=__import__('keyboard_mod',globals(),locals(),['layout','get_layout'],-1) keyboard.get_layout().start() @@ -92,8 +95,9 @@ def get_data(p): 'gmail' : "gmail_check.unread()", # 'torrentflux' : "torrentflux.SPEEDS", 'cputemp' : "cputemp.cputemp()", - 'statusnet' : "statusnet.statusnet()", + 'statusnet' : "statusnet.get_statusnet()", 'volume' : "volume_mod.volume()", + 'wifi' : "wifi.get_wifi()", 'keyboard' : "keyboard.layout()" } for i in RUN_ORDER: diff --git a/dzen_python/wifi.py b/dzen_python/wifi.py new file mode 100644 index 0000000..fe30f2c --- /dev/null +++ b/dzen_python/wifi.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 +# +#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. +# File Name : wifi.py +# Creation Date : 15-10-2012 +# Last Modified : Mon 15 Oct 2012 01:56:37 PM EEST +# Created By : Greg Liras +#_._._._._._._._._._._._._._._._._._._._._.*/ + +from threading import Thread +from config_mod import WIFI_SLEEP,WIFI_IFACE,ICON_PATH +from time import sleep +from colors import set_normal_color, set_measure_color, set_gradient_color +import socket +import os + + + +WIFI="^i("+ICON_PATH+"/net-wifi.xbm) " +WIFI_SLEEP = int(WIFI_SLEEP) +ctl_iface = "/var/run/wpa_supplicant/" + WIFI_IFACE + +def set_wifi(status): + global WIFI + WIFI = "^i("+ICON_PATH+"/net-wifi.xbm) " + status + +def get_wifi(): + return WIFI +def get_ssid(status): + lines = str(status[0]).strip("'").split("\\n") + a = lines[1].split('=')[1] + return a + +class wifi(Thread): + def run(self): + global WIFI,WIFI_SLEEP, ctl_iface + soc = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0) + soc.bind("/tmp/wpa_supplicant"+str(os.getpid())) + soc.connect(ctl_iface) + while True: + soc.sendall(b'STATUS') + status = soc.recvfrom(1024) + ssid = get_ssid(status) + set_wifi(ssid) + sleep(WIFI_SLEEP) + +def main(): + pass + +if __name__ == "__main__": + main() + From e9df9f80e47da42eb32753fff8d70b3fc4049f61 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Tue, 16 Oct 2012 10:06:12 +0300 Subject: [PATCH 10/11] modular icons --- dzen_python/battery.py | 5 +++-- dzen_python/cpu.py | 5 +++-- dzen_python/cputemp.py | 15 ++++++++++++--- dzen_python/gmail_check.py | 16 +++++++++++++--- dzen_python/hddtemp.py | 5 +++-- dzen_python/icons.py | 15 +++++++++++++++ dzen_python/ram.py | 5 +++-- dzen_python/wifi.py | 22 ++++++++++++++-------- 8 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 dzen_python/icons.py diff --git a/dzen_python/battery.py b/dzen_python/battery.py index 8b39187..650d23b 100644 --- a/dzen_python/battery.py +++ b/dzen_python/battery.py @@ -1,8 +1,9 @@ from threading import Thread from time import sleep from colors import set_measure_color,set_normal_color -from config_mod import BATTERY_NAME, ICON_PATH +from config_mod import BATTERY_NAME from pynotify import init as notiftinit,Notification,URGENCY_NORMAL,EXPIRES_NEVER +from icons import set_icon BATTERY="" def battery(): return BATTERY @@ -39,7 +40,7 @@ def run(self): for i in f2lines: if i.startswith("last full capacity"): full=i.split()[2] - BATTERY=" ^i("+ICON_PATH+"/power-bat.xbm)"+set_measure_color(100-percent)+str(percent)+set_normal_color()+"%" + BATTERY=set_icon("/power-bat.xbm")+set_measure_color(100-percent)+str(percent)+set_normal_color()+"%" f1.close() f2.close() except: diff --git a/dzen_python/cpu.py b/dzen_python/cpu.py index bfc3328..500045a 100644 --- a/dzen_python/cpu.py +++ b/dzen_python/cpu.py @@ -1,6 +1,7 @@ from threading import Thread -from config_mod import CPU_SLEEP,ICON_PATH,CPU_BAR_COLOR +from config_mod import CPU_SLEEP,CPU_BAR_COLOR from colors import set_measure_color,set_gradient_color, set_normal_color , set_color +from icons import set_icon from time import sleep from psutil import cpu_percent from math import ceil @@ -31,5 +32,5 @@ def run(self): fpercentage=100*(freq-MIN_FREQ)/(MAX_FREQ-MIN_FREQ) cpu_frequencies=" @ "+set_gradient_color(fpercentage)+str(round(freq/1000.,1))+set_normal_color()+"GHz" percentage=round(cpu_percent(), 1) - CPU="^i("+ICON_PATH+"/cpu.xbm) "+set_gradient_color(percentage)+"^r("+str(int(ceil(float(percentage/2))))+"x8)"+set_color(CPU_BAR_COLOR)+"^r("+str(int(50-ceil(float(percentage/2))))+"x8)"+set_normal_color()+cpu_frequencies + CPU=set_icon("/cpu.xbm")+set_gradient_color(percentage)+"^r("+str(int(ceil(float(percentage/2))))+"x8)"+set_color(CPU_BAR_COLOR)+"^r("+str(int(50-ceil(float(percentage/2))))+"x8)"+set_normal_color()+cpu_frequencies sleep(int(CPU_SLEEP)) diff --git a/dzen_python/cputemp.py b/dzen_python/cputemp.py index ab8718f..1cb072b 100644 --- a/dzen_python/cputemp.py +++ b/dzen_python/cputemp.py @@ -7,7 +7,7 @@ # #* Creation Date : 15-09-2011 # -#* Last Modified : Tue 01 May 2012 03:47:58 PM EEST +#* Last Modified : Tue 16 Oct 2012 10:04:50 AM EEST # #* Created By : Greg Liras # @@ -15,12 +15,21 @@ from threading import Thread from time import sleep -from config_mod import ICON_PATH +from icons import set_icon from colors import set_gradient_color,set_normal_color CPUTEMP="" def cputemp(): return CPUTEMP +def set_cputemp(TC1, percent1, TC2, percent2): + global CPUTEMP + CPUTEMP ="{0}{1}{2} | {3}{4}{5}".format(set_icon("temp.xbm"), + set_gradient_color(100-percent1), + TC1, + set_normal_color(), + set_gradient_color(100-percent2), + TC2, + set_normal_color()) class get_cputemp(Thread): def run(self): global CPUTEMP @@ -38,7 +47,7 @@ def run(self): percent1 = 100 if percent2 > 100: percent2 = 100 - CPUTEMP = "^i("+ICON_PATH+"/temp.xbm) "+ set_gradient_color(100-percent1)+str(TC1)+set_normal_color()+" | "+set_gradient_color(100-percent2)+str(TC2)+set_normal_color() + CPUTEMP = set_cputemp(TC1, percent1, TC2, percent2) f1.close() f2.close() except IOError: diff --git a/dzen_python/gmail_check.py b/dzen_python/gmail_check.py index 3537945..42f9353 100644 --- a/dzen_python/gmail_check.py +++ b/dzen_python/gmail_check.py @@ -1,13 +1,23 @@ from time import sleep from threading import Thread -from config_mod import GMAIL_NOTIFIER,GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_MAILBOXES,GMAIL_USERNAME,GMAIL_PASSWORD,ICON_PATH +from config_mod import GMAIL_NOTIFIER,GMAIL_BACKGROUND_COLOR,GMAIL_COLOR,GMAIL_UNREAD_COLOR,GMAIL_MAILBOXES,GMAIL_USERNAME,GMAIL_PASSWORD from colors import set_colors,set_normal_color from imaplib import IMAP4_SSL -UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+"n/a"+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() +from icons import set_icon +UNREAD="" from gi.repository import Notify, GLib, Gtk def unread(): return UNREAD +def set_unread(un="n/a"): + global UNREAD + UNREAD = "{0}{1}{2} {3}{4}".format(set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR), + un, + set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR), + set_icon("envelope.xbm"), + set_normal_color()) + +set_unread() class gmail_notifier(object): def __init__(self): @@ -47,7 +57,7 @@ def run(self): unseen += len(count[0][1:].split()) notifier.check(unseen) - UNREAD=set_colors(GMAIL_UNREAD_COLOR,GMAIL_BACKGROUND_COLOR)+str(unseen)+set_colors(GMAIL_COLOR,GMAIL_BACKGROUND_COLOR)+" ^i("+ICON_PATH+"/envelope.xbm)"+set_normal_color() + set_unread(unseen) srv.close() srv.logout() sleep(60) diff --git a/dzen_python/hddtemp.py b/dzen_python/hddtemp.py index c809bf6..9d4ebc2 100644 --- a/dzen_python/hddtemp.py +++ b/dzen_python/hddtemp.py @@ -1,8 +1,9 @@ from threading import Thread -from config_mod import HDDTEMP_SLEEP,ICON_PATH +from config_mod import HDDTEMP_SLEEP from socket import socket, AF_INET,SOCK_STREAM from colors import set_normal_color, set_measure_color ,set_gradient_color from time import sleep +from icons import set_icon HDDTEMP="" @@ -21,6 +22,6 @@ def run(self): percentage=100*(int(temp)-25)/60 except ValueError: continue - HDDTEMP="^i("+ICON_PATH+"/temp.xbm) "+set_gradient_color(percentage)+temp+set_normal_color()+"C" + HDDTEMP=set_icon("temp.xbm")+set_gradient_color(percentage)+temp+set_normal_color()+"C" sleep(int(HDDTEMP_SLEEP)) diff --git a/dzen_python/icons.py b/dzen_python/icons.py new file mode 100644 index 0000000..6cbf658 --- /dev/null +++ b/dzen_python/icons.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 +# +#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. +# File Name : icons.py +# Creation Date : 16-10-2012 +# Last Modified : Tue 16 Oct 2012 09:43:04 AM EEST +# Created By : Greg Liras +#_._._._._._._._._._._._._._._._._._._._._.*/ + +from config_mod import ICON_PATH + +def set_icon(iconfile): + return "^i({0}/{1}) ".format(ICON_PATH, iconfile) + diff --git a/dzen_python/ram.py b/dzen_python/ram.py index d550865..34b0c04 100644 --- a/dzen_python/ram.py +++ b/dzen_python/ram.py @@ -1,7 +1,8 @@ from threading import Thread -from config_mod import RAM_SLEEP,ICON_PATH +from config_mod import RAM_SLEEP from time import sleep from colors import set_normal_color, set_measure_color, set_gradient_color +from icons import set_icon def free_mem(): """Return the free amount memory on the system, in bytes.""" @@ -56,5 +57,5 @@ def run(self): while 1: used=bytes_to_mb(used_phymem()-cached_mem()-buffers()) percentage=(100*used)/TOTAL_RAM_MB - RAM="^i("+ICON_PATH+"/mem.xbm) "+set_gradient_color(percentage)+str(used)+set_normal_color()+"M" + RAM=set_icon("mem.xbm")+set_gradient_color(percentage)+str(used)+set_normal_color()+"M" sleep(int(RAM_SLEEP)) diff --git a/dzen_python/wifi.py b/dzen_python/wifi.py index fe30f2c..6cc8333 100644 --- a/dzen_python/wifi.py +++ b/dzen_python/wifi.py @@ -4,33 +4,39 @@ #* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. # File Name : wifi.py # Creation Date : 15-10-2012 -# Last Modified : Mon 15 Oct 2012 01:56:37 PM EEST +# Last Modified : Tue 16 Oct 2012 09:45:31 AM EEST # Created By : Greg Liras #_._._._._._._._._._._._._._._._._._._._._.*/ from threading import Thread -from config_mod import WIFI_SLEEP,WIFI_IFACE,ICON_PATH +from config_mod import WIFI_SLEEP,WIFI_IFACE from time import sleep from colors import set_normal_color, set_measure_color, set_gradient_color +from icons import set_icon import socket import os -WIFI="^i("+ICON_PATH+"/net-wifi.xbm) " +WIFI=set_icon("net-wifi.xbm") WIFI_SLEEP = int(WIFI_SLEEP) ctl_iface = "/var/run/wpa_supplicant/" + WIFI_IFACE def set_wifi(status): global WIFI - WIFI = "^i("+ICON_PATH+"/net-wifi.xbm) " + status + WIFI = "{0}{1}".format(set_icon("net-wifi.xbm"), status) def get_wifi(): return WIFI def get_ssid(status): - lines = str(status[0]).strip("'").split("\\n") - a = lines[1].split('=')[1] - return a + status = dict([ map(lambda y: str(y), x.split('=')) for x in str(status)[2:].strip("'").split("\\n") if x]) + if status['wpa_state'] == 'SCANNING': + return 'scanning' + elif status['wpa_state'] == 'COMPLETED': + return status['ssid'] + else: + print(status) + return 'check the log' class wifi(Thread): def run(self): @@ -40,7 +46,7 @@ def run(self): soc.connect(ctl_iface) while True: soc.sendall(b'STATUS') - status = soc.recvfrom(1024) + status, ctl_file = soc.recvfrom(1024) ssid = get_ssid(status) set_wifi(ssid) sleep(WIFI_SLEEP) From 4e7d63ba2d38844eca86c1b3cf9463b3c3905c95 Mon Sep 17 00:00:00 2001 From: Gregory Liras Date: Thu, 25 Oct 2012 21:11:01 +0300 Subject: [PATCH 11/11] debugged hddtemp, now apears smoother --- dzen_python/hddtemp.py | 4 ++-- dzen_python/wifi.py | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/dzen_python/hddtemp.py b/dzen_python/hddtemp.py index 9d4ebc2..6517a6a 100644 --- a/dzen_python/hddtemp.py +++ b/dzen_python/hddtemp.py @@ -13,15 +13,15 @@ class get_hddtemp(Thread): def run(self): global HDDTEMP,HDDTEMP_SLEEP while 1: + sleep(int(HDDTEMP_SLEEP)) s = socket(AF_INET, SOCK_STREAM) s.connect(("localhost",7634)) buf = s.recv(4096) s.close() - temp=buf[-5:-3] + temp=str(buf).split("|")[3] try: percentage=100*(int(temp)-25)/60 except ValueError: continue HDDTEMP=set_icon("temp.xbm")+set_gradient_color(percentage)+temp+set_normal_color()+"C" - sleep(int(HDDTEMP_SLEEP)) diff --git a/dzen_python/wifi.py b/dzen_python/wifi.py index 6cc8333..78eabe3 100644 --- a/dzen_python/wifi.py +++ b/dzen_python/wifi.py @@ -4,7 +4,7 @@ #* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. # File Name : wifi.py # Creation Date : 15-10-2012 -# Last Modified : Tue 16 Oct 2012 09:45:31 AM EEST +# Last Modified : Tue 16 Oct 2012 05:13:30 PM EEST # Created By : Greg Liras #_._._._._._._._._._._._._._._._._._._._._.*/ @@ -30,13 +30,10 @@ def get_wifi(): return WIFI def get_ssid(status): status = dict([ map(lambda y: str(y), x.split('=')) for x in str(status)[2:].strip("'").split("\\n") if x]) - if status['wpa_state'] == 'SCANNING': - return 'scanning' - elif status['wpa_state'] == 'COMPLETED': + if status['wpa_state'] == 'COMPLETED': return status['ssid'] else: - print(status) - return 'check the log' + return status['wpa_state'] class wifi(Thread): def run(self):