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(0.5, *purple0)
26 lightclr.add_color_stop_rgba(0.501, *purple1)
27 lightclr.add_color_stop_rgba(1.0, *purple1)
29 darkclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
30 darkclr.add_color_stop_rgba(0.0, 0.0, 0.0, 0.0, 0.0)
31 darkclr.add_color_stop_rgba(1.0, 0.25, 0.25, 0.25, 1.0)
33 markerclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
34 markerclr.add_color_stop_rgba(0.0, 1.0, 1.0, 1.0, 0.0)
35 markerclr.add_color_stop_rgba(0.5, 1.0, 1.0, 1.0, 0.75)
36 markerclr.add_color_stop_rgba(1.0, 1.0, 1.0, 1.0, 1.0)
38 self.lightclr = lightclr
39 self.darkclr = darkclr
40 self.markerclr = markerclr
42 def on_expose(self, widget, event):
43 context = self.window.cairo_create()
44 context.rectangle(event.area.x, event.area.y,
45 event.area.width, event.area.height)
50 #ecac1f - light orange
53 #813e82 - light purple
56 def hex_to_flt(self, r, g, b, a = 255.0):
57 return float(r)/255.0, float(g)/255.0, float(b)/255.0, float(a)/255.0
59 def draw(self, context):
60 rect = self.get_allocation()
63 #context.set_source_rgb(1.0, 0.5, 0.0)
64 lowx = rect.width*self.pos - self.WIDTH*0.5
65 hix = rect.width*self.pos + self.WIDTH*0.5
70 elif hix > rect.width:
71 lowx = rect.width - self.WIDTH
75 context.rectangle(0, 0, lowx, rect.height)
76 context.set_source(self.lightclr)
79 if hix < rect.width-0.01:
80 context.rectangle(hix, 0, rect.width-hix, rect.height)
81 context.set_source(self.darkclr)
84 context.rectangle(lowx, 0, self.WIDTH, rect.height)
85 context.set_source(self.markerclr)
88 def set_position(self, pos):