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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-01-26 10:54:27 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-01-26 10:54:27 +0300
commit1f5cec709c8f79ff706eca4399583696853a3aec (patch)
treea5b8283383b7151c506ecccea3cfc7a39d90b24b /release/scripts/templates
parent7a231938119f97bde0f78bd939a55274806cf1f5 (diff)
update to background_job template to use --factory-startup option.
make all templates pep8 compliant.
Diffstat (limited to 'release/scripts/templates')
-rw-r--r--release/scripts/templates/addon_add_object.py20
-rw-r--r--release/scripts/templates/background_job.py37
-rw-r--r--release/scripts/templates/builtin_keyingset.py15
-rw-r--r--release/scripts/templates/gamelogic.py4
-rw-r--r--release/scripts/templates/gamelogic_basic.py1
-rw-r--r--release/scripts/templates/gamelogic_module.py1
-rw-r--r--release/scripts/templates/operator_export.py7
-rw-r--r--release/scripts/templates/operator_modal.py1
-rw-r--r--release/scripts/templates/operator_modal_draw.py3
-rw-r--r--release/scripts/templates/operator_modal_view3d.py2
-rw-r--r--release/scripts/templates/operator_simple.py4
-rw-r--r--release/scripts/templates/operator_uv.py3
-rw-r--r--release/scripts/templates/panel_simple.py1
13 files changed, 57 insertions, 42 deletions
diff --git a/release/scripts/templates/addon_add_object.py b/release/scripts/templates/addon_add_object.py
index 44073f998ab..00db3a55291 100644
--- a/release/scripts/templates/addon_add_object.py
+++ b/release/scripts/templates/addon_add_object.py
@@ -22,12 +22,14 @@ def add_object(self, context):
scale_x = self.scale.x
scale_y = self.scale.y
- verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),
- Vector(( 1 * scale_x, 1 * scale_y, 0)),
- Vector(( 1 * scale_x, -1 * scale_y, 0)),
- Vector((-1 * scale_x, -1 * scale_y, 0)),]
+ verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),
+ Vector((1 * scale_x, 1 * scale_y, 0)),
+ Vector((1 * scale_x, -1 * scale_y, 0)),
+ Vector((-1 * scale_x, -1 * scale_y, 0)),
+ ]
+
edges = []
- faces = [[0,1,2,3]]
+ faces = [[0, 1, 2, 3]]
mesh_data = bpy.data.meshes.new(name='New Object Mesh')
mesh_data.from_pydata(verts, edges, faces)
@@ -42,14 +44,14 @@ class OBJECT_OT_add_object(bpy.types.Operator, AddObjectHelper):
bl_options = {'REGISTER', 'UNDO'}
scale = FloatVectorProperty(name='scale',
- default=(1,1,1),
+ default=(1.0, 1.0, 1.0),
subtype='TRANSLATION',
description='scaling')
def execute(self, context):
-
+
add_object(self, context)
-
+
return {'FINISHED'}
@@ -61,9 +63,11 @@ def add_object_button(self, context):
text="Add Object",
icon="PLUGIN")
+
def register():
bpy.types.INFO_MT_mesh_add.append(add_object_button)
+
def unregister():
bpy.types.INFO_MT_mesh_add.remove(add_object_button)
diff --git a/release/scripts/templates/background_job.py b/release/scripts/templates/background_job.py
index bf29de63830..f199ee5ad50 100644
--- a/release/scripts/templates/background_job.py
+++ b/release/scripts/templates/background_job.py
@@ -1,16 +1,21 @@
# This script is an example of how you can run blender from the command line (in background mode with no interface)
# to automate tasks, in this example it creates a text object, camera and light, then renders and/or saves it.
# This example also shows how you can parse command line options to python scripts.
-#
+#
# Example usage for this test.
-# blender -b -P $HOME/background_job.py -- --text="Hello World" --render="/tmp/hello" --save="/tmp/hello.blend"
-#
-# Notice all python args are after the "--" argument.
+# blender --background --factory-startup --python $HOME/background_job.py -- --text="Hello World" --render="/tmp/hello" --save="/tmp/hello.blend"
+#
+# Notice:
+# '--factory-startup' is used to avoid the user default settings from interfearing with automated scene generation.
+# '--' causes blender to ignore all following arguments so python can use them.
+#
+# See blender --help for details.
import bpy
+
def example_function(body_text, save_path, render_path):
-
+
scene = bpy.context.scene
# Clear existing objects.
@@ -31,7 +36,7 @@ def example_function(body_text, save_path, render_path):
cam_ob = bpy.data.objects.new(name="MyCam", object_data=cam_data)
scene.objects.link(cam_ob) # add the camera data to the scene (creating a new object)
scene.camera = cam_ob # set the active camera
- cam_ob.location = 0.0, 0.0, 10.0
+ cam_ob.location = 0.0, 0.0, 10.0
# Lamp
lamp_data = bpy.data.lamps.new("MyLamp", 'POINT')
@@ -63,23 +68,23 @@ def example_function(body_text, save_path, render_path):
import sys # to get command line args
import optparse # to parse options for us and print a nice help message
+
def main():
-
+
# get the args passed to blender after "--", all of which are ignored by blender specifically
# so python may receive its own arguments
argv = sys.argv
if "--" not in argv:
- argv = [] # as if no args are passed
- else:
- argv = argv[argv.index("--") + 1:] # get all args after "--"
-
+ argv = [] # as if no args are passed
+ else:
+ argv = argv[argv.index("--") + 1:] # get all args after "--"
+
# When --help or no args are given, print this help
usage_text = "Run blender in background mode with this script:"
usage_text += " blender -b -P " + __file__ + " -- [options]"
-
+
parser = optparse.OptionParser(usage=usage_text)
-
# Example background utility, add some text and renders or saves it (with options)
# Possible types are: string, int, long, choice, float and complex.
@@ -88,8 +93,8 @@ def main():
parser.add_option("-s", "--save", dest="save_path", help="Save the generated file to the specified path", metavar='FILE')
parser.add_option("-r", "--render", dest="render_path", help="Render an image to the specified path", metavar='FILE')
- options, args = parser.parse_args(argv) # In this example we wont use the args
-
+ options, args = parser.parse_args(argv) # In this example we wont use the args
+
if not argv:
parser.print_help()
return
@@ -98,7 +103,7 @@ def main():
print("Error: --text=\"some string\" argument not given, aborting.")
parser.print_help()
return
-
+
# Run the example function
example_function(options.body_text, options.save_path, options.render_path)
diff --git a/release/scripts/templates/builtin_keyingset.py b/release/scripts/templates/builtin_keyingset.py
index 878e2747b74..799f305d8b4 100644
--- a/release/scripts/templates/builtin_keyingset.py
+++ b/release/scripts/templates/builtin_keyingset.py
@@ -1,28 +1,29 @@
import bpy
from keyingsets_utils import *
+
class BUILTIN_KSI_hello(bpy.types.KeyingSetInfo):
bl_label = "Hello World KeyingSet"
# poll - test for whether Keying Set can be used at all
def poll(ksi, context):
return (context.active_object) or (context.selected_objects)
-
+
# iterator - go over all relevant data, calling generate()
def iterator(ksi, context, ks):
for ob in context.selected_objects:
ksi.generate(context, ks, ob)
-
+
# generator - populate Keying Set with property paths to use
def generate(ksi, context, ks, data):
id_block = data.id_data
-
+
ks.paths.add(id_block, "location")
-
+
for i in range(5):
ks.paths.add(id_block, "layers", i, group_method='NAMED', group_name="5x Hello Layers")
-
+
ks.paths.add(id_block, "show_x_ray", group_method='NONE')
-
-# manually register
+
+# manually register
bpy.types.register(BUILTIN_KSI_hello)
diff --git a/release/scripts/templates/gamelogic.py b/release/scripts/templates/gamelogic.py
index 0a419955b81..c6d15850a4e 100644
--- a/release/scripts/templates/gamelogic.py
+++ b/release/scripts/templates/gamelogic.py
@@ -9,6 +9,7 @@ import bge
# for functions like getWindowWidth(), getWindowHeight()
# import Rasterizer
+
def main():
cont = bge.logic.getCurrentController()
@@ -18,7 +19,6 @@ def main():
# for scripts that deal with spacial logic
own_pos = own.worldPosition
-
# Some example functions, remove to write your own script.
# check for a positive sensor, will run on any object without errors.
print('Logic info for KX_GameObject', own.name)
@@ -52,14 +52,12 @@ def main():
# sens_key = cont.sensors['key_sensor']
# actu_motion = cont.actuators['motion']
-
# Loop through all other objects in the scene
sce = bge.logic.getCurrentScene()
print('Scene Objects:', sce.name)
for ob in sce.objects:
print(' ', ob.name, ob.worldPosition)
-
# Example where collision objects are checked for their properties
# adding to our objects "life" property
"""
diff --git a/release/scripts/templates/gamelogic_basic.py b/release/scripts/templates/gamelogic_basic.py
index c5578a0add9..dbfcf948b18 100644
--- a/release/scripts/templates/gamelogic_basic.py
+++ b/release/scripts/templates/gamelogic_basic.py
@@ -1,5 +1,6 @@
import bge
+
def main():
cont = bge.logic.getCurrentController()
diff --git a/release/scripts/templates/gamelogic_module.py b/release/scripts/templates/gamelogic_module.py
index 70bd4d9b45b..fcc8a8839c9 100644
--- a/release/scripts/templates/gamelogic_module.py
+++ b/release/scripts/templates/gamelogic_module.py
@@ -12,6 +12,7 @@ import bge
# inside the function if you intend to use the module
# with multiple objects.
+
def main(cont):
own = cont.owner
diff --git a/release/scripts/templates/operator_export.py b/release/scripts/templates/operator_export.py
index ef8acfeb3a3..4f950b11d01 100644
--- a/release/scripts/templates/operator_export.py
+++ b/release/scripts/templates/operator_export.py
@@ -1,5 +1,6 @@
import bpy
+
def write_some_data(context, filepath, use_some_setting):
print("running write_some_data...")
f = open(filepath, 'w')
@@ -18,9 +19,9 @@ from bpy.props import *
class ExportSomeData(bpy.types.Operator, ExportHelper):
'''This appiers in the tooltip of the operator and in the generated docs.'''
- bl_idname = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed
+ bl_idname = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed
bl_label = "Export Some Data"
-
+
# ExportHelper mixin class uses this
filename_ext = ".txt"
@@ -28,7 +29,7 @@ class ExportSomeData(bpy.types.Operator, ExportHelper):
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
- use_setting = BoolProperty(name="Example Boolean", description="Example Tooltip", default= True)
+ use_setting = BoolProperty(name="Example Boolean", description="Example Tooltip", default=True)
type = bpy.props.EnumProperty(items=(('OPT_A', "First Option", "Description one"), ('OPT_B', "Second Option", "Description two.")),
name="Example Enum",
diff --git a/release/scripts/templates/operator_modal.py b/release/scripts/templates/operator_modal.py
index 6283626e7b1..026b5fd2d16 100644
--- a/release/scripts/templates/operator_modal.py
+++ b/release/scripts/templates/operator_modal.py
@@ -1,6 +1,7 @@
import bpy
from bpy.props import *
+
class ModalOperator(bpy.types.Operator):
'''Move an object with the mouse, example.'''
bl_idname = "object.modal_operator"
diff --git a/release/scripts/templates/operator_modal_draw.py b/release/scripts/templates/operator_modal_draw.py
index e159bc0f9c5..52259e4b8e7 100644
--- a/release/scripts/templates/operator_modal_draw.py
+++ b/release/scripts/templates/operator_modal_draw.py
@@ -2,10 +2,11 @@ import bpy
import bgl
import blf
+
def draw_callback_px(self, context):
print("mouse points", len(self.mouse_path))
- font_id = 0 # XXX, need to find out how best to get this.
+ font_id = 0 # XXX, need to find out how best to get this.
# draw some text
blf.position(font_id, 15, 30, 0)
diff --git a/release/scripts/templates/operator_modal_view3d.py b/release/scripts/templates/operator_modal_view3d.py
index 55b58596f17..eacd335c1da 100644
--- a/release/scripts/templates/operator_modal_view3d.py
+++ b/release/scripts/templates/operator_modal_view3d.py
@@ -2,6 +2,7 @@ import bpy
from mathutils import Vector
from bpy.props import FloatVectorProperty
+
class ViewOperator(bpy.types.Operator):
'''Translate the view using mouse events.'''
bl_idname = "view3d.modal_operator"
@@ -9,7 +10,6 @@ class ViewOperator(bpy.types.Operator):
offset = FloatVectorProperty(name="Offset", size=3)
-
def execute(self, context):
v3d = context.space_data
rv3d = v3d.region_3d
diff --git a/release/scripts/templates/operator_simple.py b/release/scripts/templates/operator_simple.py
index 853bfa666eb..6a887a70bdc 100644
--- a/release/scripts/templates/operator_simple.py
+++ b/release/scripts/templates/operator_simple.py
@@ -1,11 +1,13 @@
import bpy
+
def main(context):
for ob in context.scene.objects:
print(ob)
+
class SimpleOperator(bpy.types.Operator):
- ''''''
+ '''Tooltip'''
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
diff --git a/release/scripts/templates/operator_uv.py b/release/scripts/templates/operator_uv.py
index e0cf8dd5db4..73392466aa7 100644
--- a/release/scripts/templates/operator_uv.py
+++ b/release/scripts/templates/operator_uv.py
@@ -1,5 +1,6 @@
import bpy
+
def main(context):
obj = context.active_object
mesh = obj.data
@@ -8,7 +9,6 @@ def main(context):
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
-
if not mesh.uv_textures:
uvtex = bpy.ops.mesh.uv_texture_add()
else:
@@ -22,7 +22,6 @@ def main(context):
# apply the location of the vertex as a UV
uvs[j][:] = mesh.vertices[v_idx].co.xy
-
if is_editmode:
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
diff --git a/release/scripts/templates/panel_simple.py b/release/scripts/templates/panel_simple.py
index 7c73e58a3e5..160bd1ef0bf 100644
--- a/release/scripts/templates/panel_simple.py
+++ b/release/scripts/templates/panel_simple.py
@@ -1,5 +1,6 @@
import bpy
+
class OBJECT_PT_hello(bpy.types.Panel):
bl_label = "Hello World Panel"
bl_space_type = "PROPERTIES"