diff --git a/entry.py b/entry.py index 27e61f9..ebd2fa5 100755 --- a/entry.py +++ b/entry.py @@ -9,12 +9,4 @@ if hasattr(sys, 'frozen') is False: path = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(path, "zhihurss")) - elif sys.platform == 'win32': - import win32api - ASADMIN = 'asadmin' - - if sys.argv[-1] != ASADMIN: - params = ' '.join(sys.argv[1:] + [ASADMIN]) - win32api.ShellExecute(0, 'runas', sys.executable, params, os.path.abspath(os.curdir), 1) - sys.exit(0) run() diff --git a/freeze.py b/freeze.py index cc84216..30927f6 100755 --- a/freeze.py +++ b/freeze.py @@ -13,41 +13,116 @@ shutil.rmtree("build", ignore_errors=True) -packages = [ - "zhihu", - "lxml", - "PyQt5.QtQuick", - "PyQt5.QtCore", - "PyQt5.QtWidgets", - "PyQt5.QtQml", - "PyQt5.QtNetwork" -] +platform = sys.platform + +# ===== set PyQt5 dir ===== + +if platform == 'win32': + PYQT5_DIR = os.path.join(get_python_lib(), "PyQt5") +elif platform == 'darwin': + # TODO + PYQT5_DIR = os.path.join(get_python_lib(), "PyQt5") +elif platform == 'linux': + # TODO + PYQT5_DIR = os.path.join(get_python_lib(), "PyQt5") + +print('check PyQt5 dir: {0}'.format(PYQT5_DIR), '...') + +if not os.path.exists(PYQT5_DIR): + print("Can't find PyQt5's dir automatically, Please set it in freeze.py") + sys.exist(0) -QML_DIR = os.path.join(get_python_lib(), "PyQt5", 'qml') +print('Done.') + +# ===== set qml dir ===== + +if platform == 'win32': + QML_DIR = os.path.join(PYQT5_DIR, 'qml') +elif platform == 'darwin': + # TODO + QML_DIR = '' +elif platform == 'linux': + # TODO + QML_DIR = '' print('check QML dir: {0}'.format(QML_DIR), '...') -if os.path.exists(QML_DIR) is False: - print("Can't find PyQt5's QML dir automatically, Please set it dir in freeze.py") +if not os.path.exists(QML_DIR): + print("Can't find PyQt5's QML dir automatically, Please set it in freeze.py") sys.exist(0) print('Done.') -include_files = [ - ("zhihurss/res/qml/", "qml"), - (os.path.join(QML_DIR, "QtQuick"), "QtQuick"), - (os.path.join(QML_DIR, "QtQuick.2"), "QtQuick.2"), - (os.path.join(QML_DIR, "QtWebKit"), "QtWebKit") +# ===== setup include files ===== + +# ----- qt files ----- + +if platform == 'win32': + qt_files_list = [ + 'libEGL.dll', + 'libGLESv2.dll', + 'QtWebProcess.exe', + 'Qt5WebKitWidgets.dll', + 'Qt5MultimediaWidgets.dll', + 'Qt5OpenGL.dll', + 'Qt5PrintSupport.dll' + ] +elif platform == 'darwin': + pass +elif platform == 'linux': + pass + +qt_files = [os.path.join(PYQT5_DIR, filename) for filename in qt_files_list] + +# ----- qml dirs ----- + +if platform == 'win32': + qml_dirs_list = [ + "QtQuick", + "QtQuick.2", + "QtWebKit" + ] +elif platform == 'darwin': + # TODO + qml_dirs_list = [] +elif platform == 'linux': + # TODO + qml_dirs_list = [] + +qml_dirs = [(os.path.join(QML_DIR, dirname), dirname) for dirname in qml_dirs_list] + +# ----- res files ----- + +res_files = [("zhihurss/res/qml/", "qml")] + +# ----- platfrom extra files ----- + +if platform == 'win32': + extra_files = [] +elif platform == 'darwin': + extra_files = [] +elif platform == 'linux': + extra_files = [] + +# ----- complete include files ----- + +include_files = qt_files + qml_dirs + res_files + extra_files + +# ===== others ===== + +packages = [ + 'lxml' ] base = None - -if sys.platform == "win32": +if platform == "win32": base = "Win32GUI" with open('README.md', 'rb') as f: readme = f.read().decode('utf-8') +# ===== setup for build ===== + setup( name=application_title, version="1.0.0", @@ -58,7 +133,8 @@ options={ "build_exe": { "packages": packages, - "include_files": include_files + "include_files": include_files, + "include_msvcr": True if sys.platform == 'win32' else False } }, executables=[Executable(main_python_file, base=base, targetName=application_title+'.exe')], diff --git a/zhihurss/util/my_pyqt.py b/zhihurss/util/my_pyqt.py index ae5c0f6..f790f3d 100644 --- a/zhihurss/util/my_pyqt.py +++ b/zhihurss/util/my_pyqt.py @@ -2,6 +2,7 @@ import sys +from PyQt5 import QtWebKit from PyQt5.QtCore import QUrl, QObject, QVariant, QMetaObject, Q_ARG, Qt from PyQt5.QtWidgets import QApplication from PyQt5.QtQuick import QQuickView