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(int(self.WIDTH), int(self.HEIGHT))
18 orange0 = self.hex_to_flt(0xec, 0xac, 0x1f)
19 orange1 = self.hex_to_flt(0xea, 0x86, 0x1d)
20 orange2 = self.hex_to_flt(0xda, 0x76, 0x0d)
21 orange3 = self.hex_to_flt(0xd0, 0x70, 0x00)
22 purple0 = self.hex_to_flt(0x81, 0x3e, 0x82)
23 purple1 = self.hex_to_flt(0x56, 0x2d, 0x5a)
25 lightclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
26 lightclr.add_color_stop_rgb(0.0, 1.0, 1.0, 1.0)
27 lightclr.add_color_stop_rgb(0.1, *orange0)
28 lightclr.add_color_stop_rgb(0.5, *orange1)
29 lightclr.add_color_stop_rgb(0.5, *orange2)
30 lightclr.add_color_stop_rgb(1.0, *orange3)
32 darkclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
33 darkclr.add_color_stop_rgb(0.0, 0.5, 0.5, 0.5)
34 darkclr.add_color_stop_rgb(0.5, 0.0, 0.0, 0.0)
35 darkclr.add_color_stop_rgb(1.0, 0.25, 0.25, 0.25)
37 markerclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
38 markerclr.add_color_stop_rgb(0.0, 1.0, 1.0, 1.0)
39 markerclr.add_color_stop_rgb(0.5, 1.0, 1.0, 1.0)
40 markerclr.add_color_stop_rgb(1.0, 1.0, 1.0, 1.0)
42 self.lightclr = lightclr
43 self.darkclr = darkclr
44 self.markerclr = markerclr
46 def on_expose(self, widget, event):
47 context = self.window.cairo_create()
48 context.rectangle(event.area.x, event.area.y,
49 event.area.width, event.area.height)
54 #ecac1f - light orange
57 #813e82 - light purple
60 def hex_to_flt(self, r, g, b):
61 return float(r)/255.0, float(g)/255.0, float(b)/255.0
63 def draw(self, context):
64 rect = self.get_allocation()
67 #context.set_source_rgb(1.0, 0.5, 0.0)
68 lowx = rect.width*self.pos
69 hix = rect.width*self.pos
74 elif hix > rect.width:
75 lowx = rect.width - self.WIDTH
78 context.rectangle(0, 0, rect.width, rect.height)
79 context.set_source(self.darkclr)
83 context.rectangle(0, 0, lowx, rect.height)
84 context.set_source(self.lightclr)
87 context.rectangle(0, 0, rect.width, rect.height)
88 context.set_source_rgb(0.3, 0.3, 0.3)
91 #context.rectangle(lowx, 0, self.WIDTH, rect.height)
92 #context.set_source(self.markerclr)
95 def set_position(self, pos):
103 def invalidate(self):