-
-
Save alexlib/4a4ad7b3c572003cffb6 to your computer and use it in GitHub Desktop.
pyside+qml+pyinstaller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pyinstaller -F -w --noupx main.spec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys, os | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtDeclarative import QDeclarativeView | |
def resource_path(relative_path): | |
""" Get absolute path to resource, works for dev and for PyInstaller | |
http://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile | |
""" | |
try: | |
# PyInstaller creates a temp folder and stores path in _MEIPASS | |
base_path = sys._MEIPASS | |
except Exception: | |
base_path = os.path.abspath(".") | |
return os.path.join(base_path, relative_path) | |
# Create Qt application and the QDeclarative view | |
app = QApplication(sys.argv) | |
view = QDeclarativeView() | |
# Create an URL to the QML file | |
url = QUrl(resource_path('./view.qml')) | |
# Set the QML file and show | |
view.setSource(url) | |
view.show() | |
# Enter Qt main loop | |
sys.exit(app.exec_()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: python -*- | |
block_cipher = None | |
a = Analysis(['main.py'], | |
pathex=['.'], | |
hiddenimports=[], | |
hookspath=None, | |
runtime_hooks=None, | |
cipher=block_cipher) | |
a.datas += [('view.qml', 'view.qml', 'DATA')] | |
pyz = PYZ(a.pure, | |
cipher=block_cipher) | |
exe = EXE(pyz, | |
a.scripts, | |
a.binaries, | |
a.zipfiles, | |
a.datas, | |
name='main.exe', | |
debug=False, | |
strip=None, | |
upx=False, | |
console=False ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 1.0 | |
Rectangle { | |
width: 200 | |
height: 200 | |
color: "red" | |
Text { | |
text: "Hello World" | |
anchors.centerIn: parent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment