- aspectx wasnt saved in the render preset

- define a preset base class
- cleanup some comments and whitespace
This commit is contained in:
2009-11-21 23:55:14 +00:00
parent 7343de983e
commit 1dfbf3a9f6
9 changed files with 135 additions and 110 deletions

View File

@@ -41,14 +41,14 @@ sys.stdin = None
def load_scripts(reload_scripts=False):
import traceback
def test_import(module_name):
try:
return __import__(module_name)
except:
traceback.print_exc()
return None
base_path = os.path.join(os.path.dirname(__file__), "..", "..")
base_path = os.path.normpath(base_path) # clean
@@ -64,7 +64,7 @@ def load_scripts(reload_scripts=False):
mod = test_import(f)
else:
mod = None
if reload_scripts and mod:
print("Reloading:", mod)
reload(mod)
@@ -73,10 +73,10 @@ def load_scripts(reload_scripts=False):
if "-d" in sys.argv and False: # Enable this to measure startup speed
import cProfile
cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof')
import pstats
p = pstats.Stats('blender.prof')
p.sort_stats('cumulative').print_stats(100)
else:
load_scripts()
load_scripts()

View File

@@ -22,14 +22,14 @@ StructRNA = bpy_types.Struct.__bases__[0]
class Context(StructRNA):
def copy(self):
new_context = {}
generic_keys = StructRNA.__dict__.keys()
for item in dir(self):
if item not in generic_keys:
new_context[item] = getattr(self, item)
return new_context
@@ -47,7 +47,7 @@ def ord_ind(i1,i2):
return i2,i1
class Mesh(bpy_types.ID):
def _get_edge_keys(self):
return [edge_key for face in self.faces for edge_key in face.edge_keys]
@@ -102,10 +102,9 @@ class OrderedMeta(type):
def __prepare__(name, bases, **kwargs):
return collections.OrderedDict()
# Only defined so operators members can be used by accessing self.order
class Operator(StructRNA, metaclass=OrderedMeta):
'''
Only defined so operators members can be used by accessing self.order
'''
pass
@@ -113,12 +112,8 @@ class Menu(StructRNA):
def path_menu(self, searchpath, operator):
layout = self.layout
# hard coded to set the operators 'path' to the filename.
'''
Unrelated to the class above, add menu items from the filesystem.
hard coded to set the operators 'path' to the filename.
'''
import os
def path_to_name(f):

View File

