[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3944] contrib/py/scripts/addons/ io_mesh_xyz: Names of classes and functions were changed, according to the "Style Guide for

Clemens Barth barth at root-1.de
Fri Nov 9 20:55:00 CET 2012


Revision: 3944
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3944
Author:   blendphys
Date:     2012-11-09 19:54:56 +0000 (Fri, 09 Nov 2012)
Log Message:
-----------
Names of classes and functions were changed, according to the "Style Guide for 
Python Code" (http://www.python.org/dev/peps/pep-0008/) and the recent review
(http://codereview.appspot.com/6815052).

Blendphys

Modified Paths:
--------------
    contrib/py/scripts/addons/io_mesh_xyz/__init__.py
    contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py
    contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py

Modified: contrib/py/scripts/addons/io_mesh_xyz/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/__init__.py	2012-11-09 15:57:28 UTC (rev 3943)
+++ contrib/py/scripts/addons/io_mesh_xyz/__init__.py	2012-11-09 19:54:56 UTC (rev 3944)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2011-12-18
-#  Last modified                 : 2012-11-03
+#  Last modified                 : 2012-11-09
 #
 #  Acknowledgements 
 #  ================
@@ -49,10 +49,7 @@
     "category": "Import-Export"
 }
 
-import os
-import io
 import bpy
