3 # module that shows a clock
7 # * finish support for 'workbeat'
10 from time import strftime,time,localtime,mktime
16 """ the init thingy """
18 global frmt, ready, acc, lst, bar
19 global wbdir, wbshow, wbstart, wbstop, wblabel, ew, sw, wboutside
21 msg = szstoolbox.MSG()
22 cfg = szstoolbox.CFG('clock')
23 workbeat = cfg.read('workbeat')
25 wbdir = cfg.read('wbdirection')
26 wboutside = cfg.read('wboutside')
27 if wboutside not in ('yes','no'):
29 msg.debug('illegal value for wboutside, using "yes"',2)
30 wbshow = cfg.read('wbshow')
31 if wbshow in ('bar','meter','both'):
32 wblabel = cfg.read('wblabel')
33 if wbshow in ('text','both'):
34 ew = int(cfg.read('ew')) # EndWith
35 sw = int(cfg.read('sw')) # StartWith
39 acc = int(szstoolbox.CFG('global').read('accuracy'))
40 frmt = str(cfg.read('format')).strip()
41 lst = frmt.split('%N')
44 if wbdir not in ('up','down',None):
46 msg.debug('illegal workbeat direction, using "up"',2)
48 if wbshow not in ('bar','meter','text','both',None):
50 msg.debug('illegal workbeat show option, using "both"',2)
53 workbeat = workbeat.split(',')
54 wbstart = workbeat[0].split(':')
55 wbstop = workbeat[1].split(':')
57 """ the main function """
59 global frmt,workbeat,bar
65 y = '@'+str(round((((time()+3600)%86400)/86.4),acc))
66 y = y[:y.find('.')+acc+1]
67 while len(y[y.find('.')+1:len(y)]) < acc: y=y+'0'
68 frmt = lst[0]+y+lst[1]
70 if wbshow <> None and wbdir <> None:
71 tpl1 = list(localtime())
72 tpl2 = list(localtime())
73 tpl1[3] = int(wbstart[0])
74 tpl1[4] = int(wbstart[1])
75 tpl2[3] = int(wbstop[0])
76 tpl2[4] = int(wbstop[1])
77 start = mktime(tuple(tpl1))
78 stop = mktime(tuple(tpl2))
80 jetzt = time() - start
82 # ### DEBUGSECTION ###
83 # print '--------D-E-B-U-G--------'
84 # print 'Start: '+str(start)#starttime
85 # print 'Stop: '+str(stop) #endtime
86 # print 'Spanne: '+str(spanne) #stop-start
87 # print 'Jetzt: '+str(jetzt) #now
88 # print 'wbshow: '+wbshow #showtype
89 # print 'wbdir: '+wbdir #direction
90 # print str(int(round(jetzt*100/spanne)))+'%'+wblabel #bar
91 # print str(100-int(round(jetzt*100/spanne)))+'%'+wblabel #100-bar
92 # print '--------D-E-B-U-G--------'
93 # ### END OF DEBUG ###
95 wb = jetzt * 100 / spanne
97 if wboutside == 'yes':
103 if wb > ew or wb < sw:
111 if wbshow in ('bar','meter'):
114 bar = str(wb)+'%'+wblabel
117 elif wbshow == 'text':
118 tmp = frmt+' ('+str(wb)+'%%)'
121 tmp = frmt+' ('+str(wb)+'%%)'
123 bar = str(wb)+'%'+wblabel
130 return [strftime(tmp),bar]
132 return [strftime(tmp)]
135 print "============================="
136 print "frmt type is "+str(type(frmt))+" (should be 'str')"
137 print "bar type is "+str(type(bar))+" (should be 'str' or 'NoneType')"
138 print "outputted text: '"+strftime(frmt)+"'"
139 print "outputted bar: '"+str(bar)+"'"
140 print "Netbeat should be: @"+str(round((((time()+3600)%86400)/86.4),acc))
141 print "Actual time should be: "+strftime("%X")
142 print "Actual date should be: "+strftime("%x")
143 print "============================="
145 if __name__ == '__main__':
146 """ only to debug... """
149 from time import sleep