@@ -32,12 +32,12 @@ def rna_idprop_ui_get(item, create=True):
def rna_idprop_ui_prop_get(item, prop, create=True):
rna_ui = rna_idprop_ui_get(item, create)
if rna_ui == None:
return None
try:
return rna_ui[prop]
except:
@@ -47,7 +47,7 @@ def rna_idprop_ui_prop_get(item, prop, create=True):
def rna_idprop_ui_prop_clear(item, prop):
rna_ui = rna_idprop_ui_get(item, False)
if rna_ui == None:
return
@@ -58,21 +58,21 @@ def rna_idprop_ui_prop_clear(item, prop):
def draw(layout, context, context_member, use_edit = True):
def assign_props(prop, val, key):
prop.path = context_member
prop.property = key
try:
prop.value = str(val)
except:
pass
rna_item = eval("context." + context_member)
items = rna_item.items()
items.sort()
if use_edit:
row = layout.row()
props = row.itemO("wm.properties_add", properties=True, text="Add")
@@ -83,10 +83,10 @@ def draw(layout, context, context_member, use_edit = True):
if key == '_RNA_UI':
continue
row = layout.row()
convert_to_pyobject = getattr(val, "convert_to_pyobject", None)
val_orig = val
if convert_to_pyobject:
val_draw = val = val.convert_to_pyobject()
@@ -101,23 +101,23 @@ def draw(layout, context, context_member, use_edit = True):
row = split.row()
else:
row = box.row()
row.itemL(text=key)
# explicit exception for arrays
if convert_to_pyobject and not hasattr(val_orig, "len"):
row.itemL(text=val_draw)
else:
row.itemR(rna_item, '["%s"]' % key, text="")
if use_edit:
row = split.row(align=True)
prop = row.itemO("wm.properties_edit", properties=True, text="edit")
assign_props(prop, val_draw, key)
prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
assign_props(prop, val_draw, key)
from bpy.props import *
@@ -138,14 +138,14 @@ class WM_OT_properties_edit(bpy.types.Operator):
'''Internal use (edit a property path)'''
bl_idname = "wm.properties_edit"
bl_label = "Edit Property!"
path = rna_path
property = rna_property
value = rna_value
min = rna_min
max = rna_max
description = StringProperty(name="Tip", default="")
# the class instance is not persistant, need to store in the class
# not ideal but changes as the op runs.
_last_prop = ['']
@@ -160,72 +160,72 @@ class WM_OT_properties_edit(bpy.types.Operator):
value_eval = eval(value)
except:
value_eval = value
if type(value_eval) == str:
value_eval = '"' + value_eval + '"'
value_eval = '"' + value_eval + '"'
# First remove
item = eval("context.%s" % path)
rna_idprop_ui_prop_clear(item, prop_old)
exec_str = "del item['%s']" % prop_old
# print(exec_str)
exec(exec_str)
# Reassign
exec_str = "item['%s'] = %s" % (prop, value_eval)
# print(exec_str)
exec(exec_str)
prop_type = type(item[prop])
prop_ui = rna_idprop_ui_prop_get(item, prop)
if prop_type in (float, int):
prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.properties.min)
prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.properties.max)
prop_ui['description'] = self.properties.description
return ('FINISHED',)
def invoke(self, context, event):
self._last_prop[:] = [self.properties.property]
item = eval("context.%s" % self.properties.path)
# setup defaults
prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create
if prop_ui:
self.properties.min = prop_ui.get("min", -1000000000)
self.properties.max = prop_ui.get("max", 1000000000)
self.properties.description = prop_ui.get("description", "")
if 0:
_message= "PyConsole, press Ctrl+D to unlock the BGE"
import sys
# evaluate commands in current namespace
frame= sys._getframe()
namespace = frame.f_globals.copy()
namespace.update(frame.f_locals)
import code
_message= "PyConsole, press Ctrl+D to unlock the BGE"
import sys
# evaluate commands in current namespace
frame= sys._getframe()
namespace = frame.f_globals.copy()
namespace.update(frame.f_locals)
import code
# Autocomp in python, not as comprehensive as IPython
import rlcompleter
try: # ick, some pythons dont have this
import readline
readline.parse_and_bind("tab: complete")
readline.parse_and_bind("tab: complete")
except:
pass
code.interact(banner=_message, local=namespace)
wm = context.manager
wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',)
@@ -240,7 +240,7 @@ class WM_OT_properties_add(bpy.types.Operator):
def execute(self, context):
item = eval("context.%s" % self.properties.path)
def unique_name(names):
prop = 'prop'
prop_new = prop
@@ -248,14 +248,14 @@ class WM_OT_properties_add(bpy.types.Operator):
while prop_new in names:
prop_new = prop + str(i)
i+=1
return prop_new
property = unique_name(item.keys())
item[property] = 1.0
return ('FINISHED',)
class WM_OT_properties_remove(bpy.types.Operator):
'''Internal use (edit a property path)'''
bl_idname = "wm.properties_remove"
@@ -267,5 +267,5 @@ class WM_OT_properties_remove(bpy.types.Operator):
def execute(self, context):
item = eval("context.%s" % self.properties.path)
del item[self.properties.property]
return ('FINISHED',)
return ('FINISHED',)

View File

@@ -142,7 +142,7 @@ def autocomplete(context):
sc = context.space_data
console = get_console(hash(context.region))[0]
current_line = sc.history[-1]
line = current_line.line

View File

@@ -51,11 +51,11 @@ def execute(context):
line = sc.history[-1].line
except:
return ('CANCELLED',)
bpy.ops.console.scrollback_append(text=sc.prompt + line, type='INPUT')
shell_run(line)
# insert a new blank line
bpy.ops.console.history_append(text="", current_character=0,
remove_duplicates=True)
@@ -72,7 +72,7 @@ def autocomplete(context):
def banner(context):
sc = context.space_data
shell_run("bash --version")
sc.prompt = os.getcwd()+PROMPT

