Skip to content

Commit b380279

Browse files
authored
Merge pull request #2994 from ferdnyc/blender-py-style
Blender Python scripts: Code formatting
2 parents 69632c1 + 0524a02 commit b380279

20 files changed

+1386
-1384
lines changed

src/blender/scripts/blinds.py

+65-65
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,85 @@
1-
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
1+
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
22
# Copyright (C) 2009 Jonathan Thomas
33
#
4-
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
4+
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
55
#
6-
# OpenShot Video Editor is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
6+
# OpenShot Video Editor is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
1010
#
11-
# OpenShot Video Editor is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
11+
# OpenShot Video Editor is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
1515
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
16+
# You should have received a copy of the GNU General Public License
17+
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
1818

1919

2020
# Import Blender's python API. This only works when the script is being
2121
# run from the context of Blender. Blender contains it's own version of Python
2222
# with this library pre-installed.
2323
import bpy
2424

25-
# Load a font
25+
2626
def load_font(font_path):
27-
""" Load a new TTF font into Blender, and return the font object """
28-
# get the original list of fonts (before we add a new one)
29-
original_fonts = bpy.data.fonts.keys()
30-
31-
# load new font
32-
bpy.ops.font.open(filepath=font_path)
33-
34-
# get the new list of fonts (after we added a new one)
35-
for font_name in bpy.data.fonts.keys():
36-
if font_name not in original_fonts:
37-
return bpy.data.fonts[font_name]
38-
39-
# no new font was added
40-
return None
27+
""" Load a new TTF font into Blender, and return the font object """
28+
# get the original list of fonts (before we add a new one)
29+
original_fonts = bpy.data.fonts.keys()
30+
31+
# load new font
32+
bpy.ops.font.open(filepath=font_path)
33+
34+
# get the new list of fonts (after we added a new one)
35+
for font_name in bpy.data.fonts.keys():
36+
if font_name not in original_fonts:
37+
return bpy.data.fonts[font_name]
38+
39+
# no new font was added
40+
return None
4141

4242
# Debug Info:
4343
# ./blender -b test.blend -P demo.py
4444
# -b = background mode
4545
# -P = run a Python script within the context of the project file
4646

47+
4748
# Init all of the variables needed by this script. Because Blender executes
4849
# this script, OpenShot will inject a dictionary of the required parameters
4950
# before this script is executed.
50-
params = {
51-
'title' : 'Oh Yeah! OpenShot!',
52-
'extrude' : 0.1,
53-
'bevel_depth' : 0.02,
54-
'spacemode' : 'CENTER',
55-
'text_size' : 1.5,
56-
'width' : 1.0,
57-
'fontname' : 'Bfont',
58-
59-
'color' : [0.8,0.8,0.8],
60-
'alpha' : 1.0,
61-
62-
'output_path' : '/tmp/',
63-
'fps' : 24,
64-
'quality' : 90,
65-
'file_format' : 'PNG',
66-
'color_mode' : 'RGBA',
67-
'horizon_color' : [0.57, 0.57, 0.57],
68-
'resolution_x' : 1920,
69-
'resolution_y' : 1080,
70-
'resolution_percentage' : 100,
71-
'start_frame' : 20,
72-
'end_frame' : 25,
73-
'animation' : True,
74-
}
75-
76-
#INJECT_PARAMS_HERE
51+
params = {
52+
'title': 'Oh Yeah! OpenShot!',
53+
'extrude': 0.1,
54+
'bevel_depth': 0.02,
55+
'spacemode': 'CENTER',
56+
'text_size': 1.5,
57+
'width': 1.0,
58+
'fontname': 'Bfont',
59+
60+
'color': [0.8, 0.8, 0.8],
61+
'alpha': 1.0,
62+
63+
'output_path': '/tmp/',
64+
'fps': 24,
65+
'quality': 90,
66+
'file_format': 'PNG',
67+
'color_mode': 'RGBA',
68+
'horizon_color': [0.57, 0.57, 0.57],
69+
'resolution_x': 1920,
70+
'resolution_y': 1080,
71+
'resolution_percentage': 100,
72+
'start_frame': 20,
73+
'end_frame': 25,
74+
'animation': True,
75+
}
76+
77+
# INJECT_PARAMS_HERE
7778

