~ubuntu-branches/ubuntu/karmic/tovid/karmic

« back to all changes in this revision

Viewing changes to src/pymakemenu

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-24 22:04:40 UTC
  • Revision ID: james.westby@ubuntu.com-20080124220440-x7cheljduf1rdgnq
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# pymakemenu
 
3
 
 
4
__doc__ = \
 
5
"""Generate an (S)VCD/DVD menu MPEG (to replace the 'makemenu' shell script).
 
6
"""
 
7
 
 
8
import sys
 
9
from libtovid.opts import Option, OptionDict
 
10
from libtovid.media import standard_media
 
11
from libtovid.template import Style, textmenu, thumbmenu
 
12
from libtovid import log
 
13
 
 
14
# Dictionary of valid options with documentation
 
15
OPTION_DEFS = [\
 
16
    Option('out', 'NAME', None,
 
17
        """Output prefix or menu name."""),
 
18
 
 
19
    Option('titles', '"TITLE"[, "TITLE"]', [],
 
20
        """Comma-separated list of quoted titles; these are the titles that
 
21
        will be displayed (and linked) from the menu."""),
 
22
 
 
23
    Option('format', 'vcd|svcd|dvd', 'dvd',
 
24
        """Generate a menu compliant with the specified disc format"""),
 
25
    Option('tvsys', 'pal|ntsc', 'ntsc',
 
26
        """Make the menu for the specified TV system"""),
 
27
    Option('background', 'IMAGE', None,
 
28
        """Use IMAGE (in most any graphic format) as a background."""),
 
29
    Option('audio', 'AUDIOFILE', None,
 
30
        """Use AUDIOFILE for background music while the menu plays."""),
 
31
    Option('font', 'FONTNAME', 'Helvetica',
 
32
        """Use FONTNAME for the menu text."""),
 
33
    Option('fontsize', 'NUM', '24',
 
34
        """Use a font size of NUM pixels."""),
 
35
    Option('align', 'west|north|east|south|center', 'northwest'),
 
36
    Option('textcolor', 'COLOR', 'white',
 
37
        """Color of menu text. COLOR may be a hexadecimal triplet (#RRGGBB or
 
38
        #RGB), or a color name from 'convert -list color."""),
 
39
    Option('highlightcolor', 'COLOR', 'red',
 
40
        """Color of menu highlights."""),
 
41
    Option('selectcolor', 'COLOR', 'green',
 
42
        """Color of menu selections."""),
 
43
 
 
44
    # Thumbnail menus and effects
 
45
    Option('thumbnails', 'FILE[, FILE ...]', [],
 
46
        """Create thumbnails of the provided list of video files, which
 
47
        should correspond to the given -titles list."""),
 
48
    Option('border', 'NUM', '0',
 
49
        """Add a border of NUM pixels around thumbnails."""),
 
50
    Option('effects', 'shadow|round|glass [, ...]', [],
 
51
        """Add the listed effects to the thumbnails.""")
 
52
]
 
53
 
 
54
 
 
55
if __name__ == '__main__':
 
56
    """Create a Menu with provided options and generate it.
 
57
    """
 
58
    options = OptionDict(OPTION_DEFS)
 
59
    # If no arguments were provided, print usage notes
 
60
    # TODO: Proper argument verification
 
61
    if len(sys.argv) < 3:
 
62
        print 'Usage: pymakemenu [options] -out NAME'
 
63
        print 'Where [options] may be any of the following:'
 
64
        print options.usage()
 
65
        print 'Please provide an output name (-out).'
 
66
        sys.exit()
 
67
    options.override(sys.argv[1:])
 
68
    # Target MediaFile
 
69
    target = standard_media(options['format'], options['tvsys'])
 
70
    target.filename = options['out']
 
71
    # Create the style
 
72
    style = Style(options['font'],
 
73
                  options['fontsize'],
 
74
                  options['textcolor'],
 
75
                  options['highlightcolor'],
 
76
                  options['selectcolor'],
 
77
                  options['align'])
 
78
    if options['thumbnails'] != []:
 
79
        menu = thumbmenu.ThumbMenu(target, options['thumbnails'],
 
80
                                   options['titles'], style)
 
81
    else:
 
82
        menu = textmenu.TextMenu(target, options['titles'], style)
 
83
    menu.generate()