New progress bar
authorKristoffer Grönlund <kristoffer.gronlund@purplescout.se>
Tue, 5 Jan 2010 18:55:32 +0000 (19:55 +0100)
committerKristoffer Grönlund <kristoffer.gronlund@purplescout.se>
Wed, 6 Jan 2010 13:56:42 +0000 (14:56 +0100)
helldon/__init__.py
jamaui/playerwindow.py
jamaui/songposition.py

index 0959038..9f095c6 100644 (file)
@@ -1,4 +1,5 @@
 import gtk
+import cairo
 
 gtk.HILDON_SIZE_AUTO = -1
 gtk.HILDON_SIZE_AUTO_WIDTH = -1
@@ -10,6 +11,21 @@ BUTTON_ARRANGEMENT_VERTICAL = 1
 def hildon_gtk_window_set_progress_indicator(wnd, onoff):
     pass
 
+def transparent_expose(widget, event):
+    bgimg = 'data/bg.png'
+    if bgimg:
+        background, mask = gtk.gdk.pixbuf_new_from_file(bgimg).render_pixmap_and_mask()
+        #self.realize()
+        widget.window.set_back_pixmap(background, False)
+        #widget.window.clear()
+    #cr = widget.window.cairo_create()
+    #cr.set_operator(cairo.OPERATOR_CLEAR)
+    # Ugly but we don't have event.region
+    #region = gtk.gdk.region_rectangle(event.area)
+    #cr.region(region)
+    #cr.fill()
+    return False
+
 class Program(gtk.Window):
     instance = None
 
@@ -18,13 +34,17 @@ class Program(gtk.Window):
         self.set_app_paintable(True)
         self._vbox = gtk.VBox()
         self._title = gtk.Label("Jamaendo")
+        self._title.set_alignment(0.1, 0.5)
         self._backbtn = gtk.Button("Quit")
+        self._backbtn.set_alignment(1.0, 0.5)
         self._hbox = gtk.HBox()
         self._hbox.pack_start(self._title, True)
         self._hbox.pack_start(self._backbtn, False)
         self._notebook = gtk.Notebook()
         self._notebook.set_size_request(800, 445)
         self._notebook.set_show_tabs(False)
+        self._notebook.set_app_paintable(True)
+        self._notebook.connect("expose-event", transparent_expose)
         self._vbox.pack_start(self._hbox, False)
         self._vbox.pack_start(self._notebook, True)
         self.add(self._vbox)
@@ -60,6 +80,7 @@ class Program(gtk.Window):
             self._backbtn.set_label("<<<")
         else:
             self._backbtn.set_label("Quit")
+        self._notebook.window.clear()
 
     def popped_stackable(self, wnd=None):
         pass
@@ -85,9 +106,27 @@ class Program(gtk.Window):
     def size(self):
         return len(self._stack)+1
 
-class StackableWindow(gtk.Frame):
+    def pop(self, sz):
+        ret = [x for x in self._stack] + [self._notebook.get_nth_page(0)]
+        while self._stack:
+            self.pop_stackable()
+        return ret
+
+    def push_list(self, windows):
+        for window in windows:
+            self.push_stackable(window)
+
+    #        windows = stack.pop(sz)
+    #    windows.remove(player)
+    #    windows.append(player)
+    #    stack.push_list(windows)
+
+
+class StackableWindow(gtk.EventBox):
     def __init__(self):
-        gtk.Frame.__init__(self)
+        gtk.EventBox.__init__(self)
+        self.set_app_paintable(True)
+        #self.connect("expose-event", transparent_expose)
         self._nb_index = 0
         Program.instance.push_stackable(self)
         self.connect('destroy', self.on_destroy)
@@ -126,4 +165,6 @@ class Button(gtk.Button):
         self.set_label(title)
 
 class PannableArea(gtk.ScrolledWindow):
-    pass
+    def __init__(self):
+        gtk.ScrolledWindow.__init__(self)
+        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
index 2fd350a..1ff65f8 100644 (file)
@@ -55,9 +55,9 @@ class PlayerWindow(hildon.StackableWindow):
         self.player = the_player
         self.playlist = the_player.playlist
 
-        vbox = gtk.VBox()
+        vbox = gtk.VBox(False, 8)
 
-        hbox = gtk.HBox(False, 8)
+        hbox = gtk.HBox(False)
 
         self.cover = gtk.Image()
         self.set_default_cover()
@@ -85,8 +85,10 @@ class PlayerWindow(hildon.StackableWindow):
         vbox2.pack_start(self.track, True)
         vbox2.pack_start(self.artist, True)
         vbox2.pack_start(self.album, True)
+        vbox2.pack_start(self.progress, False, True)
 
-        hbox.pack_start(self.cover, False, True, 0)
+        hbox.set_border_width(8)
+        hbox.pack_start(self.cover, False, True, 8)
         hbox.pack_start(vbox2, True, True, 0)
 
         vbox.pack_start(hbox, True, True, 0)
@@ -96,8 +98,6 @@ class PlayerWindow(hildon.StackableWindow):
 
         vbox.pack_start(btns, False, True, 0)
 
-        vbox.pack_start(self.progress, False)
-
         self.add_stock_button(btns, gtk.STOCK_MEDIA_PREVIOUS, self.on_prev)
         self.add_play_button(btns)
         self.add_stock_button(btns, gtk.STOCK_MEDIA_STOP, self.on_stop)