7879
# The remainder of this script will modify the current Blender .blend project
7980
# file, and adjust the settings. The .blend file is specified in the XML file
8081
# that defines this template in OpenShot.
81-
#----------------------------------------------------------------------------
82+
# ----------------------------------------------------------------------------
8283

8384
# Modify Text / Curve settings
8485
#print (bpy.data.curves.keys())
@@ -93,12 +94,12 @@ def load_font(font_path):
9394
# Get font object
9495
font = None
9596
if params["fontname"] != "Bfont":
96-
# Add font so it's available to Blender
97-
font = load_font(params["fontname"])
97+
# Add font so it's available to Blender
98+
font = load_font(params["fontname"])
9899
else:
99-
# Get default font
100-
font = bpy.data.fonts["Bfont"]
101-
100+
# Get default font
101+
font = bpy.data.fonts["Bfont"]
102+
102103
text_object.font = font
103104

104105
text_object = bpy.data.curves["Subtitle"]
@@ -134,15 +135,14 @@ def load_font(font_path):
134135
bpy.context.scene.frame_end = params["end_frame"]
135136

136137
# Animation Speed (use Blender's time remapping to slow or speed up animation)
137-
animation_speed = int(params["animation_speed"]) # time remapping multiplier
138-
new_length = int(params["end_frame"]) * animation_speed # new length (in frames)
138+
animation_speed = int(params["animation_speed"]) # time remapping multiplier
139+
new_length = int(params["end_frame"]) * animation_speed # new length (in frames)
139140
bpy.context.scene.frame_end = new_length
140141
bpy.context.scene.render.frame_map_old = 1
141142
bpy.context.scene.render.frame_map_new = animation_speed
142143
if params["start_frame"] == params["end_frame"]:
143-
bpy.context.scene.frame_start = params["end_frame"]
144-
bpy.context.scene.frame_end = params["end_frame"]
144+
bpy.context.scene.frame_start = params["end_frame"]
145+
bpy.context.scene.frame_end = params["end_frame"]
145146

146147
# Render the current animation to the params["output_path"] folder
147148
bpy.ops.render.render(animation=params["animation"])
148-

src/blender/scripts/blur.py

+66-66
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,87 @@
1-
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
1+
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
22
# Copyright (C) 2009 Jonathan Thomas
33
#
4-
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
4+
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
55
#
6-
# OpenShot Video Editor is free software: you can redistribute it and/or modify
7-
# it under the terms of the GNU General Public License as published by
8-
# the Free Software Foundation, either version 3 of the License, or
9-
# (at your option) any later version.
6+
# OpenShot Video Editor is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
1010
#
11-
# OpenShot Video Editor is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
11+
# OpenShot Video Editor is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
1515
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
16+
# You should have received a copy of the GNU General Public License
17+
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
1818

1919

2020
# Import Blender's python API. This only works when the script is being
2121
# run from the context of Blender. Blender contains it's own version of Python
2222
# with this library pre-installed.
2323
import bpy
2424

25-
# Load a font
25+
2626
def load_font(font_path):
27-
""" Load a new TTF font into Blender, and return the font object """
28-
# get the original list of fonts (before we add a new one)
29-
original_fonts = bpy.data.fonts.keys()
30-
31-
# load new font
32-
bpy.ops.font.open(filepath=font_path)
33-
34-
# get the new list of fonts (after we added a new one)
35-
for font_name in bpy.data.fonts.keys():
36-
if font_name not in original_fonts:
37-
return bpy.data.fonts[font_name]
38-
39-
# no new font was added
40-
return None
27+
""" Load a new TTF font into Blender, and return the font object """
28+
# get the original list of fonts (before we add a new one)
29+
original_fonts = bpy.data.fonts.keys()
30+
31+
# load new font
32+
bpy.ops.font.open(filepath=font_path)
33+
34+
# get the new list of fonts (after we added a new one)
35+
for font_name in bpy.data.fonts.keys():
36+
if font_name not in original_fonts:
37+
return bpy.data.fonts[font_name]
38+
39+
# no new font was added
40+
return None
4141

4242
# Debug Info:
4343
# ./blender -b test.blend -P demo.py
4444
# -b = background mode
4545
# -P = run a Python script within the context of the project file
4646

