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

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

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17  import pgm 
 18  from pgm.graph.text import Text 
 19  from pgm.graph.image import Image 
 20   
 21  from progressbar_osd import ProgressBarOsd 
 22  from dock import Dock 
 23   
 24  import time, os 
 25   
 26   
 27  # The Time-Layouts 
 28  TIME_LAYOUT_NORMAL = 0 
 29  TIME_LAYOUT_ELAPSED = 1 
 30  TIME_LAYOUT_MINUS = 2 
 31   
32 -class PlayerOsd(Dock):
33
34 - def __init__(self, canvas, layer, 35 playing_length, 36 width, height, 37 bar_bg_image, bar_fg_image, 38 background_image):
39 40 Dock.__init__(self, canvas, layer, width, height, background_image) 41 42 self._time_position = 0 43 self._time_string = "" 44 self._time_layout = TIME_LAYOUT_NORMAL 45 46 47 inner_width = width * 0.9 48 inner_x = (width - inner_width)/2.0 49 50 51 # build the title 52 self._title = Text() 53 self._title.label = "" 54 # self._title.font_family = "MgOpen Cosmetica" 55 self._title.ellipsize = pgm.TEXT_ELLIPSIZE_MIDDLE 56 self._title.fg_color = (220, 220, 220, 255) 57 self._title.bg_color = (0, 0, 0, 0) 58 self.add(self._title) 59 self._title.position = (inner_x, 0.05, 0.0) 60 self._title.size = (inner_width, height*0.33) 61 self._title.font_height = self._title.height 62 63 # build the time bar 64 self._timebar = ProgressBarOsd(canvas, layer, playing_length, 65 bar_bg_image, bar_fg_image) 66 self._timebar.bg_color = (0, 0, 0, 0) 67 self.add(self._timebar) 68 self._timebar.position = (inner_x, height*(0.33+0.15), 0.0) 69 self._timebar.size = (inner_width, height*0.2) 70 self._timebar.visible = False 71 72 # build the total time text 73 self._time = Text() 74 self._time.label = "" 75 # self._time.font_family = "MgOpen Cosmetica" 76 self._time.fg_color = (255, 255, 255, 255) 77 self._time.bg_color = (0, 0, 0, 0) 78 self._time.alignment = pgm.TEXT_ALIGN_RIGHT 79 self.add(self._time) 80 self._time.position = (inner_x, height*(0.33+0.2+0.15), 0.001) 81 self._time.size = (inner_width, height*0.2) 82 self._time.font_height = self._time.height 83 self._time.visible = False 84 85 self._title.visible = True 86 87 self.playing_length = playing_length
88
89 - def playing_length__set(self, length):
90 """ 91 Set the length of the playing media (in milliseconds) 92 """ 93 self._timebar.length = length 94 if length > 1: 95 self._timebar.visible = True 96 self._show_time() 97 else: 98 self._timebar.visible = False
99
100 - def playing_length__get(self):
101 """ 102 Get the length of the playing media (in milliseconds) 103 """ 104 return self._timebar.length
105 106
107 - def title__set(self, title):
108 """ 109 Set the title of the dock 110 @param title: the name of a movie or a audio file 111 @type title: string 112 """ 113 self._title.label = title
114 # self._title.font_height = self._title.height 115
116 - def title__get(self):
117 """ 118 Get the current title of the dock 119 """ 120 return self._title.label
121
122 - def time__set(self, position):
123 """ 124 Set the time position to position 125 """ 126 self._time_position = position 127 self._time.visible = bool(position > 1) 128 self._timebar.jump_to_position(position) 129 self._show_time()
130
131 - def time__get(self):
132 """ 133 Get the current time position 134 """ 135 return self._time_position
136
137 - def _conv_secs(self, sec, format):
138 """ 139 This returns a converted string of the seconds in the given format 140 (which must be a string that is usable for time.strftime()) 141 If the intelligent_mode was swichted on and there was the word "days" in format 142 it is replaced with the number of weeks and days 143 """ 144 if "days" in format: 145 if sec >= 60480000: 146 weeks = int(sec / 604800000) 147 if weeks != 1: 148 replacer = "%s weeks" % weeks 149 else: 150 replacer = "1 week" 151 152 days = int(((sec - (weeks * 604800000)) / 86400000)) 153 if days != 1: 154 replacer += " %s days" % days 155 else: 156 replacer += " 1 day" 157 format = format.replace("days" , replacer) 158 elif sec >= 86400000: 159 days = int(sec / 86400000) 160 format = format.replace("days" , ("%s day(s)", days)) 161 else: 162 format = format.replace("days","") 163 164 return time.strftime(format, time.gmtime(sec/1000))
165
166 - def _show_time(self):
167 format = self.conversion_string 168 label = "" 169 170 if self._time_layout == TIME_LAYOUT_MINUS: 171 label = "- %s" % (self._conv_secs( 172 self.playing_length 173 -self.time, format)) 174 elif self._time_layout == TIME_LAYOUT_ELAPSED: 175 label = "%s" % (self._conv_secs(self.time, format)) 176 else: 177 if self.time > 1: 178 label = self._conv_secs(self.time, format) 179 if self.playing_length > 1: 180 total = self._conv_secs(self.playing_length, format) 181 label += " / %s" % total 182 183 if label != self._time.label: 184 self._time.label = label
185 # self._time.font_height = self._time.height 186
187 - def conversion_string__set(self, string):
188 """ 189 Set the conversion string for the time to string 190 @param string: a string that could be parsed by time.strftime 191 if there is none given, the player dock is set in the intelligent 192 mode, and trys to guess what format is usefull 193 """ 194 self._time_string = string 195 self._show_time()
196 # FIXME: missed total time formatting 197
198 - def conversion_string__get(self):
199 """ 200 Returns the string that is currently used to parse in time.strftime 201 """ 202 if self._time_string == "": 203 format = "%Ss" 204 if self.playing_length > 1: 205 time_value = self.playing_length 206 else: 207 time_value = self.time 208 if time_value >= 86400000: 209 format = "days %H:%M" 210 elif time_value >= 3600000: 211 format = "%H:%M:%S" 212 elif time_value >= 60000: 213 format = "%M:%S" 214 215 return format 216 else: 217 return self._time_string
218
219 - def time_layout__set(self, layout):
220 """ 221 Set how the time should be shown 222 """ 223 self._time_layout = layout 224 self._show_time()
225
226 - def time_layout__get(self):
227 """ 228 Get the currently used time layout 229 """ 230 return self._time_layout
231