View File

@@ -4,12 +4,12 @@
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -26,12 +26,12 @@ def main(context):
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
mesh = ob.data
face_list = [face for face in mesh.faces]
face_edge_keys = [face.edge_keys for face in face_list]
edge_face_count = mesh.edge_face_count_dict
def test_interior(index):
for key in face_edge_keys[index]:
if edge_face_count[key] < 3:

View File

@@ -19,47 +19,28 @@
import bpy
import os
class AddPreset(bpy.types.Operator):
'''Add a Render Preset'''
from wm import AddPresetBase
class AddPresetRender(AddPresetBase):
bl_idname = "render.preset_add"
bl_label = "Add Render Preset"
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen= 64, default= "New Preset")
_preset_values = [
name = AddPresetBase.name
preset_values = [
"bpy.context.scene.render_data.resolution_x",
"bpy.context.scene.render_data.resolution_y",
"bpy.context.scene.render_data.pixel_aspect_x",
"bpy.context.scene.render_data.pixel_aspect_x",
"bpy.context.scene.render_data.pixel_aspect_y",
"bpy.context.scene.render_data.fps",
"bpy.context.scene.render_data.fps_base",
"bpy.context.scene.render_data.resolution_percentage",
]
_last_preset = "" # hack to avoid remaking
def _as_filename(self, name): # could reuse for other presets
for char in " !@#$%^&*(){}:\";'[]<>,./?":
name = name.replace('.', '_')
return name.lower()
def execute(self, context):
filename = self._as_filename(self.properties.name) + ".py"
target_path = os.path.join(os.path.dirname(__file__), os.path.pardir, "presets", "render", filename)
print(target_path)
file_preset = open(target_path, 'w')
for rna_path in self._preset_values:
file_preset.write("%s = %s\n" % (rna_path, eval(rna_path)))
file_preset.close()
return ('FINISHED',)
preset_path = os.path.join("presets", "render")
bpy.ops.add(AddPresetRender)
def invoke(self, context, event):
wm = context.manager
wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',)
bpy.ops.add(AddPreset)

View File

@@ -175,4 +175,4 @@ class VertexPaintDirt(bpy.types.Operator):
bpy.ops.add(VertexPaintDirt)
if __name__ == "__main__":
bpy.ops.mesh.vertex_paint_dirt()
bpy.ops.mesh.vertex_paint_dirt()

View File

@@ -4,12 +4,12 @@
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -19,6 +19,7 @@
# <pep8-80 compliant>
import bpy
import os
from bpy.props import *
@@ -391,6 +392,54 @@ class WM_OT_reload_scripts(bpy.types.Operator):
'''
return ('FINISHED',)
class AddPresetBase(bpy.types.Operator):
'''Base preset class, only for subclassing
subclasses must define
- preset_values
- preset_path '''
bl_idname = "render.preset_add"
bl_label = "Add Render Preset"
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen= 64, default= "New Preset")
'''
preset_values = [
"bpy.context.scene.render_data.resolution_x",
"bpy.context.scene.render_data.resolution_y",
"bpy.context.scene.render_data.pixel_aspect_x",
"bpy.context.scene.render_data.pixel_aspect_y",
"bpy.context.scene.render_data.fps",
"bpy.context.scene.render_data.fps_base",
"bpy.context.scene.render_data.resolution_percentage",
]
preset_path = os.path.join("presets", "render")
'''
def _as_filename(self, name): # could reuse for other presets
for char in " !@#$%^&*(){}:\";'[]<>,./?":
name = name.replace('.', '_')
return name.lower()
def execute(self, context):
filename = self._as_filename(self.properties.name) + ".py"
target_path = os.path.join(os.path.dirname(__file__), os.path.pardir, self.preset_path, filename)
file_preset = open(target_path, 'w')
for rna_path in self.preset_values:
file_preset.write("%s = %s\n" % (rna_path, eval(rna_path)))
file_preset.close()
return ('FINISHED',)
def invoke(self, context, event):
wm = context.manager
wm.invoke_props_popup(self, event)
return ('RUNNING_MODAL',)
bpy.ops.add(MESH_OT_delete_edgeloop)
bpy.ops.add(WM_OT_context_set_boolean)