Cleanup: pep8 for examples

This commit is contained in:
Campbell Barton
2019-11-01 10:53:47 +11:00
parent 78ad368d12
commit 61bf51acb5
7 changed files with 19 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ if blender_date is None:
# Happens when built without WITH_BUILD_INFO e.g. # Happens when built without WITH_BUILD_INFO e.g.
date_string = time.strftime("%B %d, %Y", time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))) date_string = time.strftime("%B %d, %Y", time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))))
else: else:
blender_date = blender_date.strip().partition(" ")[2] # remove 'date:' prefix blender_date = blender_date.strip().partition(" ")[2] # remove 'date:' prefix
date_string = time.strftime("%B %d, %Y", time.strptime(blender_date, "%Y-%m-%d")) date_string = time.strftime("%B %d, %Y", time.strptime(blender_date, "%Y-%m-%d"))
outfile = open(outfilename, "w") outfile = open(outfilename, "w")

View File

@@ -4,7 +4,9 @@ Run a Function in x Seconds
""" """
import bpy import bpy
def in_5_seconds(): def in_5_seconds():
print("Hello World") print("Hello World")
bpy.app.timers.register(in_5_seconds, first_interval=5) bpy.app.timers.register(in_5_seconds, first_interval=5)

View File

@@ -4,8 +4,10 @@ Run a Function every x Seconds
""" """
import bpy import bpy
def every_2_seconds(): def every_2_seconds():
print("Hello World") print("Hello World")
return 2.0 return 2.0
bpy.app.timers.register(every_2_seconds) bpy.app.timers.register(every_2_seconds)

View File

@@ -6,6 +6,7 @@ import bpy
counter = 0 counter = 0
def run_10_times(): def run_10_times():
global counter global counter
counter += 1 counter += 1
@@ -14,4 +15,5 @@ def run_10_times():
return None return None
return 0.1 return 0.1
bpy.app.timers.register(run_10_times) bpy.app.timers.register(run_10_times)

View File

@@ -5,8 +5,10 @@ Assign parameters to functions
import bpy import bpy
import functools import functools
def print_message(message): def print_message(message):
print("Message:", message) print("Message:", message)
bpy.app.timers.register(functools.partial(print_message, "Hello"), first_interval=2.0) bpy.app.timers.register(functools.partial(print_message, "Hello"), first_interval=2.0)
bpy.app.timers.register(functools.partial(print_message, "World"), first_interval=3.0) bpy.app.timers.register(functools.partial(print_message, "World"), first_interval=3.0)

View File

@@ -29,7 +29,7 @@ class OBJECT_OT_simple_exporter(bpy.types.Operator):
# Happens for non-geometry objects. # Happens for non-geometry objects.
continue continue
print(f"Exporting mesh with {len(mesh.vertices)} vertices " print(f"Exporting mesh with {len(mesh.vertices)} vertices "
f"at {object_instance.matrix_world}") f"at {object_instance.matrix_world}")
object_instace.to_mesh_clear() object_instace.to_mesh_clear()
return {'FINISHED'} return {'FINISHED'}

View File

@@ -101,7 +101,7 @@ class CustomRenderEngine(bpy.types.RenderEngine):
# Bind shader that converts from scene linear to display space, # Bind shader that converts from scene linear to display space,
bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND)
bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA); bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA)
self.bind_display_space_shader(scene) self.bind_display_space_shader(scene)
if not self.draw_data or self.draw_data.dimensions != dimensions: if not self.draw_data or self.draw_data.dimensions != dimensions:
@@ -135,18 +135,18 @@ class CustomDrawData:
# Bind shader that converts from scene linear to display space, # Bind shader that converts from scene linear to display space,
# use the scene's color management settings. # use the scene's color management settings.
shader_program = bgl.Buffer(bgl.GL_INT, 1) shader_program = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGetIntegerv(bgl.GL_CURRENT_PROGRAM, shader_program); bgl.glGetIntegerv(bgl.GL_CURRENT_PROGRAM, shader_program)
# Generate vertex array # Generate vertex array
self.vertex_array = bgl.Buffer(bgl.GL_INT, 1) self.vertex_array = bgl.Buffer(bgl.GL_INT, 1)
bgl.glGenVertexArrays(1, self.vertex_array) bgl.glGenVertexArrays(1, self.vertex_array)
bgl.glBindVertexArray(self.vertex_array[0]) bgl.glBindVertexArray(self.vertex_array[0])
texturecoord_location = bgl.glGetAttribLocation(shader_program[0], "texCoord"); texturecoord_location = bgl.glGetAttribLocation(shader_program[0], "texCoord")
position_location = bgl.glGetAttribLocation(shader_program[0], "pos"); position_location = bgl.glGetAttribLocation(shader_program[0], "pos")
bgl.glEnableVertexAttribArray(texturecoord_location); bgl.glEnableVertexAttribArray(texturecoord_location)
bgl.glEnableVertexAttribArray(position_location); bgl.glEnableVertexAttribArray(position_location)
# Generate geometry buffers for drawing textured quad # Generate geometry buffers for drawing textured quad
position = [0.0, 0.0, width, 0.0, width, height, 0.0, height] position = [0.0, 0.0, width, 0.0, width, height, 0.0, height]
@@ -178,7 +178,7 @@ class CustomDrawData:
bgl.glActiveTexture(bgl.GL_TEXTURE0) bgl.glActiveTexture(bgl.GL_TEXTURE0)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0]) bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0])
bgl.glBindVertexArray(self.vertex_array[0]) bgl.glBindVertexArray(self.vertex_array[0])
bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4); bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4)
bgl.glBindVertexArray(0) bgl.glBindVertexArray(0)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
@@ -201,6 +201,7 @@ def get_panels():
return panels return panels
def register(): def register():
# Register the RenderEngine # Register the RenderEngine
bpy.utils.register_class(CustomRenderEngine) bpy.utils.register_class(CustomRenderEngine)
@@ -208,6 +209,7 @@ def register():
for panel in get_panels(): for panel in get_panels():
panel.COMPAT_ENGINES.add('CUSTOM') panel.COMPAT_ENGINES.add('CUSTOM')
def unregister(): def unregister():
bpy.utils.unregister_class(CustomRenderEngine) bpy.utils.unregister_class(CustomRenderEngine)