[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31656] trunk/blender: various utf8 compatibility fixes

Campbell Barton ideasman42 at gmail.com
Mon Aug 30 10:28:51 CEST 2010


Revision: 31656
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31656
Author:   campbellbarton
Date:     2010-08-30 10:28:48 +0200 (Mon, 30 Aug 2010)

Log Message:
-----------
various utf8 compatibility fixes
- OBJ import/export now work with non utf8 paths. (all exporters and importers need changes like this)
- strip non utf8 chars from new ID blocks (also applies to renaming)
- set the file rename button to allow non-utf8 chars. 

Modified Paths:
--------------
    trunk/blender/release/scripts/io/export_obj.py
    trunk/blender/release/scripts/io/import_scene_obj.py
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/release/scripts/io/export_obj.py
===================================================================
--- trunk/blender/release/scripts/io/export_obj.py	2010-08-30 08:23:48 UTC (rev 31655)
+++ trunk/blender/release/scripts/io/export_obj.py	2010-08-30 08:28:48 UTC (rev 31656)
@@ -122,7 +122,7 @@
                     try:
                         filepath = copy_image(mtex.texture.image)
 #                       filepath = mtex.texture.image.filepath.split('\\')[-1].split('/')[-1]
-                        file.write('map_Kd %s\n' % filepath) # Diffuse mapping image
+                        file.write('map_Kd %s\n' % repr(filepath)[1:-1]) # Diffuse mapping image
                         break
                     except:
                         # Texture has no image though its an image type, best ignore.
@@ -332,7 +332,7 @@
         return ret
 
 
-    print('OBJ Export path: "%s"' % filepath)
+    print('OBJ Export path: %r' % filepath)
     temp_mesh_name = '~tmp-mesh'
 
     time1 = time.clock()
@@ -342,13 +342,13 @@
     file = open(filepath, "w")
 
     # Write Header
-    file.write('# Blender v%s OBJ File: %s\n' % (bpy.app.version_string, bpy.data.filepath.split('/')[-1].split('\\')[-1] ))
+    file.write('# Blender v%s OBJ File: %r\n' % (bpy.app.version_string, os.path.basename(bpy.data.filepath)))
     file.write('# www.blender.org\n')
 
     # Tell the obj file what material file to use.
     if EXPORT_MTL:
-        mtlfilepath = '%s.mtl' % '.'.join(filepath.split('.')[:-1])
-        file.write('mtllib %s\n' % ( mtlfilepath.split('\\')[-1].split('/')[-1] ))
+        mtlfilepath = os.path.splitext(filepath)[0] + ".mtl"
+        file.write('mtllib %s\n' % repr(os.path.basename(mtlfilepath))[1:-1]) # filepath can contain non utf8 chars, use repr
 
     if EXPORT_ROTX90:
         mat_xrot90= mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')
@@ -864,7 +864,7 @@
     # List of operator properties, the attributes will be assigned
     # to the class instance from the operator settings before calling.
 
-    filepath = StringProperty(name="File Path", description="Filepath used for exporting the OBJ file", maxlen= 1024, default= "")
+    filepath = StringProperty(name="File Path", description="Filepath used for exporting the OBJ file", maxlen= 1024, default= "", subtype='FILE_PATH')
     check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'})
 
     # context group

Modified: trunk/blender/release/scripts/io/import_scene_obj.py
===================================================================
--- trunk/blender/release/scripts/io/import_scene_obj.py	2010-08-30 08:23:48 UTC (rev 31655)
+++ trunk/blender/release/scripts/io/import_scene_obj.py	2010-08-30 08:28:48 UTC (rev 31656)
@@ -892,7 +892,7 @@
     This function passes the file and sends the data off
         to be split into objects and then converted into mesh objects
     '''
-    print('\nimporting obj "%s"' % filepath)
+    print('\nimporting obj %r' % filepath)
 
     if SPLIT_OBJECTS or SPLIT_GROUPS or SPLIT_MATERIALS:
         POLYGROUPS = False
@@ -935,7 +935,7 @@
     # so we need to know weather
     context_multi_line= ''
 
-    print('\tparsing obj file "%s"...' % filepath)
+    print("\tparsing obj file...")
     time_sub= time.time()
 # 	time_sub= sys.time()
 
@@ -1220,7 +1220,7 @@
 # 	time_new= sys.time()
 
     print('%.4f sec' % (time_new-time_sub))
-    print('finished importing: "%s" in %.4f sec.' % (filepath, (time_new-time_main)))
+    print('finished importing: %r in %.4f sec.' % (filepath, (time_new-time_main)))
 
 
 DEBUG= True
@@ -1467,7 +1467,7 @@
     # to the class instance from the operator settings before calling.
 
 
-    filepath = StringProperty(name="File Path", description="Filepath used for importing the OBJ file", maxlen= 1024, default= "")
+    filepath = StringProperty(name="File Path", description="Filepath used for importing the OBJ file", maxlen= 1024, default= "", subtype='FILE_PATH')
 
     CREATE_SMOOTH_GROUPS = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default= True)
     CREATE_FGONS = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default= True)

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c	2010-08-30 08:23:48 UTC (rev 31655)
+++ trunk/blender/source/blender/blenkernel/intern/library.c	2010-08-30 08:28:48 UTC (rev 31656)
@@ -1185,8 +1185,15 @@
 	 * easier to assign each time then to check if its needed */
 	name[sizeof(name)-1]= 0;
 
-	if(name[0] == '\0')
+	if(name[0] == '\0') {
+		/* disallow empty names */
 		strcpy(name, ID_FALLBACK_NAME);
+	}
+	else {
+		/* disallow non utf8 chars,
+		 * the interface checks for this but new ID's based on file names dont */
+		BLI_utf8_invalid_strip(name, strlen(name));
+	}
 
 	result = check_for_dupid(lb, id, name);
 	strcpy(id->name+2, name);
@@ -1377,8 +1384,9 @@
 			text[4]= 0;
 		}
 	}
-	else
-		strcpy(text, "");
+	else {
+		text[0]= '\0';
+	}
 }
 
 void rename_id(ID *id, char *name)

Modified: trunk/blender/source/blender/editors/space_file/file_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_draw.c	2010-08-30 08:23:48 UTC (rev 31655)
+++ trunk/blender/source/blender/editors/space_file/file_draw.c	2010-08-30 08:28:48 UTC (rev 31656)
@@ -544,6 +544,7 @@
 			uiBut *but = uiDefBut(block, TEX, 1, "", spos, sy-layout->tile_h-3, 
 				but_width, layout->textheight*2, sfile->params->renameedit, 1.0f, (float)sizeof(sfile->params->renameedit),0,0,"");
 			uiButSetRenameFunc(but, renamebutton_cb, file);
+			uiButSetFlag(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
 			if ( 0 == uiButActiveOnly(C, block, but)) {
 				file->flags &= ~EDITING;
 			}

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-08-30 08:23:48 UTC (rev 31655)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-08-30 08:28:48 UTC (rev 31656)
@@ -233,7 +233,7 @@
 	}
 }
 
-static PyObject *py_safe_byte_to_unicode(char *str)
+static PyObject *py_safe_byte_to_unicode(const char *str)
 {
 	PyObject *result= PyUnicode_FromString(str);
 	if(result) {





More information about the Bf-blender-cvs mailing list