5 log = logging.getLogger(__name__)
7 # shows the current song position (looking a bit nicer than a default widget, hopefully)
8 class SongPosition(gtk.DrawingArea):
13 gtk.DrawingArea.__init__(self)
14 self.connect('expose-event', self.on_expose)
15 self.set_size_request(24, 8)
18 orange0 = self.hex_to_flt(0xec, 0xac, 0x1f)
19 orange1 = self.hex_to_flt(0xea, 0x86, 0x1d, 0.25)
20 purple0 = self.hex_to_flt(0x81, 0x3e, 0x82)
21 purple1 = self.hex_to_flt(0x56, 0x2d, 0x5a, 0.25)
23 lightclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
24 lightclr.add_color_stop_rgba(0.0, *purple1)
25 lightclr.add_color_stop_rgba(1.0, *purple0)
27 darkclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
28 darkclr.add_color_stop_rgba(0.0, 0.0, 0.0, 0.0, 0.0)
29 darkclr.add_color_stop_rgba(1.0, 0.25, 0.25, 0.25, 1.0)
31 markerclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
32 markerclr.add_color_stop_rgba(0.0, 1.0, 1.0, 1.0, 0.0)
33 markerclr.add_color_stop_rgba(0.5, 1.0, 1.0, 1.0, 0.75)
34 markerclr.add_color_stop_rgba(1.0, 1.0, 1.0, 1.0, 1.0)
36 self.lightclr = lightclr
37 self.darkclr = darkclr
38 self.markerclr = markerclr
40 def on_expose(self, widget, event):
41 context = self.window.cairo_create()
42 context.rectangle(event.area.x, event.area.y,
43 event.area.width, event.area.height)
48 #ecac1f - light orange
51 #813e82 - light purple
54 def hex_to_flt(self, r, g, b, a = 255.0):
55 return float(r)/255.0, float(g)/255.0, float(b)/255.0, float(a)/255.0
57 def draw(self, context):
58 rect = self.get_allocation()
61 #context.set_source_rgb(1.0, 0.5, 0.0)
62 lowx = rect.width*self.pos - self.WIDTH*0.5
63 hix = rect.width*self.pos + self.WIDTH*0.5
68 elif hix > rect.width:
69 lowx = rect.width - self.WIDTH
73 context.rectangle(0, 0, lowx, rect.height)
74 context.set_source(self.lightclr)
77 if hix < rect.width-0.01:
78 context.rectangle(hix, 0, rect.width-hix, rect.height)
79 context.set_source(self.darkclr)
82 context.rectangle(lowx, 0, self.WIDTH, rect.height)
83 context.set_source(self.markerclr)
86 def set_position(self, pos):