-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand.py
More file actions
103 lines (77 loc) · 2.82 KB
/
command.py
File metadata and controls
103 lines (77 loc) · 2.82 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: command
:synopsis: Some command used to build pyqt.
.. moduleauthor:: Answeror <answeror@gmail.com>
These code was borrowed from `https://bitbucket.org/jbmohler/pyhacc/src/b0ad3a0b1e58/setup.py`_.
"""
import os
import distutils
from distutils.core import Command
from cx_Freeze import build
def needsupdate(src, targ):
return not os.path.exists(targ) or os.path.getmtime(src) > os.path.getmtime(targ)
class PySideUiBuild:
def qrc(self, qrc_file, py_file):
import subprocess
rccprocess = subprocess.Popen(['pyside-rcc', qrc_file, '-py3', '-o', py_file])
rccprocess.wait()
def uic(self, ui_file, py_file):
import subprocess
rccprocess = subprocess.Popen(['pyside-uic', ui_file, '-o', py_file])
rccprocess.wait()
class PyQt4UiBuild:
def qrc(self, qrc_file, py_file):
import subprocess
rccprocess = subprocess.Popen(['pyrcc4', qrc_file, '-py3', '-o', py_file])
rccprocess.wait()
def uic(self, ui_file, py_file):
from PyQt4 import uic
fp = open(py_file, 'w')
uic.compileUi(ui_file, fp)
fp.close()
class QtUiBuild(Command, PyQt4UiBuild):
description = "build Python modules from Qt Designer .ui files"
user_options = []
ui_files = []
qrc_files = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def compile_ui(self, ui_file, py_file):
if not needsupdate(ui_file, py_file):
return
print("compiling %s -> %s" % (ui_file, py_file))
try:
self.uic(ui_file, py_file)
except Exception as e:
raise distutils.errors.DistutilsExecError('Unable to compile user interface %s' % str(e))
return
def compile_qrc(self, qrc_file, py_file):
if not needsupdate(qrc_file, py_file):
return
print("compiling %s -> %s" % (qrc_file, py_file))
try:
self.qrc(qrc_file, py_file)
except Exception as e:
raise distutils.errors.DistutilsExecError('Unable to compile resource file %s' % str(e))
return
def run(self):
for f in self.ui_files:
dir, basename = os.path.split(f)
self.compile_ui(f, os.path.join(dir, "ui_" + basename.replace(".ui", ".py")))
for f in self.qrc_files:
dir, basename = os.path.split(f)
self.compile_qrc(f, os.path.join(dir, basename.replace(".qrc", "_rc.py")))
QtUiBuild.ui_files = []
QtUiBuild.qrc_files = [os.path.join(dir, f) \
for dir in ['.'] \
for f in os.listdir(dir) if f.endswith('.qrc')]
class Build(build):
sub_commands = [('build_ui', None)] + build.sub_commands
cmds = {
'build': Build,
'build_ui': QtUiBuild,
}