[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyKDE] kdepyuic from PyKDE-3.3.2
From: Hans-Peter Jansen <hpj () urpla ! net>
Date: 2003-04-19 14:01:55
[Download RAW message or body]
Hi Jim,
today I started to play with qt designer and kde widgets. During
this course, I stumbled across some pretty obvious flaws in kdepyuic
(besides being white space damaged). While at it, I've applied
a KDatePicker ctor mangling in order to satisfy KDE's needs.
Attached:
kdepyuic.diff
kdepyuic-ws.diff (same with my prefered white spacing)
kdeform1.ui{.h} (which I played with)
Let me know, what do you think about it
["kdepyuic-ws.diff" (text/x-diff)]
--- kdepyuic.orig 2003-04-19 15:11:00.000000000 +0200
+++ kdepyuic 2003-04-19 15:56:25.000000000 +0200
@@ -33,111 +33,113 @@
FALSE = 0
TRUE = not FALSE
addApp = TRUE
addImport = TRUE
pyuicPath = "pyuic"
-filename = ''
+filename = ""
# --------- support functions ----------
def getOptions ():
- global filename
+ global filename
- arglist = sys.argv [1:]
- shortOptions = "a i p:"
- longOptions = "noapp noimport pyuic="
-
- try:
- optlist, args = getopt.getopt (arglist, shortOptions, longOptions)
- except getopt.GetoptError:
- optlist = []
- args = []
+ opterr = 0
+ shortOptions = "aip:"
+ longOptions = "noapp noimport pyuic="
+
+ try:
+ optlist, args = getopt.getopt (sys.argv [1:], shortOptions, longOptions)
+ except getopt.GetoptError:
+ opterr = 1
+ optlist = []
+ args = []
- if (optlist == []) or (len (args) != 1):
- print """\nUsage:
-
- filename = args [0]
+ if opterr or (len (args) != 1):
+ print """\nUsage:
kdepyuic [options] filename.ui
Options:
- -a, --noapp Don't add KApplication code
- -i, --noimport Don't add kdecore, kdeui import statements
- -p, --pyuic Path to pyuic program
+ -a, --noapp Don't add KApplication code
+ -i, --noimport Don't add kdecore, kdeui import statements
+ -p, --pyuic Path to pyuic program
"""
- return FALSE
+ return FALSE
- return checkOptions (optlist)
+ filename = args[0]
-def checkOptions (optlist):
- global addApp, addImport, pyuicPath
+ return checkOptions (optlist)
- print 'checking options'
+def checkOptions (optlist):
+ global addApp, addImport, pyuicPath
- for pair in optlist:
- if (pair [0] == '--noapp') or (pair [0] == '-a'):
- addApp = FALSE
+ for pair in optlist:
+ if (pair [0] == '--noapp') or (pair [0] == '-a'):
+ addApp = FALSE
- elif (pair [0] == '--noimport') or (pair [0] == '-i'):
- addImport = FALSE
+ elif (pair [0] == '--noimport') or (pair [0] == '-i'):
+ addImport = FALSE
- elif (pair [0] == '--pyuic') or (pair [0] == '-p'):
- pyuicPath = pair [1]
+ elif (pair [0] == '--pyuic') or (pair [0] == '-p'):
+ pyuicPath = pair [1]
# --------- operations ----------
-def addimport (f):
- f.write ('from kdecore import KCmdLineArgs, KApplication\n')
- f.write ('from kdeui import *\n\n')
+def addimport (n):
+ n.write ('from kdecore import KCmdLineArgs, KApplication\n')
+ n.write ('from kdeui import *\n\n')
-def addapp (indent, f):
- n.write (indent + 'appname = ""\n')
- n.write (indent + 'description = ""\n')
- n.write (indent + 'version = ""\n'
- n.write ('\n')
- n.write (indent + 'KCmdLineArgs.init (sys.argv, appname, description, version)\n')
- n.write (indent + 'a = KApplication ()\n\n')
+def addapp (indent, n):
+ n.write (indent + 'appname = ""\n')
+ n.write (indent + 'description = ""\n')
+ n.write (indent + 'version = ""\n')
+ n.write ('\n')
+ n.write (indent + 'KCmdLineArgs.init (sys.argv, appname, description, version)\n')
+ n.write (indent + 'a = KApplication ()\n\n')
def doPyuic ():
- fn = os.splitext (filename) [0] + '.py'
+ fn = os.path.splitext (os.path.basename(filename)) [0] + '.py'
- if addApp:
- opts = ' -x -o '
- else:
- opts = ' -o '
-
- if os.system (pyuicPath + opts + fn + filename) != 0:
- sys.exit (-1)
-
- if addApp or addImport:
- m = open (fn, 'r')
- n = open (fn + '.tmp', 'w')
-
- buff = m.readlines ()
-
- for line in buff:
- if addImport and (string.strip (line) == 'from qt import *'):
- n.write (line)
- addimport (line)
- elif addApp and (string.strip (line) == 'a = QApplication(sys.argv)'):
- indent = 0
- while line [indent] in string.whitespace:
- indent = indent + 1
- addapp (indent, n)
- else:
- n.write (line)
+ if addApp:
+ opts = ' -x -o '
+ else:
+ opts = ' -o '
+
+ if os.system (pyuicPath + opts + fn + ' ' + filename) != 0:
+ sys.exit (-1)
+
+ if addApp or addImport:
+ m = open (fn, 'r')
+ n = open (fn + '.tmp', 'w')
+
+ buff = m.readlines ()
+
+ for line in buff:
+ if addImport and (string.strip (line) == 'from qt import *'):
+ n.write (line)
+ addimport (n)
+ elif addApp and (string.strip (line) == 'a = QApplication(sys.argv)'):
+ indent = 0
+ while line [indent] in string.whitespace:
+ indent = indent + 1
+ addapp (line[:indent], n)
+ elif string.find(line, " = KDatePicker(") != -1:
+ o = string.find(line, ",")
+ n.write (line[:o] + ",QDate.currentDate()" + line[o:])
+ else:
+ n.write (line)
- m.close ()
- n.close ()
+ m.close ()
+ n.close ()
- os.unlink (fn)
- os,rename (fn + '.tmp', fn)
+ os.unlink (fn)
+ os.rename (fn + '.tmp', fn)
# --------- main ----------
getOptions ()
["kdepyuic.diff" (text/x-diff)]
--- kdepyuic.orig 2003-04-19 15:11:00.000000000 +0200
+++ kdepyuic 2003-04-19 15:15:56.000000000 +0200
@@ -33,49 +33,48 @@
FALSE = 0
TRUE = not FALSE
addApp = TRUE
addImport = TRUE
pyuicPath = "pyuic"
-filename = ''
+filename = ""
# --------- support functions ----------
def getOptions ():
global filename
- arglist = sys.argv [1:]
- shortOptions = "a i p:"
+ opterr = 0
+ shortOptions = "aip:"
longOptions = "noapp noimport pyuic="
try:
- optlist, args = getopt.getopt (arglist, shortOptions, longOptions)
+ optlist, args = getopt.getopt (sys.argv [1:], shortOptions, longOptions)
except getopt.GetoptError:
+ opterr = 1
optlist = []
args = []
- if (optlist == []) or (len (args) != 1):
+ if opterr or (len (args) != 1):
print """\nUsage:
- filename = args [0]
-
kdepyuic [options] filename.ui
Options:
-a, --noapp Don't add KApplication code
-i, --noimport Don't add kdecore, kdeui import statements
-p, --pyuic Path to pyuic program
"""
return FALSE
+ filename = args[0]
+
return checkOptions (optlist)
def checkOptions (optlist):
global addApp, addImport, pyuicPath
- print 'checking options'
-
for pair in optlist:
if (pair [0] == '--noapp') or (pair [0] == '-a'):
addApp = FALSE
elif (pair [0] == '--noimport') or (pair [0] == '-i'):
@@ -86,33 +85,33 @@
# --------- operations ----------
-def addimport (f):
- f.write ('from kdecore import KCmdLineArgs, KApplication\n')
- f.write ('from kdeui import *\n\n')
+def addimport (n):
+ n.write ('from kdecore import KCmdLineArgs, KApplication\n')
+ n.write ('from kdeui import *\n\n')
-def addapp (indent, f):
+def addapp (indent, n):
n.write (indent + 'appname = ""\n')
n.write (indent + 'description = ""\n')
- n.write (indent + 'version = ""\n'
+ n.write (indent + 'version = ""\n')
n.write ('\n')
n.write (indent + 'KCmdLineArgs.init (sys.argv, appname, description, version)\n')
n.write (indent + 'a = KApplication ()\n\n')
def doPyuic ():
- fn = os.splitext (filename) [0] + '.py'
+ fn = os.path.splitext (os.path.basename(filename)) [0] + '.py'
if addApp:
opts = ' -x -o '
else:
opts = ' -o '
- if os.system (pyuicPath + opts + fn + filename) != 0:
+ if os.system (pyuicPath + opts + fn + ' ' + filename) != 0:
sys.exit (-1)
if addApp or addImport:
m = open (fn, 'r')
n = open (fn + '.tmp', 'w')
@@ -120,24 +119,27 @@
buff = m.readlines ()
for line in buff:
if addImport and (string.strip (line) == 'from qt import *'):
n.write (line)
- addimport (line)
+ addimport (n)
elif addApp and (string.strip (line) == 'a = QApplication(sys.argv)'):
indent = 0
while line [indent] in string.whitespace:
indent = indent + 1
- addapp (indent, n)
+ addapp (line[:indent], n)
+ elif string.find(line, " = KDatePicker(") != -1:
+ o = string.find(line, ",")
+ n.write (line[:o] + ",QDate.currentDate()" + line[o:])
else:
n.write (line)
m.close ()
n.close ()
os.unlink (fn)
- os,rename (fn + '.tmp', fn)
+ os.rename (fn + '.tmp', fn)
# --------- main ----------
getOptions ()
["kdeform1.ui.h" (text/x-chdr)]
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename slots use Qt Designer which will
** update this file, preserving your code. Create an init() slot in place of
** a constructor, and a destroy() slot in place of a destructor.
*****************************************************************************/
void Form1::PushButton1_clicked()
{
qApp.exit(0)
}
["kdeform1.ui" (application/x-designer)]
_______________________________________________
PyKDE mailing list PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic