Package elisa :: Package plugins :: Package bad :: Package poblenou_frontend :: Package poblenou_widgets :: Module progressbar_osd
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.poblenou_frontend.poblenou_widgets.progressbar_osd

  1  # -*- mode: python; coding: utf-8 -*- 
  2  # 
  3  # Pigment Python tools 
  4  # 
  5  # Copyright © 2006-2008 Fluendo Embedded S.L. 
  6  # 
  7  # This library is free software; you can redistribute it and/or 
  8  # modify it under the terms of the GNU Lesser General Public 
  9  # License as published by the Free Software Foundation; either 
 10  # version 2 of the License, or (at your option) any later version. 
 11  # 
 12  # This library is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 15  # Lesser General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU Lesser General Public 
 18  # License along with this library; if not, write to the 
 19  # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 20  # Boston, MA 02111-1307, USA. 
 21   
 22  import pgm 
 23  from pgm.graph.group import Group 
 24  from pgm.graph.image import Image 
 25  from pgm.timing import implicit 
 26   
 27  import os 
 28   
 29   
30 -class ProgressBarOsd(Group):
31
32 - def __init__(self, canvas, layer, length, bg_image, fg_image):
33 34 Group.__init__(self, canvas, layer) 35 36 if length > 0: 37 self._length = length 38 else: 39 ## FIXME: Raise an Error here? 40 self._length = 100 41 self._cursor_position = 0 42 43 self._bg = Image() 44 self._bg.set_from_file(bg_image) 45 self._bg.layout = pgm.IMAGE_FILLED 46 self._bg.alignment = pgm.IMAGE_LEFT 47 self._bg.height = 1.0 48 self._bg.width = 4.0 49 self._bg.bg_color = (0, 0, 0, 0) 50 self._bg.visible = True 51 52 self._bar = Image() 53 self._bar.set_from_file(fg_image) 54 self._bar.layout = pgm.IMAGE_FILLED 55 self._bar.alignment = pgm.IMAGE_LEFT 56 self._bar.height = 1.0 57 self._bar.width = 4.0 58 self._bar.size = (0, 0) 59 self._bar.bg_color = (0, 0, 0, 0) 60 self._bar.visible = True 61 self._animated_bar = implicit.AnimatedObject(self._bar) 62 self._animated_bar.mode = implicit.REPLACE 63 self._animated_bar.setup_next_animations(duration = 200) 64 65 self.add(self._bg) 66 self.add(self._bar) 67 68 self._offset = 0.16 69 self.visible = True
70 71
72 - def size__set(self, size):
73 """ 74 Set the size of the bar. The bar is automatically new painted 75 """ 76 self._bg.size = size 77 # Needed for nicer animations 78 self._bar.height = size[1] 79 self._paint_bar(animated = False)
80
81 - def length__set(self, length):
82 """ 83 Set the length. The bar is automatically new painted 84 @param length: the length of the process 85 @type length: as above: something to do mathematic stuff 86 """ 87 self._length = length 88 if self._length <= 0: 89 self._length = 1 90 if self._cursor_position > self._length: 91 self._cursor_position = self._length 92 self._paint_bar()
93
94 - def length__get(self):
95 """ 96 to get the length: 97 @return: returns the length 98 """ 99 return self._length
100
101 - def _paint_bar(self, animated = True):
102 """ 103 Here the position is calculated and the bar is painted 104 """ 105 next_pos = self._bg.size[0] / self.length * \ 106 self._cursor_position 107 if animated: 108 self._animated_bar.width = next_pos 109 else: 110 self._animated_bar.stop_animations() 111 self._bar.width = next_pos
112
113 - def cursor_position__set(self, position):
114 """ 115 Set the position of the cursor. The bar is automatically new painted 116 (with animation) 117 @param position: the position to set to 118 @type position: something to do mathematic stuff with 119 """ 120 self._cursor_position = position 121 self._cursor_position = max(0, 122 min(self._cursor_position, self._length) 123 ) 124 # if self._cursor_position <= self._length: 125 self._paint_bar()
126
127 - def cursor_position__get(self):
128 """ 129 returns the position of the cursor 130 @return : the position of the cursor 131 """ 132 return self._cursor_position
133
134 - def jump_to_position(self, position):
135 """ 136 Jump to this position. This means that the cursor doesn't go there 137 with animationm but that it is there immediatly 138 @param position: the position to jump to 139 @type position: something to do mathematic stuff with 140 """ 141 self._cursor_position = position 142 self._cursor_position = max(0, 143 min(self._cursor_position, self.length) 144 ) 145 self._paint_bar(animated=False)
146
147 - def bg_color__set(self, color):
148 """ 149 Set the background color. The bar is automatically new painted 150 @param color: color of the background 151 """ 152 self._bg.bg_color = color
153
154 - def bg_color__get(self):
155 """ 156 returns the current background color 157 """ 158 return self._bg.bg_color
159
160 - def bar_color__set(self, color):
161 """ 162 Set the color of the bar. The bar is automatically new painted 163 @param color: color of the bar 164 """ 165 self._bar.bg_color = color
166
167 - def bar_color__get(self):
168 """ 169 return the current color of the bar 170 """ 171 return self._bar.bg_color
172