-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuis.py
executable file
·48 lines (44 loc) · 1.32 KB
/
uis.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
#!/usr/bin/env python
import os
from subprocess import call
from PyQt5 import QtGui
import re
import inspect
import importlib
def loadDialog(name,dlg=None):
module=importlib.import_module('gen.'+name)
for name,obj in inspect.getmembers(module):
if name.startswith("Ui_"):
if not dlg:
dlg=QtGui.QDialog()
ui=obj()
ui.setupUi(dlg)
return dlg
def generate():
inputs = os.listdir('uis')
for uiName in inputs:
base=(os.path.splitext(uiName))[0]
inpath=os.path.join('uis',uiName)
outpath=os.path.join('gen',base+".py")
call(['pyuic4','-o',outpath,inpath])
dlg='dlg'
f=open(outpath,"r")
lines=f.readlines()
f.close()
for i in xrange(0,len(lines)):
line=lines[i]
if line.startswith('# Created'):
lines[i]='#\n'
if line.startswith("class Ui_"):
dlg=(re.split('\W+',line))[1]
dlg=dlg[3:]
p=line.find('self.')
if p>0:
sym=line[p+5:]
if not sym.startswith('retranslateUi'):
lines[i]=line.replace('self.',dlg+'.')
f=open(outpath,"w")
f.write(''.join(lines))
f.close()
if __name__=='__main__':
generate()