def run(self): global CPU,CPU_SLEEP MAX_FREQ=0 MIN_FREQ=999999 while 1: f = open('/proc/cpuinfo', 'r') ## cpu_frequencies="" freqs=[] for line in f: if line.startswith('cpu MHz'): freqs.append(int(round(float(line.split()[3]),0))) f.close() ## for i in range (len(freqs)): ## cpu_frequencies+=" Core"+str(i)+"@ "+str(freqs[i]) freq=max(freqs) if MAX_FREQ<freq: MAX_FREQ=freq if MIN_FREQ>freq: MIN_FREQ=freq-1 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 sleep(int(CPU_SLEEP))
def drawCSSRectangle(pos=(0,0), size=(100,100), style={}, prefix=None, state=None): '''Draw a rectangle with CSS :Parameters: `state`: if a certain state string is passed, we will use styles with this postifx instead. for example: style[bg-color] and style[bg-color-down] are both set. if state == "down", we wil use bg-color-down instead of bg-color :Styles: * alpha-background (color) * border-radius (float) * border-radius-precision (float) * border-width (float) * draw-alpha-background (bool) * draw-background (bool) * draw-border (bool) ''' bg_image = style.get('bg-image-'+str(state)) if not bg_image: bg_image = style.get('bg-image') # Check if we have a cached version cache_id = '%s:%s:%s:%s:%s' % (pos, size, style, prefix, state) cache = Cache.get('css_rect', cache_id) if cache: cache.draw() if bg_image: bg_image.size = size bg_image.pos = pos bg_image.draw() return # lets use the ones for given state, # and ignore the regular ones if the state ones are there if state: state = "-" + state newstyle = {} overwrites = [] for s in style: if state in s: overwrite = s.replace(state, '') newstyle[overwrite] = style[s] overwrites.append(overwrite) if s not in overwrites: newstyle[s] = style[s] style = newstyle # hack to remove prefix in style if prefix is not None: prefix += '-' newstyle = {} for k in style: newstyle[k] = style[k] for k in style: if prefix in k: newstyle[k.replace(prefix, '')] = style[k] style = newstyle style.setdefault('border-width', 1.5) style.setdefault('border-radius', 0) style.setdefault('border-radius-precision', .1) style.setdefault('draw-border', 0) style.setdefault('draw-background', 1) style.setdefault('draw-alpha-background', 0) style.setdefault('alpha-background', (1, 1, .5, .5)) k = { 'pos': pos, 'size': size } new_cache = GlDisplayList() with new_cache: if state: set_color(*style['bg-color']) #hack becasue old widgets set this themselves linewidth = style.get('border-width') bordercolor = None if 'border-color' in style: bordercolor = style['border-color'] if style['border-radius'] > 0: k.update({ 'radius': style['border-radius'], 'precision': style['border-radius-precision'] }) if style['draw-background']: drawRoundedRectangle(**k) if style['draw-border']: if linewidth: glPushAttrib(GL_LINE_BIT) glLineWidth(linewidth) if bordercolor: with gx_color(*bordercolor): drawRoundedRectangle(style=GL_LINE_LOOP, **k) else: drawRoundedRectangle(style=GL_LINE_LOOP, **k) if linewidth: glPopAttrib() if style['draw-alpha-background']: drawRoundedRectangleAlpha(alpha=style['alpha-background'], **k) else: if style['draw-background']: drawRectangle(**k) if style['draw-border']: if linewidth: glPushAttrib(GL_LINE_BIT) glLineWidth(linewidth) if bordercolor: with gx_color(*bordercolor): drawRectangle(style=GL_LINE_LOOP, **k) else: drawRectangle(style=GL_LINE_LOOP, **k) if linewidth: glPopAttrib() if style['draw-alpha-background']: drawRectangleAlpha(alpha=style['alpha-background'], **k) # if the drawCSSRectangle is already inside a display list # compilation will not happen, but drawing yes. # so, store only if a cache is created ! if new_cache.is_compiled(): Cache.append('css_rect', cache_id, new_cache) new_cache.draw() if bg_image: bg_image.size = size bg_image.pos = pos bg_image.draw()
from colors import set_color if __name__ == "__main__": """When running as the main script, this program should 1) ask user for a color name 2) ask user for a color value 3) execute `set_color` passing a color name, color value """ set_color(None, None)