diff --git a/script/process_pypi.py b/script/process_pypi.py new file mode 100755 index 000000000..e69de29bb diff --git a/script/process_qrc.py b/script/process_qrc.py old mode 100644 new mode 100755 index b62ae55f3..6ee847fe3 --- a/script/process_qrc.py +++ b/script/process_qrc.py @@ -1,40 +1,102 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- +"""Script to process QRC files (convert .qrc to _rc.py and .rcc). -""" -Utility scripts to compile the qrc file. The script will -attempt to compile the qrc file using the following tools: - - rcc (not used) - - pyside-rcc - - pyrcc4 - - pyrcc5 +The script will attempt to compile the qrc file using the following tools: + + - pyrcc4 for PyQt4 and PyQtGraph (Python) + - pyrcc5 for PyQt5 and QtPy (Python) + - pyside-rcc for PySide (Python) + - rcc for Qt4 and Qt5 (C++) Delete the compiled files that you don't want to use manually after running this script. + +Links to understand those tools: + + - pyrcc4: http://pyqt.sourceforge.net/Docs/PyQt4/resources.html#pyrcc4 + - pyrcc5: http://pyqt.sourceforge.net/Docs/PyQt5/resources.html#pyrcc5 + - pyside-rcc: https://www.mankier.com/1/pyside-rcc + - rcc on Qt4: http://doc.qt.io/archives/qt-4.8/rcc.html + - rcc on Qt5: http://doc.qt.io/qt-5/rcc.html + """ + +from __future__ import absolute_import, print_function + +import argparse +import glob import os +import sys +from subprocess import call -def compile_all(): - """ - Compile style.qrc using rcc, pyside-rcc, pyrcc4 and pyrcc5. - """ - qrc_dir = '../qdarkstyle' - print('Changing directory to: ', qrc_dir) - os.chdir(qrc_dir) +def main(arguments): + """Process QRC files.""" + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--qrc_dir', + default='../qdarkstyle', + type=str, + help="QRC file directory, relative to current directory.",) + parser.add_argument('--create', + default='all', + choices=['pyqt', 'pyqt5', 'pyside', 'qtpy', 'pyqtgraph', 'qt', 'qt5', 'all'], + type=str, + help="Choose which one would be generated.") - # print("Compiling for Qt: style.qrc -> style.rcc") - # os.system("rcc style.qrc -o style.rcc") + args = parser.parse_args(arguments) - print("Compiling for PyQt4: style.qrc -> pyqt_style_rc.py") - os.system("pyrcc4 -py3 style.qrc -o pyqt_style_rc.py") + print('Changing directory to: ', args.qrc_dir) + os.chdir(args.qrc_dir) - print("Compiling for PyQt5: style.qrc -> pyqt5_style_rc.py") - os.system("pyrcc5 style.qrc -o pyqt5_style_rc.py") + print('Converting .qrc to _rc.py and/or .rcc ...') - print("Compiling for PySide: style.qrc -> pyside_style_rc.py") - os.system("pyside-rcc -py3 style.qrc -o pyside_style_rc.py") + for qrc_file in glob.glob('*.qrc'): + # get name without extension + filename = os.path.splitext(qrc_file)[0] + + print(filename, '...') + ext = '_rc.py' + ext_c = '.rcc' + + # creating names + py_file_pyqt5 = 'pyqt5_' + filename + ext + py_file_pyqt = 'pyqt_' + filename + ext + py_file_pyside = 'pyside_' + filename + ext + py_file_qtpy = 'qtpy_' + filename + ext + py_file_pyqtgraph = 'pyqtgraph_' + filename + ext + + # calling external commands + if args.create in ['pyqt', 'pyqtgraph', 'all']: + call(['pyrcc4', '-py3', qrc_file, '-o', py_file_pyqt]) + + if args.create in ['pyqt5', 'qtpy', 'all']: + call(['pyrcc5', qrc_file, '-o', py_file_pyqt5]) + + if args.create in ['pyside', 'all']: + call(['pyside-rcc', '-py3', qrc_file, '-o', py_file_pyside]) + + if args.create in ['qtpy', 'all']: + print("Compiling for PySide ...") + # 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']: + # 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__": - compile_all() +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/script/process_ui.py b/script/process_ui.py old mode 100644 new mode 100755 index cde102389..9f3fbb7d4 --- a/script/process_ui.py +++ b/script/process_ui.py @@ -1,35 +1,46 @@ -#!python # -*- coding: utf-8 -*- +"""Script to process UI files (convert .ui to .py). -"""Script to process UI files. +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. -It compiles .ui files for using PyQt4, PyQt5, PySide, QtPy, PyQtGraph. +To run this script you need to have these tools available on system: -To run this script you need to have these tools: - - pyuic4 - - pyuic5 - - pyside-uic + - pyuic4 for PyQt4 and PyQtGraph + - pyuic5 for PyQt5 and QtPy + - pyside-uic for Pyside -This is used to compile files for examples. +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 -:since: 2018/02/05 -:author: Daniel Cosmo Pizetta """ -from __future__ import absolute_import -from __future__ import print_function +from __future__ import absolute_import, print_function import argparse import glob import os -from subprocess import call 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', help="UI directory", default='../example/ui', type=str) + 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', 'qtpy', 'pyqtgraph', 'all'], + type=str, + help="Choose which one would be generated.") + args = parser.parse_args(arguments) print('Changing directory to: ', args.ui_dir) @@ -51,27 +62,35 @@ def main(arguments): py_file_pyqtgraph = filename + '_pyqtgraph_ui' + ext # calling external commands - call(['pyuic5', '--from-imports', ui_file, '-o', py_file_pyqt5]) - call(['pyuic4', '--from-imports', ui_file, '-o', py_file_pyqt]) - call(['pyside-uic', '--from-imports', ui_file, '-o', py_file_pyside]) + if args.create in ['pyqt', 'pyqtgraph', 'all']: + call(['pyuic4', '--from-imports', ui_file, '-o', py_file_pyqt]) - # 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 ['pyqt5', 'qtpy', 'all']: + call(['pyuic5', '--from-imports', ui_file, '-o', py_file_pyqt5]) - # 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 args.create in ['pyside', 'all']: + call(['pyside-uic', '--from-imports', ui_file, '-o', py_file_pyside]) + + if args.create in ['qtpy', 'all']: + print("Compiling for PySide ...") + # 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']: + # 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__':