index f20a5ae..8aea80e 100644 (file)
@@ -7,33 +7,37 @@ log = logging.getLogger(__name__)
 # shows the current song position (looking a bit nicer than a default widget, hopefully)
 class SongPosition(gtk.DrawingArea):
     WIDTH = 32.0
-    HEIGHT = 8.0
+    HEIGHT = 16.0
 
     def __init__(self):
         gtk.DrawingArea.__init__(self)
         self.connect('expose-event', self.on_expose)
-        self.set_size_request(24, 8)
+        self.set_size_request(self.WIDTH, self.HEIGHT)
         self.pos = 0.0
 
         orange0 = self.hex_to_flt(0xec, 0xac, 0x1f)
-        orange1 = self.hex_to_flt(0xea, 0x86, 0x1d, 0.25)
+        orange1 = self.hex_to_flt(0xea, 0x86, 0x1d)
+        orange2 = self.hex_to_flt(0xda, 0x76, 0x0d)
+        orange3 = self.hex_to_flt(0xd0, 0x70, 0x00)
         purple0 = self.hex_to_flt(0x81, 0x3e, 0x82)
-        purple1 = self.hex_to_flt(0x56, 0x2d, 0x5a, 0.25)
+        purple1 = self.hex_to_flt(0x56, 0x2d, 0x5a)
 
         lightclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
-        lightclr.add_color_stop_rgba(0.0, *purple1)
-        lightclr.add_color_stop_rgba(0.5, *purple0)
-        lightclr.add_color_stop_rgba(0.501, *purple1)
-        lightclr.add_color_stop_rgba(1.0, *purple1)
+        lightclr.add_color_stop_rgb(0.0, 1.0, 1.0, 1.0)
+        lightclr.add_color_stop_rgb(0.1, *orange0)
+        lightclr.add_color_stop_rgb(0.5, *orange1)
+        lightclr.add_color_stop_rgb(0.5, *orange2)
+        lightclr.add_color_stop_rgb(1.0, *orange3)
 
         darkclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
-        darkclr.add_color_stop_rgba(0.0, 0.0, 0.0, 0.0, 0.0)
-        darkclr.add_color_stop_rgba(1.0, 0.25, 0.25, 0.25, 1.0)
+        darkclr.add_color_stop_rgb(0.0, 0.5, 0.5, 0.5)
+        darkclr.add_color_stop_rgb(0.5, 0.0, 0.0, 0.0)
+        darkclr.add_color_stop_rgb(1.0, 0.25, 0.25, 0.25)
 
         markerclr = cairo.LinearGradient(0.0, 0.0, 0.0, self.HEIGHT)
-        markerclr.add_color_stop_rgba(0.0, 1.0, 1.0, 1.0, 0.0)
-        markerclr.add_color_stop_rgba(0.5, 1.0, 1.0, 1.0, 0.75)
-        markerclr.add_color_stop_rgba(1.0, 1.0, 1.0, 1.0, 1.0)
+        markerclr.add_color_stop_rgb(0.0, 1.0, 1.0, 1.0)
+        markerclr.add_color_stop_rgb(0.5, 1.0, 1.0, 1.0)
+        markerclr.add_color_stop_rgb(1.0, 1.0, 1.0, 1.0)
 
         self.lightclr = lightclr
         self.darkclr = darkclr
@@ -53,16 +57,16 @@ class SongPosition(gtk.DrawingArea):
     #813e82 - light purple
     #562d5a - dark purple
 
-    def hex_to_flt(self, r, g, b, a = 255.0):
-        return float(r)/255.0, float(g)/255.0, float(b)/255.0, float(a)/255.0
+    def hex_to_flt(self, r, g, b):
+        return float(r)/255.0, float(g)/255.0, float(b)/255.0
 
     def draw(self, context):
         rect = self.get_allocation()
 
 
         #context.set_source_rgb(1.0, 0.5, 0.0)
-        lowx = rect.width*self.pos - self.WIDTH*0.5
-        hix = rect.width*self.pos + self.WIDTH*0.5
+        lowx = rect.width*self.pos
+        hix = rect.width*self.pos
 
         if lowx < 0.0:
             lowx = 0.0
@@ -71,19 +75,22 @@ class SongPosition(gtk.DrawingArea):
             lowx = rect.width - self.WIDTH
             hix = rect.width
 
+        context.rectangle(0, 0, rect.width, rect.height)
+        context.set_source(self.darkclr)
+        context.fill()
+
         if lowx > 0.01:
             context.rectangle(0, 0, lowx, rect.height)
             context.set_source(self.lightclr)
             context.fill()
 
-        if hix < rect.width-0.01:
-            context.rectangle(hix, 0, rect.width-hix, rect.height)
-            context.set_source(self.darkclr)
-            context.fill()
+        context.rectangle(0, 0, rect.width, rect.height)
+        context.set_source_rgb(0.6, 0.6, 0.6)
+        context.stroke()
 
-        context.rectangle(lowx, 0, self.WIDTH, rect.height)
-        context.set_source(self.markerclr)
-        context.fill()
+        #context.rectangle(lowx, 0, self.WIDTH, rect.height)
+        #context.set_source(self.markerclr)
+        #context.fill()
 
     def set_position(self, pos):
         if pos < 0.0: