[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4133] contrib/py/scripts/addons/ add_mesh_clusters/__init__.py:

Clemens Barth barth at root-1.de
Thu Jan 3 14:17:01 CET 2013


Revision: 4133
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4133
Author:   blendphys
Date:     2013-01-03 13:16:58 +0000 (Thu, 03 Jan 2013)
Log Message:
-----------

According to Campbell's demand (see email below, bpy.context.scene issue) and 
the last message in the tracker 

http://projects.blender.org/tracker/index.php?func=detail&aid=31618&group_id=153&atid=468)

I have changed the code. 

Blendphys.


******************* Campbells email from 20.12.2012 03:38 ********************

Recently I've noticed addons using bpy.context.scene when being
imported or in the register() function.

This is really bad practice and will cause inconsistency if the addon
is enabled and a different blend file is loaded.
In the worst case accessing a removed datablock can crash which is
likely if a datablock is stored as a global variable on activation -
object_laplace_lightning.py does this.

I've changed addon loading so that they only get access to a
restricted context which only exposes 'window_manager' - needed for
adding keymaps.

.....

Modified Paths:
--------------
    contrib/py/scripts/addons/add_mesh_clusters/__init__.py

Modified: contrib/py/scripts/addons/add_mesh_clusters/__init__.py
===================================================================
--- contrib/py/scripts/addons/add_mesh_clusters/__init__.py	2013-01-03 13:09:57 UTC (rev 4132)
+++ contrib/py/scripts/addons/add_mesh_clusters/__init__.py	2013-01-03 13:16:58 UTC (rev 4133)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2012-03-25 by Clemens Barth
 #  First publication in Blender  : 2012-05-27 by Clemens Barth
-#  Last modified                 : 2012-11-03
+#  Last modified                 : 2013-01-03
 #
 #
 #
@@ -102,10 +102,7 @@
     def draw(self, context):
         layout = self.layout
         
-        if len(context.scene.atom_cluster) == 0:
-            bpy.context.scene.atom_cluster.add()
-        
-        scn = context.scene.atom_cluster[0]
+        scn = context.scene.atom_cluster
 
         row = layout.row()
         row.label(text="Cluster properties")
@@ -176,7 +173,7 @@
 class CLASS_atom_cluster_Properties(bpy.types.PropertyGroup):
 
     def Callback_radius_type(self, context):
-        scn = bpy.context.scene.atom_cluster[0]
+        scn = bpy.context.scene.atom_cluster
         DEF_atom_cluster_radius_type(scn.radius_type,
                                      scn.radius_how,)
 
@@ -259,7 +256,7 @@
     bl_description = "Load the cluster"
 
     def execute(self, context):
-        scn    = context.scene.atom_cluster[0]
+        scn    = context.scene.atom_cluster
 
         add_mesh_cluster.DEF_atom_read_atom_data()
         del add_mesh_cluster.ATOM_CLUSTER_ALL_ATOMS[:]
@@ -448,7 +445,7 @@
     bl_description = "Increase the radii of the atoms"
 
     def execute(self, context):
-        scn = bpy.context.scene.atom_cluster[0]
+        scn = bpy.context.scene.atom_cluster
         DEF_atom_cluster_radius_all(
                 scn.radius_all,
                 scn.radius_how,)
@@ -462,7 +459,7 @@
     bl_description = "Decrease the radii of the atoms"
 
     def execute(self, context):
-        scn = bpy.context.scene.atom_cluster[0]
+        scn = bpy.context.scene.atom_cluster
         DEF_atom_cluster_radius_all(
                 1.0/scn.radius_all,
                 scn.radius_how,)
@@ -512,13 +509,10 @@
 def DEF_menu_func(self, context):
     self.layout.operator(CLASS_ImportCluster.bl_idname, icon='PLUGIN')
 
-def register_atom_class():
-    bpy.types.Scene.atom_cluster = bpy.props.CollectionProperty(type=CLASS_atom_cluster_Properties)    
-    bpy.context.scene.atom_cluster.add()
-
 def register():
     bpy.utils.register_module(__name__)
-    register_atom_class()
+    bpy.types.Scene.atom_cluster = bpy.props.PointerProperty(type=
+                                                  CLASS_atom_cluster_Properties)    
     bpy.types.INFO_MT_mesh_add.append(DEF_menu_func)
     
 def unregister():



More information about the Bf-extensions-cvs mailing list