| 1 |
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas) |
| 2 |
# |
| 3 |
# This file is part of DeVeDe-NG |
| 4 |
# |
| 5 |
# DeVeDe-NG is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 3 |
| 7 |
# as published by the Free Software Foundation. |
| 8 |
# |
| 9 |
# DeVeDe-NG is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 16 |
|
| 17 |
import cairo |
| 18 |
from gi.repository import Gtk, Gdk, GdkPixbuf |
| 19 |
import os |
| 20 |
import devedeng.configuration_data |
| 21 |
import devedeng.interface_manager |
| 22 |
import devedeng.message |
| 23 |
import devedeng.mux_dvd_menu |
| 24 |
|
| 25 |
|
| 26 |
class dvd_menu(devedeng.interface_manager.interface_manager): |
| 27 |
|
| 28 |
def __init__(self): |
| 29 |
|
| 30 |
self.entry_vertical_margin = 2.0 |
| 31 |
self.entry_separation = 2.0 |
| 32 |
|
| 33 |
devedeng.interface_manager.interface_manager.__init__(self) |
| 34 |
self.config = devedeng.configuration_data.configuration.get_config() |
| 35 |
|
| 36 |
self.default_background = os.path.join(self.config.pic_path, "backgrounds", "default_bg.png") |
| 37 |
self.default_sound = os.path.join(self.config.pic_path, "silence.ogg") |
| 38 |
|
| 39 |
self.add_colorbutton("title_color", (0, 0, 0, 1), self.update_preview) |
| 40 |
self.add_colorbutton("title_shadow", (0, 0, 0, 0), self.update_preview) |
| 41 |
self.add_colorbutton("unselected_color", (1, 1, 1, 1), self.update_preview) |
| 42 |
self.add_colorbutton("shadow_color", (0, 0, 0, 0), self.update_preview) |
| 43 |
self.add_colorbutton("selected_color", (0, 1, 1, 1), self.update_preview) |
| 44 |
self.add_colorbutton("background_color", (0, 0, 0, 0.75), self.update_preview) |
| 45 |
self.add_colorbutton("separator_color", (0, 0, 0, 1), self.update_preview) |
| 46 |
self.add_colorbutton("separator_shadow", (0, 0, 0, 0), self.update_preview) |
| 47 |
self.add_colorbutton("separator_background", (1, 1, 1, 0.75), self.update_preview) |
| 48 |
|
| 49 |
self.add_text("title_text", None, self.update_preview) |
| 50 |
|
| 51 |
self.add_text("playall_text", _("Play all"), self.update_preview) |
| 52 |
|
| 53 |
self.add_group("position_horizontal", ["left", "center", "right"], "center", self.update_preview) |
| 54 |
self.add_group("at_startup", ["menu_show_at_startup", "play_first_title_at_startup"], "menu_show_at_startup") |
| 55 |
self.add_group("menu_aspect_ratio", ["menu_aspect_4_3", "menu_aspect_16_9"], "menu_aspect_4_3", self.on_menu_aspect_changed) |
| 56 |
self.add_toggle("play_all_c", False, self.update_preview) |
| 57 |
|
| 58 |
self.add_integer_adjustment("sound_length", 30) |
| 59 |
|
| 60 |
self.add_dualtoggle("audio_mp2", "audio_ac3", True) |
| 61 |
|
| 62 |
self.add_float_adjustment("margin_left", 10.0, self.update_preview) |
| 63 |
self.add_float_adjustment("margin_top", 12.5, self.update_preview) |
| 64 |
self.add_float_adjustment("margin_right", 10.0, self.update_preview) |
| 65 |
self.add_float_adjustment("margin_bottom", 12.5, self.update_preview) |
| 66 |
self.add_float_adjustment("title_horizontal", 0.0, self.update_preview) |
| 67 |
self.add_float_adjustment("title_vertical", 10.0, self.update_preview) |
| 68 |
|
| 69 |
self.add_fontbutton("title_font", "Sans 28", self.update_preview) |
| 70 |
self.add_fontbutton("entry_font", "Sans 28", self.update_preview) |
| 71 |
|
| 72 |
self.add_filebutton("background_picture", self.default_background, self.update_preview) |
| 73 |
self.add_filebutton("background_music", self.default_sound, self.update_music) |
| 74 |
|
| 75 |
self.cached_menu_font = None |
| 76 |
self.cached_menu_size = 0 |
| 77 |
self.video_rate = 2500 |
| 78 |
self.audio_rate = 224 |
| 79 |
|
| 80 |
def on_help_clicked(self, b): |
| 81 |
help_file = devedeng.help.help("menu.html") |
| 82 |
|
| 83 |
def get_estimated_size(self): |
| 84 |
estimated_size = ((self.video_rate + self.audio_rate) * self.sound_length) / 8 |
| 85 |
return estimated_size |
| 86 |
|
| 87 |
def update_music(self, b=None): |
| 88 |
self.store_ui(self.builder) |
| 89 |
cv = devedeng.converter.converter.get_converter() |
| 90 |
film_analizer = (cv.get_film_analizer())() |
| 91 |
film_analizer.get_film_data(self.background_music) |
| 92 |
if (film_analizer.video_streams != 0): |
| 93 |
devedeng.message.message_window(_("The selected file is a video, not an audio file"), _("Error")) |
| 94 |
self.on_no_sound_clicked(None) |
| 95 |
elif (film_analizer.audio_streams == 0): |
| 96 |
devedeng.message.message_window(_("The selected file is not an audio file"), _("Error")) |
| 97 |
self.on_no_sound_clicked(None) |
| 98 |
else: |
| 99 |
self.sound_length = film_analizer.original_length |
| 100 |
|
| 101 |
def update_preview(self, b=None): |
| 102 |
self.store_ui(self.builder) |
| 103 |
self.sf = None # force to repaint the menu |
| 104 |
self.wdrawing_area.queue_draw() |
| 105 |
|
| 106 |
def on_default_background_clicked(self, b): |
| 107 |
self.background_picture = self.default_background |
| 108 |
self.update_ui(self.builder) |
| 109 |
self.update_preview() |
| 110 |
|
| 111 |
def on_no_sound_clicked(self, b): |
| 112 |
self.background_music = self.default_sound |
| 113 |
self.sound_length = 30 |
| 114 |
self.update_ui(self.builder) |
| 115 |
|
| 116 |
def show_configuration(self, file_list): |
| 117 |
self.builder = Gtk.Builder() |
| 118 |
self.builder.set_translation_domain(self.config.gettext_domain) |
| 119 |
self.file_list = file_list |
| 120 |
|
| 121 |
self.refresh_static_data() |
| 122 |
|
| 123 |
self.builder.add_from_file(os.path.join(self.config.glade, "wmenu.ui")) |
| 124 |
self.builder.connect_signals(self) |
| 125 |
|
| 126 |
self.wframe_preview = self.builder.get_object("frame_preview") |
| 127 |
self.wframe_preview_controls = self.builder.get_object( |
| 128 |
"frame_preview_controls") |
| 129 |
self.wmenu = self.builder.get_object("menu") |
| 130 |
self.wpreview_menu = self.builder.get_object("preview_menu") |
| 131 |
self.wdrawing_area = self.builder.get_object("drawingarea_preview") |
| 132 |
self.wcurrent_page = self.builder.get_object("current_page") |
| 133 |
self.wshow_as_selected = self.builder.get_object("show_as_selected") |
| 134 |
self.wshow_as_selected.connect("toggled", self.update_preview) |
| 135 |
|
| 136 |
self.wbackground_picture = self.builder.get_object( |
| 137 |
"background_picture") |
| 138 |
self.wbackground_music = self.builder.get_object("background_music") |
| 139 |
|
| 140 |
file_filter_pictures = Gtk.FileFilter() |
| 141 |
file_filter_pictures.set_name(_("Picture files")) |
| 142 |
|
| 143 |
file_filter_pictures.add_mime_type("image/*") |
| 144 |
|
| 145 |
file_filter_all = Gtk.FileFilter() |
| 146 |
file_filter_all.set_name(_("All files")) |
| 147 |
file_filter_all.add_pattern("*") |
| 148 |
|
| 149 |
self.wbackground_picture.add_filter(file_filter_pictures) |
| 150 |
self.wbackground_picture.add_filter(file_filter_all) |
| 151 |
|
| 152 |
file_filter_music = Gtk.FileFilter() |
| 153 |
file_filter_music.set_name(_("Sound files")) |
| 154 |
|
| 155 |
file_filter_music.add_mime_type("audio/*") |
| 156 |
|
| 157 |
file_filter_all = Gtk.FileFilter() |
| 158 |
file_filter_all.set_name(_("All files")) |
| 159 |
file_filter_all.add_pattern("*") |
| 160 |
|
| 161 |
self.wbackground_music.add_filter(file_filter_music) |
| 162 |
self.wbackground_music.add_filter(file_filter_all) |
| 163 |
|
| 164 |
self.wmenu.show_all() |
| 165 |
|
| 166 |
self.pages = 0 |
| 167 |
self.update_ui(self.builder) |
| 168 |
self.save_ui() |
| 169 |
|
| 170 |
def on_accept_clicked(self, b): |
| 171 |
self.store_ui(self.builder) |
| 172 |
self.wmenu.destroy() |
| 173 |
|
| 174 |
def on_cancel_clicked(self, b): |
| 175 |
self.restore_ui() |
| 176 |
self.wmenu.destroy() |
| 177 |
|
| 178 |
def get_font_params(self, font_name): |
| 179 |
font_elements = font_name.split(" ") |
| 180 |
|
| 181 |
if (len(font_elements)) < 2: |
| 182 |
fontname = "Sans" |
| 183 |
fontstyle = cairo.FONT_WEIGHT_NORMAL |
| 184 |
fontslant = cairo.FONT_SLANT_NORMAL |
| 185 |
fontsize = 12 |
| 186 |
else: |
| 187 |
fontname = "" |
| 188 |
fontstyle = cairo.FONT_WEIGHT_NORMAL |
| 189 |
fontslant = cairo.FONT_SLANT_NORMAL |
| 190 |
for counter2 in range(len(font_elements) - 1): |
| 191 |
if font_elements[counter2] == "Bold": |
| 192 |
fontstyle = cairo.FONT_WEIGHT_BOLD |
| 193 |
elif font_elements[counter2] == "Italic": |
| 194 |
fontslant = cairo.FONT_SLANT_ITALIC |
| 195 |
else: |
| 196 |
fontname += " " + font_elements[counter2] |
| 197 |
if fontname != "": |
| 198 |
fontname = fontname[1:] |
| 199 |
else: |
| 200 |
fontname = "Sans" |
| 201 |
|
| 202 |
try: |
| 203 |
fontsize = float(font_elements[-1]) |
| 204 |
except: |
| 205 |
fontsize = 12 |
| 206 |
|
| 207 |
return fontname, fontstyle, fontslant, fontsize |
| 208 |
|
| 209 |
def paint_arrow(self, xl, xr, y, arrow_type, left): |
| 210 |
|
| 211 |
if arrow_type == "menu_entry": |
| 212 |
fgcolor = self.unselected_color |
| 213 |
elif arrow_type == "menu_entry_selected": |
| 214 |
fgcolor = self.selected_color |
| 215 |
elif arrow_type == "menu_entry_activated": |
| 216 |
fgcolor = (1.0 - self.selected_color[0], 1.0 - self.selected_color[ |
| 217 |
1], 1.0 - self.selected_color[2], self.selected_color[3]) |
| 218 |
else: |
| 219 |
return |
| 220 |
|
| 221 |
fo = cairo.FontOptions() |
| 222 |
fo.set_antialias(cairo.ANTIALIAS_NONE) |
| 223 |
self.cr.set_font_options(fo) |
| 224 |
self.cr.set_antialias(cairo.ANTIALIAS_NONE) |
| 225 |
|
| 226 |
x = (xl + xr) / 2.0 |
| 227 |
h = (self.cached_menu_size / 2.0) - 1.0 |
| 228 |
self.cr.set_source_rgba(fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]) |
| 229 |
self.cr.move_to(x, y - h) |
| 230 |
if (left): |
| 231 |
self.cr.line_to(x - self.cached_menu_size + 2, y) |
| 232 |
else: |
| 233 |
self.cr.line_to(x + self.cached_menu_size - 2, y) |
| 234 |
self.cr.line_to(x, y + h) |
| 235 |
self.cr.line_to(x, y - h) |
| 236 |
self.cr.fill() |
| 237 |
|
| 238 |
fo = cairo.FontOptions() |
| 239 |
fo.set_antialias(cairo.ANTIALIAS_DEFAULT) |
| 240 |
self.cr.set_font_options(fo) |
| 241 |
self.cr.set_antialias(cairo.ANTIALIAS_DEFAULT) |
| 242 |
|
| 243 |
def write_text(self, text, text_type, xl, xr, y, alignment): |
| 244 |
""" Renders a line of text, in the rectangle delimited by xl,y-h;xr,y+h, with the specified alignment """ |
| 245 |
|
| 246 |
if text is None: |
| 247 |
return |
| 248 |
if text_type == "title": |
| 249 |
fgcolor = self.title_color |
| 250 |
bgcolor = self.title_shadow |
| 251 |
hard_borders = False |
| 252 |
font = self.title_font |
| 253 |
elif text_type == "menu_separator": |
| 254 |
fgcolor = self.separator_color |
| 255 |
bgcolor = self.separator_shadow |
| 256 |
hard_borders = False |
| 257 |
font = self.entry_font |
| 258 |
elif text_type == "menu_entry": |
| 259 |
fgcolor = self.unselected_color |
| 260 |
bgcolor = self.shadow_color |
| 261 |
hard_borders = True |
| 262 |
font = self.entry_font |
| 263 |
elif text_type == "menu_entry_selected": |
| 264 |
fgcolor = self.selected_color |
| 265 |
bgcolor = None |
| 266 |
hard_borders = True |
| 267 |
font = self.entry_font |
| 268 |
elif text_type == "menu_entry_activated": |
| 269 |
fgcolor = (1.0 - self.selected_color[0], 1.0 - self.selected_color[1], 1.0 - self.selected_color[2], self.selected_color[3]) |
| 270 |
bgcolor = None |
| 271 |
hard_borders = True |
| 272 |
font = self.entry_font |
| 273 |
else: |
| 274 |
return |
| 275 |
|
| 276 |
if hard_borders: |
| 277 |
fo = cairo.FontOptions() |
| 278 |
fo.set_antialias(cairo.ANTIALIAS_NONE) |
| 279 |
self.cr.set_font_options(fo) |
| 280 |
self.cr.set_antialias(cairo.ANTIALIAS_NONE) |
| 281 |
|
| 282 |
(fontname, fontstyle, fontslant, fontsize) = self.get_font_params(font) |
| 283 |
self.cr.select_font_face(fontname, fontslant, fontstyle) |
| 284 |
self.cr.set_font_size(fontsize) |
| 285 |
extents = self.cr.text_extents(text) |
| 286 |
|
| 287 |
if alignment == "left": |
| 288 |
x = xl |
| 289 |
elif alignment == "right": |
| 290 |
x = xr - extents[2] |
| 291 |
elif alignment == "center": |
| 292 |
x = ((xl + xr) / 2.0) - (extents[2] / 2.0) |
| 293 |
|
| 294 |
if (bgcolor is not None): |
| 295 |
self.cr.move_to(x + extents[0] + 2, y - |
| 296 |
(extents[3] / 2.0) - extents[1] + 2) |
| 297 |
self.cr.set_source_rgba( |
| 298 |
bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3]) |
| 299 |
self.cr.show_text(text) |
| 300 |
|
| 301 |
self.cr.move_to(x + extents[0], y - (extents[3] / 2.0) - extents[1]) |
| 302 |
self.cr.set_source_rgba(fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]) |
| 303 |
self.cr.show_text(text) |
| 304 |
|
| 305 |
if hard_borders: |
| 306 |
fo = cairo.FontOptions() |
| 307 |
fo.set_antialias(cairo.ANTIALIAS_DEFAULT) |
| 308 |
self.cr.set_font_options(fo) |
| 309 |
self.cr.set_antialias(cairo.ANTIALIAS_DEFAULT) |
| 310 |
|
| 311 |
def refresh_static_data(self): |
| 312 |
""" This method sets data that can't be changed from the dvd settings window. |
| 313 |
It must be called before painting a menu """ |
| 314 |
|
| 315 |
if self.config.PAL: |
| 316 |
self.y = 576.0 |
| 317 |
else: |
| 318 |
self.y = 480.0 |
| 319 |
|
| 320 |
self.title_list = [] |
| 321 |
counter = 0 |
| 322 |
for element in self.file_list: |
| 323 |
if element.element_type == "file_movie": |
| 324 |
if element.show_in_menu: |
| 325 |
self.title_list.append((element, counter)) |
| 326 |
counter += 1 |
| 327 |
else: |
| 328 |
self.title_list.append((element, None)) |
| 329 |
|
| 330 |
self.sf = None |
| 331 |
self.current_shown_page = 0 |
| 332 |
self.wcurrent_page = None |
| 333 |
|
| 334 |
def paint_menu(self, paint_background, paint_selected, paint_activated, page_number): |
| 335 |
coordinates = [] |
| 336 |
|
| 337 |
if self.sf is None: |
| 338 |
if self.to_png: |
| 339 |
self.sf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 720, int(self.y)) |
| 340 |
else: |
| 341 |
self.sf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 720, 540) |
| 342 |
self.cr = cairo.Context(self.sf) |
| 343 |
if not self.to_png: |
| 344 |
if self.menu_aspect_ratio == "menu_aspect_16_9": |
| 345 |
self.cr.scale(1.0,405.0 / self.y) |
| 346 |
else: |
| 347 |
self.cr.scale(1.0,540.0 / self.y) |
| 348 |
|
| 349 |
if self.cached_menu_font != self.entry_font: |
| 350 |
# memorize the font sizes |
| 351 |
(fontname, fontstyle, fontslant, fontsize) = self.get_font_params(self.entry_font) |
| 352 |
self.cr.select_font_face(fontname, fontslant, fontstyle) |
| 353 |
self.cr.set_font_size(fontsize) |
| 354 |
extents = self.cr.font_extents() |
| 355 |
self.cached_menu_size = extents[2] |
| 356 |
self.cached_menu_font = self.entry_font |
| 357 |
|
| 358 |
if paint_background: |
| 359 |
extra_pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.background_picture) |
| 360 |
extra_x = float(extra_pixbuf.get_width()) |
| 361 |
extra_y = float(extra_pixbuf.get_height()) |
| 362 |
|
| 363 |
self.cr.save() |
| 364 |
self.cr.scale(720.0 / extra_x, self.y / extra_y) |
| 365 |
|
| 366 |
surface = Gdk.cairo_surface_create_from_pixbuf(extra_pixbuf, 1, None) |
| 367 |
self.cr.set_source_surface(surface, 0, 0) |
| 368 |
self.cr.paint() |
| 369 |
self.cr.restore() |
| 370 |
hmargin = self.title_horizontal * 720.0 / 100.0 |
| 371 |
self.write_text(self.title_text, "title", 0 + hmargin, 720 + hmargin, self.title_vertical * self.y / 100.0, "center") |
| 372 |
|
| 373 |
top_margin_p = self.y * self.margin_top / 100.0 |
| 374 |
bottom_margin_p = self.y * self.margin_bottom / 100.0 |
| 375 |
left_margin_p = 720.0 * self.margin_left / 100.0 |
| 376 |
right_margin_p = 720.0 * self.margin_right / 100.0 |
| 377 |
|
| 378 |
entry_height = self.cached_menu_size + self.entry_vertical_margin * 2.0 + self.entry_separation |
| 379 |
entries_per_page = int((self.y - top_margin_p - bottom_margin_p) / entry_height) |
| 380 |
if (self.play_all_c): |
| 381 |
entries_per_page -= 1 |
| 382 |
n_entries = len(self.title_list) |
| 383 |
|
| 384 |
paint_arrows = False |
| 385 |
if n_entries > entries_per_page: |
| 386 |
paint_arrows = True |
| 387 |
else: |
| 388 |
for element in self.file_list: |
| 389 |
if ((element.element_type == "separator") and element.page_jump): |
| 390 |
paint_arrows = True |
| 391 |
break |
| 392 |
if paint_arrows: |
| 393 |
entries_per_page -= 1 |
| 394 |
self.pages = 1 |
| 395 |
n_entries = 1 |
| 396 |
self.page_list = [0] |
| 397 |
entry = 0 |
| 398 |
for element in self.file_list: |
| 399 |
if ((element.element_type == "separator") and element.page_jump) or (n_entries > entries_per_page): |
| 400 |
self.pages += 1 |
| 401 |
n_entries = 1 |
| 402 |
self.page_list.append(entry) |
| 403 |
entry += 1 |
| 404 |
n_entries += 1 |
| 405 |
if (page_number > self.pages) and (page_number > 0): |
| 406 |
page_number = self.pages - 1 |
| 407 |
|
| 408 |
if self.wcurrent_page is not None: |
| 409 |
self.wcurrent_page.set_text(_("Page {0} of {1}").format(page_number + 1, self.pages)) |
| 410 |
xl = left_margin_p |
| 411 |
xr = 720.0 - right_margin_p |
| 412 |
y = top_margin_p + entry_height / 2.0 |
| 413 |
height = (self.cached_menu_size + self.entry_vertical_margin) / 2.0 |
| 414 |
|
| 415 |
if (self.play_all_c): |
| 416 |
coordinates.append([xl, y - height, xr, y + height, _("Play_all")]) |
| 417 |
if self.playall_text == "": |
| 418 |
playalltext = _("Play all") |
| 419 |
else: |
| 420 |
playalltext = self.playall_text |
| 421 |
if paint_background: |
| 422 |
self.paint_base(xl, xr, y, 0, self.background_color) |
| 423 |
self.write_text(playalltext, "menu_entry", xl, |
| 424 |
xr, y, self.position_horizontal) |
| 425 |
if paint_selected: |
| 426 |
self.write_text(playalltext, "menu_entry_selected", |
| 427 |
xl, xr, y, self.position_horizontal) |
| 428 |
if paint_activated: |
| 429 |
self.write_text(playalltext, "menu_entry_activated", |
| 430 |
xl, xr, y, self.position_horizontal) |
| 431 |
y += entry_height |
| 432 |
|
| 433 |
for entry_position in range(entries_per_page): |
| 434 |
entry_number = self.page_list[page_number] + entry_position |
| 435 |
if entry_number >= len(self.title_list): |
| 436 |
break |
| 437 |
entry = self.title_list[entry_number] |
| 438 |
if (entry_position != 0) and (entry[0].element_type == "separator") and (entry[0].page_jump): |
| 439 |
break |
| 440 |
if entry[0].element_type == "file_movie": |
| 441 |
text = entry[0].title_name |
| 442 |
is_movie = True |
| 443 |
coordinates.append([xl, y - height, xr, y + height, "entry"]) |
| 444 |
else: |
| 445 |
text = entry[0].separator_name |
| 446 |
is_movie = False |
| 447 |
if paint_background: |
| 448 |
self.paint_base(xl, xr, y, 0, self.background_color if is_movie else self.separator_background) |
| 449 |
self.write_text(text, "menu_entry" if is_movie else "menu_separator", xl, xr, y, self.position_horizontal) |
| 450 |
if paint_selected and is_movie: |
| 451 |
self.write_text(text, "menu_entry_selected", xl, xr, y, self.position_horizontal) |
| 452 |
if paint_activated and is_movie: |
| 453 |
self.write_text(text, "menu_entry_activated", xl, xr, y, self.position_horizontal) |
| 454 |
y += entry_height |
| 455 |
|
| 456 |
if paint_arrows: |
| 457 |
if page_number == 0: |
| 458 |
coordinates.append([xl, y - height, xr, y + height, "right"]) |
| 459 |
if paint_background: |
| 460 |
self.paint_base(xl, xr, y, 0, self.background_color) |
| 461 |
self.paint_arrow(xl, xr, y, "menu_entry", False) |
| 462 |
if paint_selected: |
| 463 |
self.paint_arrow(xl, xr, y, "menu_entry_selected", False) |
| 464 |
if paint_activated: |
| 465 |
self.paint_arrow(xl, xr, y, "menu_entry_activated", False) |
| 466 |
elif page_number == (self.pages - 1): |
| 467 |
coordinates.append([xl, y - height, xr, y + height, "left"]) |
| 468 |
if paint_background: |
| 469 |
self.paint_base(xl, xr, y, 0, self.background_color) |
| 470 |
self.paint_arrow(xl, xr, y, "menu_entry", True) |
| 471 |
if paint_selected: |
| 472 |
self.paint_arrow(xl, xr, y, "menu_entry_selected", True) |
| 473 |
if paint_activated: |
| 474 |
self.paint_arrow(xl, xr, y, "menu_entry_activated", True) |
| 475 |
else: |
| 476 |
med = (xl + xr) / 2.0 |
| 477 |
coordinates.append([xl, y - height, med, y + height, "left"]) |
| 478 |
coordinates.append([med, y - height, xr, y + height, "right"]) |
| 479 |
if paint_background: |
| 480 |
self.paint_base(xl, xr, y, 1, self.background_color) |
| 481 |
self.paint_base(xl, xr, y, 2, self.background_color) |
| 482 |
self.paint_arrow(med, xr, y, "menu_entry", False) |
| 483 |
self.paint_arrow(xl, med, y, "menu_entry", True) |
| 484 |
if paint_selected: |
| 485 |
self.paint_arrow(med, xr, y, "menu_entry_selected", False) |
| 486 |
self.paint_arrow(xl, med, y, "menu_entry_selected", True) |
| 487 |
if paint_activated: |
| 488 |
self.paint_arrow(med, xr, y, "menu_entry_activated", False) |
| 489 |
self.paint_arrow(xl, med, y, "menu_entry_activated", True) |
| 490 |
return coordinates |
| 491 |
|
| 492 |
def paint_base(self, xl, xr, y, type_b, color): |
| 493 |
|
| 494 |
height = self.cached_menu_size + self.entry_vertical_margin |
| 495 |
radius = (height) / 2.0 |
| 496 |
y -= radius |
| 497 |
|
| 498 |
if (type_b == 1): # half button, at left |
| 499 |
xr = (xl + xr) / 2.0 |
| 500 |
xr -= radius |
| 501 |
elif (type_b == 2): # half button, at right |
| 502 |
xl = (xl + xr) / 2.0 |
| 503 |
xl += radius |
| 504 |
|
| 505 |
self.cr.set_source_rgba(color[0], color[1], color[2], color[3]) |
| 506 |
self.cr.move_to(xl, y) |
| 507 |
self.cr.line_to(xr, y) |
| 508 |
self.cr.curve_to(xr + radius, y, xr + radius, |
| 509 |
y + height, xr, y + height) |
| 510 |
self.cr.line_to(xl, y + height) |
| 511 |
self.cr.curve_to(xl - radius, y + height, xl - radius, y, xl, y) |
| 512 |
self.cr.fill() |
| 513 |
|
| 514 |
def on_next_page_clicked(self, b): |
| 515 |
|
| 516 |
self.current_shown_page += 1 |
| 517 |
if (self.current_shown_page == self.pages): |
| 518 |
self.current_shown_page -= 1 |
| 519 |
self.update_preview() |
| 520 |
|
| 521 |
def on_previous_page_clicked(self, b): |
| 522 |
|
| 523 |
self.current_shown_page -= 1 |
| 524 |
if (self.current_shown_page < 0): |
| 525 |
self.current_shown_page = 0 |
| 526 |
self.update_preview() |
| 527 |
|
| 528 |
def on_menu_aspect_changed(self, b=None): |
| 529 |
self.update_preview() |
| 530 |
|
| 531 |
def on_drawingarea_preview_draw(self, widget, cr): |
| 532 |
""" Callback to repaint the menu preview window when it |
| 533 |
sends the EXPOSE event """ |
| 534 |
|
| 535 |
if (self.sf is None): |
| 536 |
self.to_png = False |
| 537 |
self.paint_menu(True, self.wshow_as_selected.get_active(), False, self.current_shown_page) |
| 538 |
if (self.current_shown_page >= self.pages): |
| 539 |
self.current_shown_page = self.pages |
| 540 |
|
| 541 |
cr.set_source_surface(self.sf) |
| 542 |
cr.paint() |
| 543 |
|
| 544 |
def create_menu_stream(self, path, n_page, coordinates): |
| 545 |
""" Creates the menu XML file """ |
| 546 |
|
| 547 |
file_name = os.path.join(path, "menu_" + str(n_page) + ".xml") |
| 548 |
entry_data = {} |
| 549 |
entry_data["chapters"] = [] |
| 550 |
entry_data["right"] = None |
| 551 |
entry_data["left"] = None |
| 552 |
|
| 553 |
xml_file = open(file_name, "w") |
| 554 |
# transparent="000000"') |
| 555 |
xml_file.write( |
| 556 |
'<subpictures>\n\t<stream>\n\t\t<spu force="yes" start="00:00:00.00"') |
| 557 |
xml_file.write(' image="' + os.path.join(path, "menu_" + str(n_page) + '_unselected_bg.png"')) |
| 558 |
xml_file.write(' highlight="' + os.path.join(path, "menu_" + str(n_page) + '_selected_bg.png"')) |
| 559 |
xml_file.write(' select="' + os.path.join(path, "menu_" + str(n_page) + '_active_bg.png"')) |
| 560 |
xml_file.write(' >\n') |
| 561 |
n_elements = 0 |
| 562 |
has_next = False |
| 563 |
has_previous = False |
| 564 |
|
| 565 |
for e in coordinates: |
| 566 |
if (e[4] == "entry"): |
| 567 |
n_elements += 1 |
| 568 |
continue |
| 569 |
if (e[4] == "right"): |
| 570 |
has_next = True |
| 571 |
continue |
| 572 |
if (e[4] == "left"): |
| 573 |
has_previous = True |
| 574 |
continue |
| 575 |
|
| 576 |
counter = 0 |
| 577 |
for element in coordinates: |
| 578 |
xl = int(element[0]) |
| 579 |
yt = int(element[1]) |
| 580 |
xr = int(element[2]) |
| 581 |
yb = int(element[3]) |
| 582 |
if (xl % 2) == 1: |
| 583 |
xl += 1 |
| 584 |
if (yt % 2) == 1: |
| 585 |
yt += 1 |
| 586 |
if (xr % 2) == 1: |
| 587 |
xr -= 1 |
| 588 |
if (yb % 2) == 1: |
| 589 |
yb -= 1 |
| 590 |
|
| 591 |
if (element[4] == "left"): |
| 592 |
entry_data["left"] = "boton" + str(n_page) + "x" + str(counter) |
| 593 |
elif (element[4] == "right"): |
| 594 |
entry_data["right"] = "boton" + \ |
| 595 |
str(n_page) + "x" + str(counter) |
| 596 |
else: |
| 597 |
entry_data["chapters"].append( |
| 598 |
"boton" + str(n_page) + "x" + str(counter)) |
| 599 |
|
| 600 |
xml_file.write('\t\t\t<button name="boton' + |
| 601 |
str(n_page) + "x" + str(counter)) |
| 602 |
xml_file.write('" x0="' + str(xl) + '" y0="' + str(yt) + |
| 603 |
'" x1="' + str(xr) + '" y1="' + str(yb) + '"') |
| 604 |
if counter > 0: |
| 605 |
xml_file.write(' up="boton' + str(n_page) + "x") |
| 606 |
if counter >= n_elements: |
| 607 |
xml_file.write(str(n_elements - 1)) |
| 608 |
else: |
| 609 |
xml_file.write(str(counter - 1)) |
| 610 |
xml_file.write('"') |
| 611 |
|
| 612 |
if (counter < (n_elements - 1)) or ((counter < n_elements) and (has_next or has_previous)): |
| 613 |
xml_file.write(' down="boton' + str(n_page) + "x") |
| 614 |
xml_file.write(str(counter + 1)) |
| 615 |
xml_file.write('"') |
| 616 |
if (element[4] == "left") and (has_next): |
| 617 |
xml_file.write(' right="boton' + str(n_page) + |
| 618 |
'x' + str(counter + 1) + '"') |
| 619 |
if (element[4] == "right") and (has_previous): |
| 620 |
xml_file.write(' left="boton' + str(n_page) + |
| 621 |
'x' + str(counter - 1) + '"') |
| 622 |
xml_file.write(' > </button>\n') |
| 623 |
counter += 1 |
| 624 |
|
| 625 |
xml_file.write("</spu>\n</stream>\n</subpictures>\n") |
| 626 |
xml_file.close() |
| 627 |
|
| 628 |
return entry_data |
| 629 |
|
| 630 |
def create_dvd_menus(self, file_list, base_path): |
| 631 |
|
| 632 |
self.file_list = file_list |
| 633 |
self.refresh_static_data() |
| 634 |
cv = devedeng.converter.converter.get_converter() |
| 635 |
menu_folder = os.path.join(base_path, "menu") |
| 636 |
try: |
| 637 |
os.makedirs(menu_folder) |
| 638 |
except: |
| 639 |
pass |
| 640 |
n_page = 0 |
| 641 |
self.pages = 1 |
| 642 |
processes = [] |
| 643 |
menu_entries = [] |
| 644 |
menu_converter = cv.get_menu_converter() |
| 645 |
while n_page < self.pages: |
| 646 |
self.sf = None |
| 647 |
self.to_png = True |
| 648 |
coordinates = self.paint_menu(True, False, False, n_page) |
| 649 |
self.sf.write_to_png(os.path.join(menu_folder, "menu_" + str(n_page) + "_bg.png")) |
| 650 |
self.sf = None |
| 651 |
self.paint_menu(False, False, False, n_page) |
| 652 |
self.sf.write_to_png(os.path.join(menu_folder, "menu_" + str(n_page) + "_unselected_bg.png")) |
| 653 |
self.sf = None |
| 654 |
self.paint_menu(False, True, False, n_page) |
| 655 |
self.sf.write_to_png(os.path.join(menu_folder, "menu_" + str(n_page) + "_selected_bg.png")) |
| 656 |
self.sf = None |
| 657 |
self.paint_menu(False, False, True, n_page) |
| 658 |
self.sf.write_to_png(os.path.join(menu_folder, "menu_" + str(n_page) + "_active_bg.png")) |
| 659 |
entry_data = self.create_menu_stream(menu_folder, n_page, coordinates) |
| 660 |
converter = menu_converter() |
| 661 |
final_path = converter.create_menu_mpeg(n_page, self.background_music, self.sound_length, self.config.PAL, self.video_rate, self.audio_rate, menu_folder, self.audio_mp2, self.menu_aspect_ratio == "menu_aspect_16_9") |
| 662 |
entry_data["filename"] = final_path |
| 663 |
menu_entries.append(entry_data) |
| 664 |
# add this process without dependencies |
| 665 |
processes.append(converter) |
| 666 |
n_page += 1 |
| 667 |
|
| 668 |
return processes, menu_entries |
| 669 |
|
| 670 |
def store_menu(self): |
| 671 |
|
| 672 |
return self.serialize() |
| 673 |
|
| 674 |
def restore_menu(self, data): |
| 675 |
|
| 676 |
# check that the menu's background picture and music are there |
| 677 |
if ('background_picture' in data) and (not os.path.exists(data['background_picture'])): |
| 678 |
data['background_picture'] = self.default_background |
| 679 |
if ('background_music' in data) and (not os.path.exists(data['background_music'])): |
| 680 |
data['background_music'] = self.default_sound |
| 681 |
|
| 682 |
self.unserialize(data) |