forked from lukasmonk/lucaschess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyqt2pyside.py
108 lines (99 loc) · 3.22 KB
/
pyqt2pyside.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: latin-1 -*-
import sys
select = raw_input( "Select GUI pyqt or pyside : " )
if select == "pyqt" :
siPyside = False
elif select == "pyside" :
siPyside = True
else :
print "Goodbye"
sys.exit()
# Especiales ----------------------------------------------------------------------------------------------
def hazRoot( siPyside ) :
for fich in ( "lucas.py", ) :
f = open( fich, "rb")
txt = ""
for linea in f :
if siPyside :
if linea.startswith( "import sip" ) or linea.startswith( "sip.setapi" ) :
linea = "#" + linea
else :
if linea.startswith( "#import sip" ) or linea.startswith( "#sip.setapi" ) :
linea = linea.replace( "#", "" )
txt += linea
f.close()
q = open( fich, "wb")
q.write( txt )
q.close()
def hazQTUtil2( siPyside ) :
fich = "Code/QT/QTUtil2.py"
f = open( fich, "rb")
txt = ""
for linea in f :
if "if resp : #+pyside" in linea :
if siPyside :
linea = " if resp : #+pyside\n"
else :
linea = " #if resp : #+pyside\n"
elif "resp = resp[0] #+pyside" in linea :
if siPyside :
linea = " resp = resp[0] #+pyside\n"
else :
linea = " #resp = resp[0] #+pyside\n"
txt += linea
f.close()
q = open( fich, "wb")
q.write( txt )
q.close()
def hazInfo( siPyside ) :
fich = "Code/QT/Info.py"
f = open( fich, "rb")
txt = ""
for linea in f :
if "ABOUT_GUI" in linea :
if siPyside :
linea = ' ( _( "ABOUT_GUI" ), "PySide - LGPL", "http://www.pyside.org/" ),\n'
else :
linea = ' ( _( "ABOUT_GUI" ), "PyQt4 - GPL", "http://www.riverbankcomputing.co.uk" ),\n'
txt += linea
f.close()
q = open( fich, "wb")
q.write( txt )
q.close()
# Fin especiales ----------------------------------------------------------------------------------------------
import os, os.path
import glob
import datetime, time
import shutil
import win32file, win32con
def hazFich( fichero, siPyside ) :
if fichero.endswith( ".py" ):
print fichero
li = []
f = open( fichero, "rb" )
vpyqt = "from PyQt4 import"
vpyside = "from PySide import"
for linea in f :
if siPyside :
if linea.startswith( vpyqt ) :
linea = linea.replace( vpyqt, vpyside )
else :
if linea.startswith( vpyside ) :
linea = linea.replace( vpyside, vpyqt )
li.append( linea )
f.close()
q = open( fichero, "wb" )
q.write( "".join(li))
q.close()
#~ ############################################################################################
def hazDir( carpeta, siPyside ) :
for fd in os.listdir( carpeta ) :
fd = carpeta + "/" + fd
if os.path.isfile( fd ) :
hazFich( fd, siPyside )
hazRoot(siPyside)
hazQTUtil2(siPyside)
hazInfo(siPyside)
hazDir( "Code", siPyside )
hazDir( "Code/QT", siPyside )
# hazFich( "mosca.py", siPyside )