~ubuntu-branches/ubuntu/natty/phatch/natty

« back to all changes in this revision

Viewing changes to tests/generate_blender_previews.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2009-09-25 23:22:12 UTC
  • mfrom: (1.1.6 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090925232212-tpdypfah7cupooz5
Tags: 0.2.1-4
Add mlocate as an alternative dependency to locate (Closes: #548251)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# Phatch - Photo Batch Processor
 
5
# Copyright (C) 2009 Juho Vepsäläinen, www.stani.be
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program.  If not, see http://www.gnu.org/licenses/
 
19
#
 
20
# Phatch recommends SPE (http://pythonide.stani.be) for editing python files.
 
21
#
 
22
# Follows PEP8
 
23
from optparse import OptionParser
 
24
from preview import Preview, PreviewGenerator
 
25
from test_actions import system_path
 
26
 
 
27
 
 
28
class BlenderPreviewGenerator(PreviewGenerator):
 
29
    action = 'blender'
 
30
 
 
31
    def __init__(self, preview_object):
 
32
        if preview_object:
 
33
            self.preview_objects = (preview_object, )
 
34
        else:
 
35
            # FIXME: should introspect this properly from existing objects!
 
36
            self.preview_objects = ('Book', 'Box', 'Can', 'Cd', 'Lcd',
 
37
                'Sphere')
 
38
 
 
39
    def generate(self):
 
40
        for preview_object in self.preview_objects:
 
41
            options = self.options
 
42
            options['Object'] = [preview_object]
 
43
            options['Render Width'] = ['128px']
 
44
            options['Render Height'] = ['128px']
 
45
 
 
46
            output_path = self.get_output_path(preview_object)
 
47
 
 
48
            blender_preview = self.previewer(self.action, options, output_path)
 
49
            blender_preview.execute()
 
50
 
 
51
 
 
52
class ObjectPreview(Preview):
 
53
 
 
54
    def get_preview_filename(self, name, choice):
 
55
        return choice['Object'].lower()
 
56
 
 
57
 
 
58
class ObjectPreviewGenerator(BlenderPreviewGenerator):
 
59
    previewer = ObjectPreview
 
60
    option_name = 'object'
 
61
 
 
62
    def get_output_path(self, preview_object):
 
63
        return system_path(self.base_path + self.option_name)
 
64
 
 
65
 
 
66
class RotationPreview(Preview):
 
67
 
 
68
    def get_preview_filename(self, name, choice):
 
69
        hori_rot = choice['Horizontal Rotation']
 
70
        vert_rot = choice['Vertical Rotation']
 
71
 
 
72
        return 'hori_' + str(hori_rot) + '_vert_' + str(vert_rot)
 
73
 
 
74
 
 
75
class RotationPreviewGenerator(BlenderPreviewGenerator):
 
76
    previewer = RotationPreview
 
77
    option_name = 'rotation'
 
78
    options = {
 
79
        'Horizontal Rotation': [-60, -30, 0, 30, 60],
 
80
        'Vertical Rotation': [0, 30, 60],
 
81
    }
 
82
 
 
83
    def get_output_path(self, preview_object):
 
84
        return system_path(self.base_path + self.option_name + '/' +
 
85
                preview_object.lower())
 
86
 
 
87
 
 
88
class BlenderPreviewApp(OptionParser):
 
89
 
 
90
    def __init__(self):
 
91
        self.option_parser = OptionParser()
 
92
 
 
93
        self.option_parser.add_option('-b', '--object', default='',
 
94
            help='Object for which to render previews. If no object is '\
 
95
            'provided it generates previews for all objects automatically.')
 
96
        self.option_parser.add_option('-o', '--objectpreview',
 
97
            action='store_false', help="Don't generate object previews.")
 
98
        self.option_parser.add_option('-r', '--rotationpreview',
 
99
            action='store_false', help="Don't generate rotation previews.")
 
100
 
 
101
    def run(self):
 
102
        options, args = self.option_parser.parse_args()
 
103
        blender_ob = options.object
 
104
 
 
105
        if options.objectpreview is None:
 
106
            object_preview_generator = ObjectPreviewGenerator(blender_ob)
 
107
            object_preview_generator.generate()
 
108
 
 
109
        if options.rotationpreview is None:
 
110
            rotation_preview_generator = RotationPreviewGenerator(blender_ob)
 
111
            rotation_preview_generator.generate()
 
112
 
 
113
 
 
114
if __name__ == '__main__':
 
115
    blender_preview = BlenderPreviewApp()
 
116
    blender_preview.run()