Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 412 lines (320 sloc) 12.205 kb
5748b02 First public version in GITHUB repository
Sergio Costas authored
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3
4 # Copyright 2006-2009 (C) Raster Software Vigo (Sergio Costas)
5 # Copyright 2006-2009 (C) Peter Gill - win32 parts
6
7 # This file is part of DeVeDe
8 #
9 # DeVeDe is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # DeVeDe is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 import pygtk # for testing GTK version number
23 pygtk.require ('2.0')
24 import gtk
25 import cairo
26 import os
27
28 import devede_other
29 import devede_dialogs
30 import devede_xml_menu
31 import devede_newfiles
32 import devede_help
33
34
35 class menu_options:
36
37 def __init__(self,gladefile,structure,global_vars,callback):
38
39 self.global_vars=global_vars
40 self.gladefile=gladefile
41 self.structure=structure
42 self.callback=callback
43
44 self.tree=devede_other.create_tree(self,"wmenu_properties",self.gladefile)
45 self.window=self.tree.get_object("wmenu_properties")
46
47 menu_filename=global_vars["menu_bg"]
48 if menu_filename==None:
49 menu_filename=os.path.join(global_vars["path"],"backgrounds","default_bg.png")
50 w=self.tree.get_object("menu_bg_file")
51 w.set_filename(menu_filename)
52 filter=gtk.FileFilter()
53 filter.add_mime_type("image/*")
54 filter.set_name("Pictures")
55 w.add_filter(filter)
56
57 self.preview_x=200
58 self.preview_y=200
59 self.sf_final=cairo.ImageSurface(cairo.FORMAT_ARGB32,self.preview_x,self.preview_y)
60 self.preview=gtk.DrawingArea()
61 self.preview.set_size_request(self.preview_x,self.preview_y)
62 self.preview.connect("expose-event",self.repaint_preview)
63 w.set_preview_widget(self.preview)
64
65 self.on_menu_bg_file_update_preview(w,menu_filename)
66
67 self.adding_sound=True
68 w=self.tree.get_object("menu_sound")
69 print "filtro"
70 filter2=gtk.FileFilter()
71 filter2.add_mime_type("audio/mpeg")
72 filter2.add_mime_type("audio/x-wav")
73 filter2.add_mime_type("application/ogg")
74 filter2.add_mime_type("audio/ogg")
75 filter2.set_name("Audio files")
76 w.add_filter(filter2)
77 print "filtrado"
78 w.set_filename(global_vars["menu_sound"])
79 print "Añado"
80
81 w=self.tree.get_object("menufont")
82 w.set_font_name(global_vars["fontname"])
83
84 w=self.tree.get_object("unselected_color")
85 color=global_vars["menu_font_color"]
86 c1=gtk.gdk.Color(color[0],color[1],color[2])
87 w.set_color(c1)
88 w.set_alpha(color[3])
89
90 w=self.tree.get_object("selected_color")
91 color=global_vars["menu_selc_color"]
92 c1=gtk.gdk.Color(color[0],color[1],color[2])
93 w.set_color(c1)
94
95 w=self.tree.get_object("shadow_color")
96 color=global_vars["menu_shadow_color"]
97 c1=gtk.gdk.Color(color[0],color[1],color[2])
98 w.set_color(c1)
99 w.set_alpha(color[3])
100
101 w=self.tree.get_object("bg_color")
102 color=global_vars["menu_bgcolor"]
103 c1=gtk.gdk.Color(color[0],color[1],color[2])
104 w.set_color(c1)
105 w.set_alpha(color[3])
106
107 if global_vars["menu_alignment"]==0:
108 w=self.tree.get_object("menutop")
109 elif global_vars["menu_alignment"]==1:
110 w=self.tree.get_object("menubottom")
111 else:
112 w=self.tree.get_object("menumiddle")
113 w.set_active(True)
114
115 if global_vars["menu_halignment"]==0:
116 w=self.tree.get_object("menuleft")
117 elif global_vars["menu_halignment"]==1:
118 w=self.tree.get_object("menuright")
119 else:
120 w=self.tree.get_object("menucenter")
121 w.set_active(True)
122
123 if global_vars["do_menu"]:
124 w=self.tree.get_object("domenu")
125 else:
126 w=self.tree.get_object("notmenu")
127 w.set_active(True)
128
129 w=self.tree.get_object("menu_title_text")
130 w.set_text(global_vars["menu_title_text"])
131
132 w=self.tree.get_object("menu_title_color")
133 color=global_vars["menu_title_color"]
134 c1=gtk.gdk.Color(color[0],color[1],color[2])
135 w.set_color(c1)
136 w.set_alpha(color[3])
137
138 w=self.tree.get_object("menu_title_shadow")
139 color=global_vars["menu_title_shadow"]
140 c1=gtk.gdk.Color(color[0],color[1],color[2])
141 w.set_color(c1)
142 w.set_alpha(color[3])
143
144 w=self.tree.get_object("menu_title_font")
145 w.set_font_name(global_vars["menu_title_fontname"])
146
26cc636 @rastersoft Now allows to specify the margins for the menu system
authored
147 w=self.tree.get_object("margin_top_adj")
148 w.set_value(100.0*global_vars["menu_top_margin"])
149 w=self.tree.get_object("margin_bottom_adj")
150 w.set_value(100.0*global_vars["menu_bottom_margin"])
151 w=self.tree.get_object("margin_left_adj")
152 w.set_value(100.0*global_vars["menu_left_margin"])
153 w=self.tree.get_object("margin_right_adj")
154 w.set_value(100.0*global_vars["menu_right_margin"])
155
5748b02 First public version in GITHUB repository
Sergio Costas authored
156 self.window.show()
157
158
159 def repaint_preview(self,dwidget,evento):
160 try:
161 cr=dwidget.window.cairo_create()
162 cr.set_source_surface(self.sf_final)
163 cr.paint()
164 except:
165 return
166
167
168 def on_menu_bg_file_update_preview(self,widget,filename2=None):
169 try:
170 if filename2==None:
171 filename=widget.get_preview_filename()
172 else:
173 filename=filename2
174
175 print "Using "+str(filename)+" as menu background"
176
177 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
178 x = pixbuf.get_width()
179 y = pixbuf.get_height()
180
181 sf_base = cairo.ImageSurface(0,x,y)
182
183 ct = cairo.Context(sf_base)
184 ct2 = gtk.gdk.CairoContext(ct)
185
186 ct2.set_source_pixbuf(pixbuf,0,0)
187 ct2.paint()
188 ct2.stroke()
189
190 xbase=float(sf_base.get_width())
191 ybase=float(sf_base.get_height())
192
193 cr_final=cairo.Context(self.sf_final)
194 cr_final.set_source_rgb(1.0,1.0,1.0)
195 cr_final.paint()
196 if xbase>ybase:
197 divisor=xbase
198 else:
199 divisor=ybase
200
201 cr_final.scale(float(self.preview_x)/divisor,float(self.preview_y)/divisor)
202
203 cr_final.set_source_surface(sf_base)
204 cr_final.paint()
205 self.repaint_preview(self.preview,"")
206 widget.set_preview_widget_active(True)
207 except:
208 widget.set_preview_widget_active(False)
209
210
211 def on_menu_sound_selection_changed(self,widget):
212
213 print "Entro"
214
215 if self.adding_sound:
216 self.adding_sound=False
217 return
218
219 filename=widget.get_filename()
220 if (filename==None) or (filename==""):
221 return
222
223 test=devede_newfiles.file_get_params()
224 check,channels=test.read_file_values(filename,True)
225 if (check!=False) or (channels!=1):
226 filename=os.path.join(self.global_vars["path"],"silence.ogg")
227 widget.set_filename(filename)
228 w = devede_dialogs.show_error(self.gladefile,_("The menu soundtrack seems damaged. Using the default silent soundtrack."))
229 w = None
230 test=None
231
232
233 def on_menu_no_sound_clicked(self,widget):
234
235 w=self.tree.get_object("menu_sound")
236 w.set_filename(os.path.join(self.global_vars["path"],"silence.ogg"))
237
238 def on_menu_help_clicked(self,widget):
239
240 help_class=devede_help.show_help(self.gladefile,self.global_vars["help_path"],"menu.html")
241
242 def on_menuprop_cancel_clicked(self,widget):
243
244 self.window.hide()
245 self.window.destroy()
246 self.window=None
247
248
249 def on_menuprop_accept_clicked(self,widget):
250
251 self.set_new_bg(self.global_vars)
252 self.window.hide()
253 self.window.destroy()
254 self.window=None
255
256
257 def on_menu_preview_clicked(self,widget):
258
259 global_vars2={}
260 global_vars2["PAL"]=self.global_vars["PAL"]
261 global_vars2["with_menu"]=True
d726839 Fixed the DVD menu preview
Sergio Costas authored
262 global_vars2["AC3_fix"]=self.global_vars["AC3_fix"]
24b54c4 Added support for AVconv
Sergio Costas authored
263 global_vars2["AC3_fix_ffmpeg"]=self.global_vars["AC3_fix_ffmpeg"]
264 global_vars2["AC3_fix_avconv"]=self.global_vars["AC3_fix_avconv"]
265 global_vars2["encoder_video"]=self.global_vars["encoder_video"]
266 global_vars2["encoder_menu"]=self.global_vars["encoder_menu"]
5748b02 First public version in GITHUB repository
Sergio Costas authored
267 self.set_new_bg(global_vars2)
268 window=menu_preview(self.gladefile,self.structure,global_vars2)
269 window=None
270
271
272 def on_menu_default_bg_clicked(self,widget):
273
274 self.global_vars["menu_bg"]=os.path.join(self.global_vars["path"],"backgrounds","default_bg.png")
275 w=self.tree.get_object("menu_bg_file")
276 w.set_filename(self.global_vars["menu_bg"])
277
278
279 def set_new_bg(self,global_vars):
280
281 w=self.tree.get_object("menu_bg_file")
282 menu_filename=w.get_filename()
283 if menu_filename==None:
284 menu_filename=os.path.join(self.global_vars["path"],"backgrounds","default_bg.png")
285 global_vars["menu_bg"]=menu_filename
286
287 w=self.tree.get_object("menu_sound")
288 sound_filename=w.get_filename()
289 test=devede_newfiles.file_get_params()
290 check,channels=test.read_file_values(sound_filename,True)
291 global_vars["menu_sound"]=sound_filename
292 global_vars["menu_sound_duration"]=test.length
293 test=None
294
295 w=self.tree.get_object("menufont")
296 global_vars["fontname"]=w.get_font_name()
297
298 w=self.tree.get_object("unselected_color")
299 color=w.get_color()
300 global_vars["menu_font_color"]=[color.red,color.green,color.blue,w.get_alpha()]
301
302 w=self.tree.get_object("selected_color")
303 color=w.get_color()
304 global_vars["menu_selc_color"]=[color.red,color.green,color.blue,65535]
305
306 w=self.tree.get_object("shadow_color")
307 color=w.get_color()
308 global_vars["menu_shadow_color"]=[color.red,color.green,color.blue,w.get_alpha()]
309
310 w=self.tree.get_object("bg_color")
311 color=w.get_color()
312 global_vars["menu_bgcolor"]=[color.red,color.green,color.blue,w.get_alpha()]
313
314 align=0 # top
315 w=self.tree.get_object("menumiddle")
316 if w.get_active():
317 align=2 # middle
318 else:
319 w=self.tree.get_object("menubottom")
320 if w.get_active():
321 align=1 # bottom
322 global_vars["menu_alignment"]=align
323
324 halign=0 # left
325 w=self.tree.get_object("menucenter")
326 if w.get_active():
327 halign=2 # middle
328 else:
329 w=self.tree.get_object("menuright")
330 if w.get_active():
331 halign=1 # right
332 global_vars["menu_halignment"]=halign
333
334 w=self.tree.get_object("domenu")
335 global_vars["do_menu"]=w.get_active()
336
337 w=self.tree.get_object("menu_title_text")
338 global_vars["menu_title_text"]=w.get_text()
339
340 w=self.tree.get_object("menu_title_color")
341 color=w.get_color()
342 global_vars["menu_title_color"]=[color.red,color.green,color.blue,w.get_alpha()]
343
344 w=self.tree.get_object("menu_title_shadow")
345 color=w.get_color()
346 global_vars["menu_title_shadow"]=[color.red,color.green,color.blue,w.get_alpha()]
347
348 w=self.tree.get_object("menu_title_font")
349 global_vars["menu_title_fontname"]=w.get_font_name()
350
26cc636 @rastersoft Now allows to specify the margins for the menu system
authored
351 w=self.tree.get_object("margin_top_adj")
352 global_vars["menu_top_margin"]=w.get_value()/100.0
353 w=self.tree.get_object("margin_bottom_adj")
354 global_vars["menu_bottom_margin"]=w.get_value()/100.0
355 w=self.tree.get_object("margin_left_adj")
356 global_vars["menu_left_margin"]=w.get_value()/100.0
357 w=self.tree.get_object("margin_right_adj")
358 global_vars["menu_right_margin"]=w.get_value()/100.0
359
5748b02 First public version in GITHUB repository
Sergio Costas authored
360 # repaint the used size
361 self.callback()
362
363
364 class menu_preview:
365
366 def menu_preview_expose(self,widget,event):
367
368 """ Callback to repaint the menu preview window when it
369 sends the EXPOSE event """
370
371 if self.menu_preview==None:
372 return
373 cr=self.menu_preview.window.cairo_create()
374 cr.set_source_surface(self.sf)
375 cr.paint()
376
377
378 def __init__(self,gladefile,structure,global_vars):
379
380 """ Shows a window with a preview of the disc menu """
381
382 self.menu_preview=None
383 if global_vars["PAL"]:
384 newtree=devede_other.create_tree(self,"wmenu_preview_pal",gladefile)
385 window=newtree.get_object("wmenu_preview_pal")
386 self.menu_preview=newtree.get_object("preview_draw_pal")
387 else:
388 newtree=devede_other.create_tree(self,"wmenu_preview_ntsc",gladefile)
389 window=newtree.get_object("wmenu_preview_ntsc")
390 self.menu_preview=newtree.get_object("preview_draw_ntsc")
391 print self.menu_preview
392
393 if global_vars.has_key("install_path")==False:
394 global_vars["install_path"]=None
395 if global_vars.has_key("path")==False:
396 global_vars["path"]=""
397 if global_vars.has_key("menu_sound")==False:
398 global_vars["menu_sound"]=""
399 if global_vars.has_key("menu_sound_duration")==False:
400 global_vars["menu_sound_duration"]=1
401 clase=devede_xml_menu.xml_files(None,None,None,structure,global_vars,"","")
bd83e8c @rastersoft FFMpeg support
authored
402 self.sf=clase.create_menu_bg(0,0,0,True)
5748b02 First public version in GITHUB repository
Sergio Costas authored
403
404 if self.sf==None:
405 devede_dialogs.show_error(gladefile,_("Can't find the menu background.\nCheck the menu options."))
406 else:
407 window.show()
408 window.run()
409 window.hide()
410 window.destroy()
411 window=None
Something went wrong with that request. Please try again.