Permalink
Browse files

Refactored color names. Should be <state>_*.

ie.

normal_fg
normal_bg
normal_border
normal_border_width

etc....

Most widgets should fallback on fg,bg,border as values for major values
(ie. 'normal')
  • Loading branch information...
1 parent 3559d3c commit a745795a0e23eb95f8c9f5989936748c1fcc2190 dcurtis committed Aug 15, 2009
View
@@ -38,12 +38,12 @@ class Caw:
edge : [0|1] edge to position the panel on. 0 = top edge, 1 = bottom edge.
- fg_color : integer value for the default foreground color of the panel. \
+ fg : integer value for the default foreground color of the panel. \
Can be written in hex (eg. 0xff0000 being red)
- bg_color : integer value for the default background color of the panel.
+ bg : integer value for the default background color of the panel.
- border_color : integer value for the border color of the panel.
+ border : integer value for the border color of the panel.
border_width : width of the panel border
@@ -91,9 +91,9 @@ def __init__(self, **kwargs):
self.y = self.yoffset
self.above = kwargs.get('above', True)
- self.fg_color = kwargs.get('fg_color', 0x000000)
- self.bg_color = kwargs.get('bg_color', 0xd6d6d6)
- self.border_color = kwargs.get('border_color', 0x606060)
+ self.fg = kwargs.get('fg', 0x000000)
+ self.bg = kwargs.get('bg', 0xd6d6d6)
+ self.border = kwargs.get('border', 0x606060)
self.shading = kwargs.get('shading', 100)
self.font_face = kwargs.get('font_face', 'Terminus')
@@ -297,7 +297,7 @@ def set_source(self, cairo, color, shading, height):
pattern = cawc.cairo_pattern_create_linear(0,0,0,height)
step = float(height) / (len(color) - 1)
cur = 0
- for color in self.bg_color:
+ for color in self.bg:
r,g,b = self.rgb(color)
cawc.cairo_pattern_add_color_stop_rgba(pattern, cur, r, g, b, a)
cur += step
@@ -319,13 +319,13 @@ def _update_background(self, *_):
0,0,
self.width, self.height)
- self.set_source(self._back_cairo_c, self.bg_color, self.shading, self.height)
+ self.set_source(self._back_cairo_c, self.bg, self.shading, self.height)
cawc.cairo_set_line_width(self._back_cairo_c, 4)
cawc.cairo_rectangle(self._back_cairo_c, 0, 0, self.width, self.height);
cawc.cairo_fill(self._back_cairo_c)
i = 0
- r,g,b = self.rgb(self.border_color)
+ r,g,b = self.rgb(self.border)
cawc.cairo_set_line_width(self._back_cairo_c, 1.0)
cawc.cairo_set_source_rgba(self._back_cairo_c, r, g, b, 1.0)
while i < self.border_width:
@@ -390,10 +390,9 @@ def mainloop(self):
self._dirty_widgets = []
elif self._dirty_widgets:
#print "only updating dirty widgets"
- y = (self.height - self._font_height)/2 + self.font_yoffset
for dw in self._dirty_widgets:
self.clear(dw.x, 0, dw.width, self.height)
- cawc.cairo_move_to(self.cairo_c, dw.x, y)
+ self._pangox = dw.x
dw.draw()
self._dirty_widgets = []
@@ -459,7 +458,7 @@ def redraw(self, *_):
ww = varspace
w.x = x
w.width = ww
- cawc.cairo_move_to(self.cairo_c, w.x, y)
+ self._pangox = x
w.draw()
x += ww
@@ -496,25 +495,29 @@ def _property_notify(self, e):
#print "Found functions"
func(e)
- def draw_text(self, text, fg_color=None, x=None, width=None, align=0, ellipsize=3):
- if fg_color is None:
- fg_color = self.fg_color
+ def draw_text(self, text, fg=None, x=None, width=None, align=0, ellipsize=3):
+ if fg is None:
+ fg = self.fg
- r,g,b = self.rgb(fg_color)
+ r,g,b = self.rgb(fg)
cawc.cairo_set_source_rgb(self.cairo_c, r, g, b);
- if x is not None:
- #y = (self.height + self._font_height)/2 + self.font_yoffset
- y = (self.height - self._font_height)/2 + self.font_yoffset
- cawc.cairo_move_to(self.cairo_c, x, y)
+ y = (self.height - self._font_height)/2 + self.font_yoffset
+ if x is None:
+ x = self._pangox
+ else:
+ self._pangox = x
+
+ cawc.cairo_move_to(self.cairo_c, x, y)
if width is not None and width > 0:
cawc.pango_layout_set_text(self.layout_c, text, width, align, ellipsize)
else:
cawc.pango_layout_set_text(self.layout_c, text)
cawc.pango_cairo_update_show_layout(self.cairo_c, self.layout_c)
+ self._pangox += self.text_width(text)
#cawc.cairo_show_text(self.cairo_c, text);
def text_width(self, text):
View
@@ -2,15 +2,15 @@
import re
class Battery(caw.widget.Widget):
- def __init__(self, battery="BAT0", warn_color='#e7e700', low_color='#d70000', fg_color=None, **kwargs):
+ def __init__(self, battery="BAT0", fg=None, warn_fg='#e7e700', low_fg='#d70000', **kwargs):
super(Battery, self).__init__(**kwargs)
self.battery = battery
self.re = re.compile('(.*):\W*(.*)')
self.symbols = {'charging': '^', 'discharging': '_', 'charged': '='}
- self.fg_color = fg_color
- self.low_color = low_color
- self.warn_color = warn_color
+ self.normal_fg = kwargs.get('normal_fg', fg)
+ self.low_fg = low_fg
+ self.warn_fg = warn_fg
def init(self, parent):
super(Battery, self).init(parent)
@@ -71,11 +71,11 @@ def draw(self):
minutesleft = 0
if remaining < self.warn:
- color = self.warn_color
+ color = self.warn_fg
elif remaining < self.low:
- color = self.low_color
+ color = self.low_fg
else:
- color = self.fg_color
+ color = self.normal_fg
symbol = self.symbols[state]
self.parent.draw_text("%2d:%02d %s%2d%s" % (hoursleft, minutesleft, symbol, float(remaining)/self.capacity * 100, symbol) , color)
View
@@ -2,10 +2,10 @@
import time
class Clock(caw.widget.Widget):
- def __init__(self, format="%Y.%m.%d %H:%M:%S", fg_color=None, **kwargs):
+ def __init__(self, format="%Y.%m.%d %H:%M:%S", fg=None, **kwargs):
super(Clock, self).__init__(**kwargs)
self.format = format
- self.fg_color = fg_color
+ self.fg = fg
def init(self, parent):
super(Clock, self).init(parent)
@@ -18,5 +18,5 @@ def update(self):
self.parent.schedule(1, self.update)
def draw(self):
- self.parent.draw_text(self.text, fg_color=self.fg_color)
+ self.parent.draw_text(self.text, fg=self.fg)
View
@@ -18,12 +18,12 @@ class CPU(caw.widget.Widget):
_initialized = False
_widgets = collections.defaultdict(list)
- def __init__(self, cpu=0, fg_color=None, med_color=0xffff00, high_color=0xff0000, med_threshold=40, high_threshold=80, show_percent=False, **kwargs):
+ def __init__(self, cpu=0, fg=None, med_fg=0xffff00, high_fg=0xff0000, med_threshold=40, high_threshold=80, show_percent=False, **kwargs):
super(CPU, self).__init__(**kwargs)
self.cpu = cpu
- self.fg_color = fg_color
- self.med_color = med_color
- self.high_color = high_color
+ self.normal_fg = kwargs.get('normal_fg', fg)
+ self.med_fg = med_fg
+ self.high_fg = high_fg
self.med_threshold = med_threshold
self.high_threshold = high_threshold
self.show_percent = show_percent
@@ -94,16 +94,16 @@ def _set_data(self, data):
def draw(self):
val = self._data['usage']
- fg_color = self.fg_color
+ fg = self.normal_fg
if val > self.high_threshold:
- fg_color = self.high_color
+ fg = self.high_fg
elif val > self.med_threshold:
- fg_color = self.med_color
+ fg = self.med_fg
if self.show_percent:
- self.parent.draw_text("%d%%" % self._data['usage'], fg_color=fg_color)
+ self.parent.draw_text("%d%%" % self._data['usage'], fg=fg)
else:
- self.parent.draw_text("%d" % self._data['usage'], fg_color=fg_color)
+ self.parent.draw_text("%d" % self._data['usage'], fg=fg)
View
@@ -3,13 +3,23 @@
import struct
class Desktop(caw.widget.Widget):
- def __init__(self, current_fg=None, fg=None, showall=False, **kwargs):
+ """Desktop name Widget
+
+ Parameters
+ ----------
+
+ fg : alias for normal_fg
+
+ normal_fg : normal desktop color
+
+ current_fg : current desktop color
+ """
+ def __init__(self, fg=None, current_fg=None, showall=False, **kwargs):
super(Desktop, self).__init__(**kwargs)
self.desktops = []
self.current = 0
- self.fg = fg
+ self.normal_fg = kwargs.get('normal_fg', fg)
self.current_fg = current_fg
- self.fg = fg
self.showall = showall
def init(self, parent):
@@ -29,13 +39,7 @@ def init(self, parent):
self.parent.atoms[self._NET_DESKTOP_NAMES].append(self._get_desktops)
self.parent.atoms[self._NET_NUMBER_OF_DESKTOPS].append(self._get_desktops)
self._get_desktops()
- #if self.fg is None:
- # self.fg = self.parent.fg
- #if self.current_fg is None:
- # self.current_fg = self.parent.fg
- #if self.current_bg is not None or self.bg is not None:
- # self.gc = self.parent.root.create_gc()
def _get_desktops(self, *args):
conn = self.parent.connection
@@ -82,13 +86,13 @@ def _update(self, event=None):
def draw(self):
- color = self.fg
+ color = self.normal_fg
if self.showall:
for i, name in enumerate(self.desktops[:self.num_desktops]):
if i == self.current:
color = self.current_fg
else:
- color = self.fg
+ color = self.normal_fg
if i != 0:
self.parent.draw_text(' ')
View
@@ -2,11 +2,10 @@
import os
import stat
import operator
-import collections
from itertools import imap, izip
class FIFO(caw.widget.Widget):
- def __init__(self, filename, align="right", start_color=0xff0000, end_color=0x999999, steps=10, history=100, variable_width=True, **kwargs):
+ def __init__(self, filename, align="right", start_fg=0xff0000, end_fg=0x999999, steps=10, history=100, variable_width=True, **kwargs):
super(FIFO, self).__init__(**kwargs)
self.filename = filename
self.text = ''
@@ -23,27 +22,27 @@ def __init__(self, filename, align="right", start_color=0xff0000, end_color=0x99
else:
self.width_hint = self.text_width
- self.colors = [end_color]
- self.coloridx = 0
+ self.fgs = [end_fg]
+ self.fgidx = 0
- srgb = (start_color >> 16,
- start_color >> 8 & 0xff,
- start_color & 0xff)
+ srgb = (start_fg >> 16,
+ start_fg >> 8 & 0xff,
+ start_fg & 0xff)
- ergb = (end_color >> 16,
- end_color >> 8 & 0xff,
- end_color & 0xff)
+ ergb = (end_fg >> 16,
+ end_fg >> 8 & 0xff,
+ end_fg & 0xff)
step = [ (s - e) / (steps -1) for s,e in izip(srgb, ergb) ]
curcolor = ergb[:]
- for i in xrange(steps-2):
+ for _ in xrange(steps-2):
curcolor = [ c+s for c,s in izip(curcolor, step)]
color = reduce(operator.ior, (curcolor[0] << 16,
curcolor[1] << 8,
curcolor[2]))
- self.colors.append(color)
- self.colors.append(start_color)
+ self.fgs.append(color)
+ self.fgs.append(start_fg)
#self.buttons[1] = self.buttons.get(1, self.clear)
#self.buttons[2] = self.buttons.get(2, self.clear)
@@ -77,7 +76,7 @@ def update(self, eventmask):
self.historyidx = len(self.history)-1
self.settext()
- self.coloridx = len(self.colors) -1
+ self.fgidx = len(self.fgs) -1
if not self.updating:
self.parent.schedule(1, self.update_coloridx)
self.updating = True
@@ -87,10 +86,10 @@ def update(self, eventmask):
self.parent.registerfd(self.fd, self.update)
def update_coloridx(self):
- self.coloridx = max(self.coloridx-1, 0)
+ self.fgidx = max(self.fgidx-1, 0)
self.parent.update()
- if self.coloridx > 0:
+ if self.fgidx > 0:
self.parent.schedule(1, self.update_coloridx)
else:
self.updating = False
@@ -104,7 +103,7 @@ def draw(self):
if self.align=="center":
x += (self.width - self.text_width) / 2
- self.parent.draw_text(self.text, self.colors[self.coloridx], x)
+ self.parent.draw_text(self.text, self.fgs[self.fgidx], x)
def settext(self):
if self.history:
View
@@ -16,13 +16,13 @@ class Net(caw.widget.Widget):
_initialized = False
_widgets = collections.defaultdict(list)
- def __init__(self, iface='eth0', stat='down', fg_color=None, med_color=0xffff00, high_color=0xff0000, med_threshold=100, high_threshold=500, show_percent=False, **kwargs):
+ def __init__(self, iface='eth0', stat='down', fg=None, med_fg=0xffff00, high_fg=0xff0000, med_threshold=100, high_threshold=500, **kwargs):
super(Net, self).__init__(**kwargs)
self.iface = iface
self.stat = stat
- self.fg_color = fg_color
- self.med_color = med_color
- self.high_color = high_color
+ self.normal_fg = kwargs.get('normal_fg', fg)
+ self.med_fg = med_fg
+ self.high_fg = high_fg
self.med_threshold = med_threshold
self.high_threshold = high_threshold
self._data = collections.defaultdict(int)
@@ -98,13 +98,13 @@ def _set_data(self, data):
def draw(self):
val = self._data[self.stat]
- fg_color = self.fg_color
+ fg = self.normal_fg
if val > self.high_threshold:
- fg_color = self.high_color
+ fg = self.high_fg
elif val > self.med_threshold:
- fg_color = self.med_color
+ fg = self.med_fg
- self.parent.draw_text("%d" % self._data[self.stat], fg_color=fg_color)
+ self.parent.draw_text("%d" % self._data[self.stat], fg=fg)
Oops, something went wrong.

0 comments on commit a745795

Please sign in to comment.