-import bmesh
 from bpy.types import Operator, Panel
 from bpy_extras.io_utils import ImportHelper, ExportHelper
 from bpy.props import (StringProperty,
@@ -69,7 +66,7 @@
 
 
 # This is the class for the file dialog.
-class CLASS_ImportXYZ(Operator, ImportHelper):
+class ImportXYZ(Operator, ImportHelper):
     bl_idname = "import_mesh.xyz"
     bl_label  = "Import XYZ (*.xyz)"
     bl_options = {'PRESET', 'UNDO'}
@@ -166,14 +163,14 @@
     def execute(self, context):
 
         import_xyz.ALL_FRAMES[:] = []
-        import_xyz.ATOM_XYZ_ELEMENTS[:] = []
+        import_xyz.ELEMENTS[:] = []
         import_xyz.STRUCTURE[:] = []
 
         # This is to determine the path.
         filepath_xyz = bpy.path.abspath(self.filepath)
 
         # Execute main routine
-        import_xyz.DEF_atom_xyz_main(
+        import_xyz.import_xyz(
                       self.use_mesh,
                       self.mesh_azimuth,
                       self.mesh_zenith,
@@ -189,14 +186,14 @@
         # Load frames                  
         if len(import_xyz.ALL_FRAMES) > 1 and self.use_frames:  
                   
-            import_xyz.DEF_atom_xyz_build_frames(self.images_per_key, 
-                                                 self.skip_frames)
+            import_xyz.build_frames(self.images_per_key, 
+                                    self.skip_frames)
         
         return {'FINISHED'}
         
 
 # This is the class for the file dialog of the exporter.
-class CLASS_ExportXYZ(Operator, ExportHelper):
+class ExportXYZ(Operator, ExportHelper):
     bl_idname = "export_mesh.xyz"
     bl_label  = "Export XYZ (*.xyz)"
     filename_ext = ".xyz"
@@ -218,30 +215,29 @@
         row.prop(self, "atom_xyz_export_type")
 
     def execute(self, context):
-        # This is in order to solve this strange 'relative path' thing.
-        export_xyz.ATOM_XYZ_FILEPATH = bpy.path.abspath(self.filepath)
-        export_xyz.DEF_atom_xyz_export(self.atom_xyz_export_type)
+        export_xyz.export_xyz(self.atom_xyz_export_type, 
+                              bpy.path.abspath(self.filepath))
 
         return {'FINISHED'}
 
 
 # The entry into the menu 'file -> import'
-def DEF_menu_func(self, context):
-    self.layout.operator(CLASS_ImportXYZ.bl_idname, text="XYZ (.xyz)")
+def menu_func(self, context):
+    self.layout.operator(ImportXYZ.bl_idname, text="XYZ (.xyz)")
 
 # The entry into the menu 'file -> export'
-def DEF_menu_func_export(self, context):
-    self.layout.operator(CLASS_ExportXYZ.bl_idname, text="XYZ (.xyz)")
+def menu_func_export(self, context):
+    self.layout.operator(ExportXYZ.bl_idname, text="XYZ (.xyz)")
 
 def register():
     bpy.utils.register_module(__name__)
-    bpy.types.INFO_MT_file_import.append(DEF_menu_func)
-    bpy.types.INFO_MT_file_export.append(DEF_menu_func_export) 
+    bpy.types.INFO_MT_file_import.append(menu_func)
+    bpy.types.INFO_MT_file_export.append(menu_func_export) 
     
 def unregister():
     bpy.utils.unregister_module(__name__)
-    bpy.types.INFO_MT_file_import.remove(DEF_menu_func)
-    bpy.types.INFO_MT_file_export.remove(DEF_menu_func_export)
+    bpy.types.INFO_MT_file_import.remove(menu_func)
+    bpy.types.INFO_MT_file_export.remove(menu_func_export)
 
 if __name__ == "__main__":
 

Modified: contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py	2012-11-09 15:57:28 UTC (rev 3943)
+++ contrib/py/scripts/addons/io_mesh_xyz/export_xyz.py	2012-11-09 19:54:56 UTC (rev 3944)
@@ -17,30 +17,17 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import io
-import math
-import os
-import copy
-from math import pi, cos, sin
-from mathutils import Vector, Matrix
-from copy import copy
-
 from . import import_xyz
 
-ATOM_XYZ_FILEPATH = ""
-ATOM_XYZ_XYZTEXT  = (  "This XYZ file has been created with Blender "
-                       "and the addon Atomic Blender - XYZ. "
-                       "For more details see: wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/XYZ\n")
 
-
-class CLASS_atom_xyz_atoms_export(object):  
+class AtomsExport(object):  
     __slots__ = ('element', 'location')
     def __init__(self, element, location):
         self.element  = element
         self.location = location
 
 
-def DEF_atom_xyz_export(obj_type):
+def export_xyz(obj_type, filepath_xyz):
 
     list_atoms = []
     counter = 0
@@ -53,7 +40,7 @@
             continue 
        
         name = ""
-        for element in import_xyz.ATOM_XYZ_ELEMENTS_DEFAULT:
+        for element in import_xyz.ELEMENTS_DEFAULT:
             if element[1] in obj.name:
                 if element[2] == "Vac":
                     name = "X"
@@ -69,21 +56,20 @@
         if len(obj.children) != 0:
             for vertex in obj.data.vertices:
                 location = obj.matrix_world*vertex.co
-                list_atoms.append(CLASS_atom_xyz_atoms_export(
-                                                       name,
-                                                       location))
+                list_atoms.append(AtomsExport(name, location))
                 counter += 1                                       
         else:
             if not obj.parent:
                 location = obj.location
-                list_atoms.append(CLASS_atom_xyz_atoms_export(
-                                                       name,
-                                                       location))                                   
+                list_atoms.append(AtomsExport(name, location))                                   
                 counter += 1                                               
 
-    xyz_file_p = open(ATOM_XYZ_FILEPATH, "w")
+    xyz_file_p = open(filepath_xyz, "w")
     xyz_file_p.write("%d\n" % counter)
-    xyz_file_p.write(ATOM_XYZ_XYZTEXT)
+    xyz_file_p.write("This XYZ file has been created with Blender "
+                     "and the addon Atomic Blender - XYZ. "
+                     "For more details see: wiki.blender.org/index.php/"
+                     "Extensions:2.6/Py/Scripts/Import-Export/XYZ\n")
 
     for i, atom in enumerate(list_atoms):
         string = "%3s%15.5f%15.5f%15.5f\n" % (

Modified: contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-11-09 15:57:28 UTC (rev 3943)
+++ contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py	2012-11-09 19:54:56 UTC (rev 3944)
@@ -17,10 +17,8 @@
 # ##### END GPL LICENSE BLOCK #####
 
 import bpy
-import io
-import math
 import os
-from math import pi, cos, sin
+from math import pi, cos, sin, sqrt
 from mathutils import Vector, Matrix
 
 # -----------------------------------------------------------------------------
@@ -38,7 +36,7 @@
 # charge states for any atom are listed, if existing.
 # The list is fixed and cannot be changed ... (see below)
 
-ATOM_XYZ_ELEMENTS_DEFAULT = (
+ELEMENTS_DEFAULT = (
 ( 1,      "Hydrogen",        "H", (  1.0,   1.0,   1.0), 0.32, 0.32, 0.79 , -1 , 1.54 ),
 ( 2,        "Helium",       "He", ( 0.85,   1.0,   1.0), 0.93, 0.93, 0.49 ),
 ( 3,       "Lithium",       "Li", (  0.8,  0.50,   1.0), 1.23, 1.23, 2.05 ,  1 , 0.68 ),
@@ -150,15 +148,15 @@
 # This list here contains all data of the elements and will be used during
 # runtime. It is a list of classes.
 # During executing Atomic Blender, the list will be initialized with the fixed
-# data from above via the class structure below (CLASS_atom_xyz_Elements). We
+# data from above via the class structure below (ElementProp). We
 # have then one fixed list (above), which will never be changed, and a list of
 # classes with same data. The latter can be modified via loading a separate
 # custom data file for instance.
-ATOM_XYZ_ELEMENTS = []
+ELEMENTS = []
 
 # This is the list, which contains all atoms of all frames! Each item is a 
 # list which contains the atoms of a single frame. It is a list of  
-# 'CLASS_atom_xyz_atom'.
+# 'AtomProp'.
 ALL_FRAMES = []
 
 # A list of ALL balls which are put into the scene
@@ -166,7 +164,7 @@
 
 
 # This is the class, which stores the properties for one element.
-class CLASS_atom_xyz_Elements(object):
+class ElementProp(object):
     __slots__ = ('number', 'name', 'short_name', 'color', 'radii', 'radii_ionic')
     def __init__(self, number, name, short_name, color, radii, radii_ionic):
         self.number = number
@@ -177,7 +175,7 @@
         self.radii_ionic = radii_ionic
 
 # This is the class, which stores the properties of one atom.
-class CLASS_atom_xyz_atom(object):  
+class AtomProp(object):  
     __slots__ = ('element', 'name', 'location', 'radius', 'color', 'material')
     def __init__(self, element, name, location, radius, color, material):
         self.element = element
@@ -191,11 +189,11 @@
 # -----------------------------------------------------------------------------
 #                                                           Some basic routines        
 
-def DEF_atom_xyz_read_elements():
+def read_elements():
 
-    ATOM_XYZ_ELEMENTS[:] = []
+    ELEMENTS[:] = []
 
-    for item in ATOM_XYZ_ELEMENTS_DEFAULT:
+    for item in ELEMENTS_DEFAULT:
 
         # All three radii into a list
         radii = [item[4],item[5],item[6]]
@@ -203,21 +201,21 @@
         # empty list.
         radii_ionic = []
 
-        li = CLASS_atom_xyz_Elements(item[0],item[1],item[2],item[3],
+        li = ElementProp(item[0],item[1],item[2],item[3],
                                      radii,radii_ionic)
-        ATOM_XYZ_ELEMENTS.append(li)
+        ELEMENTS.append(li)
 
 
 # filepath_pdb: path to pdb file
 # radiustype  : '0' default
 #               '1' atomic radii
 #               '2' van der Waals

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list