#378: Advanced (pieces) progress bar
-------------------+--------------------------------------------------------
 Reporter:  andar  |       Owner:  andar 
     Type:  patch  |      Status:  new   
 Priority:  major  |   Milestone:  Future
Component:  gtkui  |     Version:        
 Keywords:         |  
-------------------+--------------------------------------------------------

Comment(by s0undt3ch):

 Here's a GTK example, nevermind the colors used ;)

 {{{
 #!python
 import pygtk
 pygtk.require('2.0')
 import gtk

 class PiecesBar(gtk.DrawingArea):
     def __init__(self):
         gtk.DrawingArea.__init__(self)
         self.width = 0
         self.height = 0
         self.pieces = []

         self.connect('size-allocate', self.on_size_allocate)
         self.connect('expose-event', self.update)
         self.connect('realize', self.on_realize)

         self.show()

     def on_realize(self, widget):
         map = widget.get_colormap()
         done_color = map.alloc_color("#325891")
         down_color = map.alloc_color("#67DB63")
         wait_color = map.alloc_color("#EBF57A")
         miss_color = map.alloc_color("#FF4D36")
         outline_color = map.alloc_color("#888888")

         self.colors = {
             0: widget.window.new_gc(foreground=miss_color),
             1: widget.window.new_gc(foreground=wait_color),
             2: widget.window.new_gc(foreground=down_color),
             3: widget.window.new_gc(foreground=done_color)
         }
         self.gc_done = widget.window.new_gc(foreground=done_color)
         self.gc_down = widget.window.new_gc(foreground=down_color)
         self.gc_wait = widget.window.new_gc(foreground=wait_color)
         self.gc_miss = widget.window.new_gc(foreground=miss_color)
         self.gc_outline = widget.window.new_gc(foreground=outline_color)

     def on_size_allocate(self, widget, size):
         self.width = size.width
         self.height = size.height

     def update(self, widget=None, event=None):
         num_pieces = len(self.pieces)

         if num_pieces < 1:
             self.clear()
             return None

         self.window.draw_rectangle(self.gc_outline, False, 0, 0,
                                    self.width - 1, self.height - 1)

         width = self.width - 2
         pieces = self.collapse_pieces()

         start_pos = 1

         for state, wpercent in pieces:
             print state, wpercent
             pwidth = width*wpercent
             print 1, pwidth
             self.draw_piece(state, start_pos, 1, pwidth, self.height - 2)
             start_pos += pwidth

     def collapse_pieces(self):
         num_pieces = len(self.pieces)*1.0
         opieces = self.pieces[:]
         npieces = []
         v = None
         n = None
         while True:
             if not opieces:
                 break
             if v is None:
                 v = opieces.pop(0)
                 n = 1
             else:
                 vv = opieces.pop(0)
                 if v == vv:
                     n += 1
                 else:
                     npieces.append((v, n/num_pieces))
                     v = vv
                     n = 1
         return npieces

     def draw_piece(self, piece, start_x, start_y, width, height):
         self.window.draw_rectangle(
             self.colors[piece], True, start_x, start_y, width, height
         )

     def clear(self):
         self.pieces = [0]
         self.update()

     def get_text(self):
         return ""

     def set_text(self, text):
         pass

 pieces = PiecesBar()
 pieces.pieces = [3, 2, 1, 1, 1, 0, 0, 2, 0, 1, 0, 2, 2, 2, 1, 2, 2, 0, 0,
 0, 2,
                  1, 1, 1, 2, 0, 0, 2, 2, 1, 0, 2, 1, 0, 1, 1, 0, 0, 2, 3,
 3, 3,
                  3, 3, 0, 3, 3, 0, 0, 2, 0, 2, 2, 2, 0, 2, 2, 1]

 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 window.add(pieces)
 window.show_all()
 gtk.main()
 }}}

 How about this?

-- 
Ticket URL: <http://dev.deluge-torrent.org/ticket/378#comment:23>
Deluge <http://deluge-torrent.org/>
Deluge project

-- 
You received this message because you are subscribed to the Google Groups 
"Deluge Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-dev?hl=en.

Reply via email to