Welcome to mirror list, hosted at ThFree Co, Russian Federation.

__init__.py « system_demo_mode - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 902ed37b0067c5a4c2875905c8e3e2bba50eee10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

bl_info = {
    "name": "Demo Mode",
    "author": "Campbell Barton",
    "blender": (2, 5, 7),
    "api": 35622,
    "location": "Demo Menu",
    "description": "Demo mode lets you select multiple blend files and loop over them.",
    "warning": "",
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
        "Scripts/System/Demo_Mode#Running_Demo_Mode",
    "tracker_url": "",
    "support": 'OFFICIAL',
    "category": "System"}

# To support reload properly, try to access a package var, if it's there, reload everything
if "bpy" in locals():
    import imp
    if "config" in locals():
        imp.reload(config)


import bpy
from bpy.props import StringProperty, BoolProperty, IntProperty, FloatProperty, EnumProperty
from bpy_extras.io_utils import ImportHelper


class DemoModeSetup(bpy.types.Operator):
    '''Creates a demo script and optionally executes'''
    bl_idname = "wm.demo_mode_setup"
    bl_label = "Demo Mode (Setup)"
    bl_options = {'PRESET'}

    # List of operator properties, the attributes will be assigned
    # to the class instance from the operator settings before calling.

    # these are used to create the file list.
    filepath = StringProperty(name="File Path", description="Filepath used for importing the file", maxlen=1024, default="", subtype='FILE_PATH')
    random_order = BoolProperty(name="Random Order", description="Select files randomly", default=False)
    mode = EnumProperty(items=(
            ('AUTO', "Auto", ""),
            ('PLAY', "Play", ""),
            ('RENDER', "Render", ""),
            ),
                name="Method")

    run = BoolProperty(name="Run Immediately!", description="Run demo immediately", default=True)

    # these are mapped directly to the config!
    #
    # anim
    # ====
    anim_cycles = IntProperty(name="Cycles", description="Number of times to play the animation", min=1, max=1000, default=2)
    anim_time_min = FloatProperty(name="Time Min", description="Minimum number of seconds to show the animation for (for small loops)", min=0.0, max=1000.0, soft_min=1.0, soft_max=1000.0, default=4.0)
    anim_time_max = FloatProperty(name="Time Max", description="Maximum number of seconds to show the animation for (incase the end frame is very high for no reason)", min=0.0, max=100000000.0, soft_min=1.0, soft_max=100000000.0, default=8.0)
    anim_screen_switch = FloatProperty(name="Screen Switch", description="Time between switching screens (in seconds) or 0 to disable", min=0.0, max=100000000.0, soft_min=1.0, soft_max=60.0, default=0.0)
    #
    # render
    # ======
    display_render = FloatProperty(name="Render Delay", description="Time to display the rendered image before moving on (in seconds)", min=0.0, max=60.0, default=4.0)
    anim_render = BoolProperty(name="Render Anim", description="Render entire animation (render mode only)", default=False)

    def execute(self, context):
        from . import config

        keywords = self.as_keywords(ignore=("filepath", "random_order", "run"))

        from . import config
        cfg_str, dirpath = config.as_string(self.filepath, self.random_order, **keywords)
        text = bpy.data.texts.get("demo.py")
        if text:
            text.name += ".back"

        text = bpy.data.texts.new("demo.py")
        text.from_string(cfg_str)

        if self.run:
            extern_demo_mode_run()

        return {'FINISHED'}

    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}

    def check(self, context):
        return True  # lazy

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        box.label("Search *.blend recursively")
        box.label("Writes: demo.py config text.")

        col = layout.column()
        col.prop(self, "run")

        col.label("Generate Settings:")
        row = col.row()
        row.prop(self, "mode", expand=True)
        col.prop(self, "random_order")

        mode = self.mode

        col.separator()
        colsub = col.column()
        colsub.active = (mode in ('AUTO', 'PLAY'))
        colsub.label("Animate Settings:")
        colsub.prop(self, "anim_cycles")
        colsub.prop(self, "anim_time_min")
        colsub.prop(self, "anim_time_max")
        colsub.prop(self, "anim_screen_switch")

        col.separator()
        colsub = col.column()
        colsub.active = (mode in ('AUTO', 'RENDER'))
        colsub.label("Render Settings:")
        colsub.prop(self, "display_render")


class DemoModeRun(bpy.types.Operator):
    bl_idname = "wm.demo_mode_run"
    bl_label = "Demo Mode (Start)"

    def execute(self, context):
        if extern_demo_mode_run():
            return {'FINISHED'}
        else:
            self.report({'ERROR'}, "Cant load demo.py config, run: File -> Demo Mode (Setup)")
            return {'CANCELLED'}


# --- call demo_mode.py funcs
def extern_demo_mode_run():
    # this accesses demo_mode.py which is kept standalone
    # and can be run direct.
    from . import demo_mode
    if demo_mode.load_config():
        demo_mode.demo_mode_load_file()  # kick starts the modal operator
        return True
    else:
        return False


def extern_demo_mode_register():
    # this accesses demo_mode.py which is kept standalone
    # and can be run direct.
    from . import demo_mode
    demo_mode.register()


def extern_demo_mode_unregister():
    # this accesses demo_mode.py which is kept standalone
    # and can be run direct.
    from . import demo_mode
    demo_mode.unregister()

# --- intergration


def menu_func(self, context):
    layout = self.layout
    layout.operator(DemoModeSetup.bl_idname, icon='PREFERENCES')
    layout.operator(DemoModeRun.bl_idname, icon='PLAY')
    layout.separator()


def register():
    bpy.utils.register_class(DemoModeSetup)
    bpy.utils.register_class(DemoModeRun)

    bpy.types.INFO_MT_file.prepend(menu_func)

    extern_demo_mode_register()


def unregister():
    bpy.utils.unregister_class(DemoModeSetup)
    bpy.utils.unregister_class(DemoModeRun)

    bpy.types.INFO_MT_file.remove(menu_func)

    extern_demo_mode_unregister()

if __name__ == "__main__":
    register()