1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
28 TIME_LAYOUT_NORMAL = 0
29 TIME_LAYOUT_ELAPSED = 1
30 TIME_LAYOUT_MINUS = 2
31
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
52 self._title = Text()
53 self._title.label = ""
54
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
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
73 self._time = Text()
74 self._time.label = ""
75
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
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
101 """
102 Get the length of the playing media (in milliseconds)
103 """
104 return self._timebar.length
105
106
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
115
117 """
118 Get the current title of the dock
119 """
120 return self._title.label
121
130
132 """
133 Get the current time position
134 """
135 return self._time_position
136
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
185
186
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
197
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
220 """
221 Set how the time should be shown
222 """
223 self._time_layout = layout
224 self._show_time()
225
227 """
228 Get the currently used time layout
229 """
230 return self._time_layout
231