Add support for creating frozen executables with cx_Freeze; use new setup_qt module for building Qt UI files
This commit is contained in:
parent
8ac3346c1e
commit
92e1771db5
5
qspectrumanalyzer.py
Executable file
5
qspectrumanalyzer.py
Executable file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
from qspectrumanalyzer.__main__ import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -106,7 +106,11 @@ class BasePowerThread(QtCore.QThread):
|
||||
|
||||
|
||||
# Build list of all backends
|
||||
_backends_files = glob.glob(os.path.join(os.path.dirname(__file__), "*.py"))
|
||||
_base_path = os.path.realpath(os.path.dirname(__file__))
|
||||
_backends_files = (glob.glob(os.path.join(_base_path, "*.py")) +
|
||||
glob.glob(os.path.join(_base_path, "*.pyc")) +
|
||||
glob.glob(os.path.join(_base_path, "*.pyo")))
|
||||
|
||||
__all__ = [os.path.splitext(os.path.basename(f))[0] for f in _backends_files
|
||||
if os.path.isfile(f) and not os.path.basename(f).startswith("_")]
|
||||
|
||||
|
29
setup-qt.py
29
setup-qt.py
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os, shutil
|
||||
from glob import glob
|
||||
|
||||
package = "qspectrumanalyzer"
|
||||
languages = ["cs"]
|
||||
|
||||
print("Rebuilding PyQt resource files...")
|
||||
for f in glob("{}/*.qrc".format(package)):
|
||||
os.system("pyrcc5 -o {}/qrc_{}.py {}".format(package, os.path.basename(f[:-4]), f))
|
||||
|
||||
print("Rebuilding PyQt UI files...")
|
||||
for f in glob("{}/*.ui".format(package)):
|
||||
os.system("pyuic5 -o {}/ui_{}.py {}".format(package, os.path.basename(f[:-3]), f))
|
||||
|
||||
print("Changing compiled UI files from PyQt5 to Qt.py wrapper...")
|
||||
os.system("sed -i 's/^from PyQt5 import/from Qt import/g' {}/ui_*.py".format(package))
|
||||
|
||||
print("Updating translations...")
|
||||
lang_files = " ".join("{}/languages/{}_{}.ts".format(package, package, lang) for lang in languages)
|
||||
os.system("pylupdate5 {}/*.py -ts {}".format(package, lang_files))
|
||||
os.system("lrelease {}/languages/*.ts".format(package))
|
||||
|
||||
print("Regenerating .pyc files...")
|
||||
shutil.rmtree("{}/__pycache__".format(package), ignore_errors=True)
|
||||
for f in glob("{}/*.pyc".format(package)):
|
||||
os.remove(f)
|
||||
__import__("{}.__main__".format(package))
|
47
setup.py
47
setup.py
@ -1,8 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from setuptools import setup
|
||||
import sys, pathlib, subprocess, shutil, re
|
||||
import setuptools
|
||||
|
||||
from qspectrumanalyzer.version import __version__
|
||||
|
||||
setup_cmdclass = {}
|
||||
setup_kwargs = {}
|
||||
|
||||
# Allow compilation of Qt .qrc, .ui and .ts files (build_qt command)
|
||||
try:
|
||||
from setup_qt import build_qt
|
||||
setup_cmdclass['build_qt'] = build_qt
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Allow building of frozen executables with cx_Freeze (build_exe command)
|
||||
try:
|
||||
from cx_Freeze import setup, Executable
|
||||
|
||||
base = 'Win32GUI' if sys.platform == 'win32' else None
|
||||
setup_kwargs['executables'] = [
|
||||
Executable('qspectrumanalyzer.py', base=base),
|
||||
Executable('soapy_power.py', base=None),
|
||||
]
|
||||
except ImportError:
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
setup(
|
||||
name="QSpectrumAnalyzer",
|
||||
version=__version__,
|
||||
@ -48,5 +73,23 @@ setup(
|
||||
"Programming Language :: Python :: 3",
|
||||
"Topic :: Communications :: Ham Radio",
|
||||
"Topic :: Scientific/Engineering :: Visualization"
|
||||
]
|
||||
],
|
||||
options={
|
||||
'build_exe': {
|
||||
'packages': ['qspectrumanalyzer', 'qspectrumanalyzer.backends'],
|
||||
'excludes': [],
|
||||
'includes': [
|
||||
'numpy.core._methods', 'numpy.lib.format', 'pyqtgraph.debug', 'pyqtgraph.ThreadsafeTimer'
|
||||
],
|
||||
'include_msvcr': True,
|
||||
'optimize': 2,
|
||||
},
|
||||
'build_qt': {
|
||||
'packages': ['qspectrumanalyzer'],
|
||||
'languages': ['cs'],
|
||||
'replacement_bindings': 'Qt'
|
||||
},
|
||||
},
|
||||
cmdclass=setup_cmdclass,
|
||||
**setup_kwargs
|
||||
)
|
||||
|
5
soapy_power.py
Executable file
5
soapy_power.py
Executable file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
from soapypower.__main__ import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user