47+
4748
# Init all of the variables needed by this script. Because Blender executes
4849
# this script, OpenShot will inject a dictionary of the required parameters
4950
# before this script is executed.
50-
params = {
51-
'title' : 'Oh Yeah! OpenShot!',
52-
'extrude' : 0.1,
53-
'bevel_depth' : 0.02,
54-
'spacemode' : 'CENTER',
55-
'text_size' : 1.5,
56-
'width' : 1.0,
57-
'fontname' : 'Bfont',
58-
59-
'color' : [0.8,0.8,0.8],
60-
'alpha' : 1.0,
61-
62-
'output_path' : '/tmp/',
63-
'fps' : 24,
64-
'quality' : 90,
65-
'file_format' : 'PNG',
66-
'color_mode' : 'RGBA',
67-
'horizon_color' : [0.57, 0.57, 0.57],
68-
'resolution_x' : 1920,
69-
'resolution_y' : 1080,
70-
'resolution_percentage' : 100,
71-
'start_frame' : 20,
72-
'end_frame' : 25,
73-
'animation' : True,
74-
'blur_amount_x': 75,
75-
'blur_amount_y': 75,
76-
}
77-
78-
#INJECT_PARAMS_HERE
51+
params = {
52+
'title': 'Oh Yeah! OpenShot!',
53+
'extrude': 0.1,
54+
'bevel_depth': 0.02,
55+
'spacemode': 'CENTER',
56+
'text_size': 1.5,
57+
'width': 1.0,
58+
'fontname': 'Bfont',
59+
60+
'color': [0.8, 0.8, 0.8],
61+
'alpha': 1.0,
62+
63+
'output_path': '/tmp/',
64+
'fps': 24,
65+
'quality': 90,
66+
'file_format': 'PNG',
67+
'color_mode': 'RGBA',
68+
'horizon_color': [0.57, 0.57, 0.57],
69+
'resolution_x': 1920,
70+
'resolution_y': 1080,
71+
'resolution_percentage': 100,
72+
'start_frame': 20,
73+
'end_frame': 25,
74+
'animation': True,
75+
'blur_amount_x': 75,
76+
'blur_amount_y': 75,
77+
}
78+
79+
# INJECT_PARAMS_HERE
7980

8081
# The remainder of this script will modify the current Blender .blend project
8182
# file, and adjust the settings. The .blend file is specified in the XML file
8283
# that defines this template in OpenShot.
83-
#----------------------------------------------------------------------------
84+
# ----------------------------------------------------------------------------
8485

8586
# Modify Text / Curve settings
8687
#print (bpy.data.curves.keys())
@@ -95,11 +96,11 @@ def load_font(font_path):
9596
# Get font object
9697
font = None
9798
if params["fontname"] != "Bfont":
98-
# Add font so it's available to Blender
99-
font = load_font(params["fontname"])
99+
# Add font so it's available to Blender
100+
font = load_font(params["fontname"])
100101
else:
101-
# Get default font
102-
font = bpy.data.fonts["Bfont"]
102+
# Get default font
103+
font = bpy.data.fonts["Bfont"]
103104

104105
text_object.font = font
105106

@@ -131,15 +132,14 @@ def load_font(font_path):
131132
bpy.context.scene.frame_end = params["end_frame"]
132133

133134
# Animation Speed (use Blender's time remapping to slow or speed up animation)
134-
animation_speed = int(params["animation_speed"]) # time remapping multiplier
135-
new_length = int(params["end_frame"]) * animation_speed # new length (in frames)
135+
animation_speed = int(params["animation_speed"]) # time remapping multiplier
136+
new_length = int(params["end_frame"]) * animation_speed # new length (in frames)
136137
bpy.context.scene.frame_end = new_length
137138
bpy.context.scene.render.frame_map_old = 1
138139
bpy.context.scene.render.frame_map_new = animation_speed
139140
if params["start_frame"] == params["end_frame"]:
140-
bpy.context.scene.frame_start = params["end_frame"]
141-
bpy.context.scene.frame_end = params["end_frame"]
141+
bpy.context.scene.frame_start = params["end_frame"]
142+
bpy.context.scene.frame_end = params["end_frame"]
142143

143144
# Render the current animation to the params["output_path"] folder
144145
bpy.ops.render.render(animation=params["animation"])
145-

0 commit comments

Comments
 (0)