[PyKDE] [SOLVED]+[PATCH] Re: problem with icon image handling in designer

Hans-Peter Jansen hpj at urpla.net
Thu Oct 16 00:52:01 BST 2003


Hi Phil,

I got around this with the pyuic -embed option. Hrmf. Obviously, it 
produces a module, which can be included within a Python: comment.

Studying this module revealed a list based lookup of the images,
which involves a linear search. What do you think about this patch,
which tries to do this more elegantly:

--- pyuic3/embed.cpp.orig	2003-10-15 23:48:49.000000000 +0200
+++ pyuic3/embed.cpp	2003-10-15 23:49:58.000000000 +0200
@@ -185,11 +185,11 @@
     }
 
     if ( !list_image.isEmpty() ) {
-	out << indent << "embed_image_vec = [\n";
+	out << indent << "embed_image_dict = {\n";
 	++indent;
 	EmbedImage *e = list_image.first();
 	while ( e ) {
-	    out << indent << "["
+	    out << indent << "\"" << e->name << "\": ("
 		<< e->width << ","
 		<< e->height << ","
 		<< e->depth << ","
@@ -203,29 +203,29 @@
 	    else
 		out << "None,";
 	    if ( e->alpha )
-		out << "1,";
+		out << "1";
 	    else
-		out << "0,";
-	    out << "\"" << e->name << "\"],\n";
+		out << "0";
+	    out << "),\n";
 	    e = list_image.next();
 	}
 	--indent;
-	out << indent << "]\n";
+	out << indent << "}\n";
 
 	out << "\n"
 	    "\n"
 	    "def uic_findImage(name):\n";
 	++indent;
-	out << indent << "global embed_image_vec\n";
+	out << indent << "global embed_image_dict\n";
 	out << "\n";
+	out << indent << "iname = str(name)\n";
+	out << indent << "if embed_image_dict.has_key(iname):\n";
+	++indent;
 #ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
-	out << indent << "for (w,h,depth,data,comp,nrCol,colTab,alpha,iname) in embed_image_vec:" << endl;
+	out << indent << "w,h,depth,data,comp,nrCol,colTab,alpha = embed_image_dict[iname]" << endl;
 #else
-	out << indent << "for (w,h,depth,data,nrCol,colTab,alpha,iname) in embed_image_vec:" << endl;
+	out << indent << "w,h,depth,data,nrCol,colTab,alpha = embed_image_dict[iname]" << endl;
 #endif
-	++indent;
-	out << indent << "if iname == str(name):" << endl;
-	++indent;
 #ifndef QT_NO_IMAGE_COLLECTION_COMPRESSION
 	// Keep the data object alive until we have a deep copy of the image.
 	out << indent << "data = qUncompress(data).data()\n";
@@ -239,7 +239,6 @@
 	out << "\n";
 	out << indent << "return img\n";
 	--indent;
-	--indent;
 	out << endl;
 	out << indent << "return QImage()\n";
 	--indent;


Tested, work for me.

I think, putting some words into the docs about image handling with 
designer is indicated. Hopefully, I can put something together soon.

Pete

On Wednesday 15 October 2003 16:28, Hans-Peter Jansen wrote:
>
> Does anybody has an idea, how to solve this currently without
> hacking pyuic or the resulting python module?
>
> Pete




More information about the PyQt mailing list