Guys, thank you all for the advices. I've remade my addition in more universal way. Looks like all widgets which qt-desigener uses are from kdeui and kfile modules, so imports are just from them now. If it use another modules just little additions will need. At the moment all imports works nice but I suggest somebody make tests too.
   Attachment is a diff-patch like you asked.
--- kdepyuic.old        2006-02-12 12:55:57.000000000 +0300
+++ kdepyuic    2006-02-12 12:55:36.000000000 +0300
@@ -28,6 +28,7 @@
 # 2003/04/19: some minor bits from Hans-Peter Jansen, <[EMAIL PROTECTED]>
 
 import sys, getopt, os, os.path, string
+import kdeui, kfile
 
 #---------- globals ----------
 
@@ -140,9 +141,71 @@
 
         os.unlink (fn)
         os.rename (fn + '.tmp', fn)
-
+        
+    postFilter(fn)
     print fn + ' written'
 
+def makeWidgetsList(modName): # make list of widgets by module name
+    widgetsList = []
+    
+    if modName == "kdeui":
+        for item in dir(kdeui):
+            if not item.startswith("__"):
+                widgetsList.append(item)
+    elif modName == "kfile":
+        for item in dir(kfile):
+            if not item.startswith("__"):
+                widgetsList.append(item)
+                
+    return widgetsList
+
+def searchKDEWidgets(buff): # search all KDE widgets
+    modNames = ["kdeui", "kfile"]
+    fullImport = ""
+    
+    for mod in modNames:
+        modWidgets = makeWidgetsList(mod)
+        importStr = checkMod(mod, modWidgets, buff)
+        if importStr != "":
+            fullImport += importStr
+    
+    return fullImport
+    
+    
+def checkMod(mod, modWidgets, buff): # check widgets from one module
+    usedWidgets = []
+    modImport = ""
+    for widget in modWidgets:
+        if string.find(buff, widget + "(") != -1:
+            usedWidgets.append(widget)
+    if len(usedWidgets) > 0:
+        importStr = "from " + mod + " import "
+        for widget in usedWidgets:
+            importStr = importStr + widget + ", "
+        modImport = modImport + importStr[:-2] + "\n"
+    
+    return modImport
+
+def postFilter(fn): # main procedure for making KDE imports
+    m = open (fn, 'r')
+    n = open (fn + '.tmp', 'w')
+    buffList = m.readlines()
+    for num in range(8):
+        n.write(buffList[num])
+        num += 1
+    buff = ""
+    for str in buffList[9:]:
+        buff = buff + str
+
+    imp = searchKDEWidgets(buff)
+    if imp != "":
+        n.write(imp)
+    n.write(buff)
+    
+    n.close()
+    m.close()
+    os.unlink(fn)
+    os.rename(fn + '.tmp', fn)
 
 # --------- main ----------
 
_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to