summaryrefslogtreecommitdiff
path: root/contrib/QDarkStyleSheet/script/process_ui.py
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2019-03-11 14:19:23 +0100
committerChristoph Berg <christoph.berg@credativ.de>2019-03-11 14:19:23 +0100
commit200de07a95209a55d6019ba87f0abc78d302bf4c (patch)
tree3b2922eb5d89b01ad214cae492e871c3bfb5df18 /contrib/QDarkStyleSheet/script/process_ui.py
parente0737c56c1e384e05064a0c6e1ac46979371041b (diff)
New upstream version 2.0.1+repackupstream/2.0.1+repack
Diffstat (limited to 'contrib/QDarkStyleSheet/script/process_ui.py')
-rwxr-xr-xcontrib/QDarkStyleSheet/script/process_ui.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/contrib/QDarkStyleSheet/script/process_ui.py b/contrib/QDarkStyleSheet/script/process_ui.py
new file mode 100755
index 00000000..bbe11545
--- /dev/null
+++ b/contrib/QDarkStyleSheet/script/process_ui.py
@@ -0,0 +1,124 @@
+# -*- coding: utf-8 -*-
+"""Script to process UI files (convert .ui to .py).
+
+It compiles .ui files to be used with PyQt4, PyQt5, PySide, QtPy, PyQtGraph.
+You just need to run (it has default values) from script folder.
+
+To run this script you need to have these tools available on system:
+
+ - pyuic4 for PyQt4 and PyQtGraph
+ - pyuic5 for PyQt5 and QtPy
+ - pyside-uic for Pyside
+ - pyside2-uic for Pyside2
+
+Links to understand those tools:
+
+ - pyuic4: http://pyqt.sourceforge.net/Docs/PyQt4/designer.html#pyuic4
+ - pyuic5: http://pyqt.sourceforge.net/Docs/PyQt5/designer.html#pyuic5
+ - pyside-uic: https://www.mankier.com/1/pyside-uic
+ - pyside2-uic: https://wiki.qt.io/Qt_for_Python_UiFiles (Documentation Incomplete)
+
+"""
+
+from __future__ import absolute_import, print_function
+
+import argparse
+import glob
+import os
+import sys
+from subprocess import call
+
+
+def main(arguments):
+ """Process UI files."""
+ parser = argparse.ArgumentParser(description=__doc__,
+ formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.add_argument('--ui_dir',
+ default='../example/ui',
+ type=str,
+ help="UI files directory, relative to current directory.",)
+ parser.add_argument('--create',
+ default='all',
+ choices=['pyqt', 'pyqt5', 'pyside', 'pyside2', 'qtpy', 'pyqtgraph', 'all'],
+ type=str,
+ help="Choose which one would be generated.")
+
+ args = parser.parse_args(arguments)
+
+ print('Changing directory to: ', args.ui_dir)
+ os.chdir(args.ui_dir)
+
+ print('Converting .ui to .py ...')
+
+ for ui_file in glob.glob('*.ui'):
+ # get name without extension
+ filename = os.path.splitext(ui_file)[0]
+ print(filename, '...')
+ ext = '.py'
+
+ # creating names
+ py_file_pyqt5 = filename + '_pyqt5_ui' + ext
+ py_file_pyqt = filename + '_pyqt_ui' + ext
+ py_file_pyside = filename + '_pyside_ui' + ext
+ py_file_pyside2 = filename + '_pyside2_ui' + ext
+ py_file_qtpy = filename + '_qtpy_ui' + ext
+ py_file_pyqtgraph = filename + '_pyqtgraph_ui' + ext
+
+ # calling external commands
+ if args.create in ['pyqt', 'pyqtgraph', 'all']:
+ try:
+ call(['pyuic4', '--from-imports', ui_file, '-o', py_file_pyqt])
+ except Exception as er:
+ print("You must install pyuic4 %s" % str(er))
+ else:
+ print("Compiling using pyuic4 ...")
+
+ if args.create in ['pyqt5', 'qtpy', 'all']:
+ try:
+ call(['pyuic5', '--from-imports', ui_file, '-o', py_file_pyqt5])
+ except Exception as er:
+ print("You must install pyuic5 %s" % str(er))
+ else:
+ print("Compiling using pyuic5 ...")
+
+ if args.create in ['pyside', 'all']:
+ try:
+ call(['pyside-uic', '--from-imports', ui_file, '-o', py_file_pyside])
+ except Exception as er:
+ print("You must install pyside-uic %s" % str(er))
+ else:
+ print("Compiling using pyside-uic ...")
+
+ if args.create in ['pyside2', 'all']:
+ try:
+ call(['pyside2-uic', '--from-imports', ui_file, '-o', py_file_pyside2])
+ except Exception as er:
+ print("You must install pyside2-uic %s" % str(er))
+ else:
+ print("Compiling using pyside2-uic ...")
+
+ if args.create in ['qtpy', 'all']:
+ print("Creating also for qtpy ...")
+ # special case - qtpy - syntax is PyQt5
+ with open(py_file_pyqt5, 'r') as file:
+ filedata = file.read()
+ # replace the target string
+ filedata = filedata.replace('from PyQt5', 'from qtpy')
+ with open(py_file_qtpy, 'w+') as file:
+ # write the file out again
+ file.write(filedata)
+
+ if args.create in ['pyqtgraph', 'all']:
+ print("Creating also for pyqtgraph ...")
+ # special case - pyqtgraph - syntax is PyQt4
+ with open(py_file_pyqt, 'r') as file:
+ filedata = file.read()
+ # replace the target string
+ filedata = filedata.replace('from PyQt4', 'from pyqtgraph.Qt')
+ with open(py_file_pyqtgraph, 'w+') as file:
+ # write the file out again
+ file.write(filedata)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))