QGraphicsView, QtOpenGL et py2exe
Bonjour,
Je me suis recemment tourne vers PyQt pour developper un utilitaire multi-plateforme destine aux "Gamers" et je me retrouve confronter a un probleme lorsque j'utilise py2exe pour generer un binaire a partir de mon programme.
J'ai deja reussi a compiler des applications incluant un grand nombre de modules en plus de Qt sans trop de difficultes et c'est la raison pour laquelle je pense que la source de mon probleme doit venir des options de compilation de py2exe.
Concretement, lorsque je lance mon programme en utilisant l'interpreteur Python (2.5 ou 2.6) l'image que contient ma "GraphicsView" s'affiche correctement. En revanche apres avoir genere le .exe, j'obtiens juste un cadre blanc.
Voici le code en question (fonctionnel avec la librairie PyQt4 installe):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| from PyQt4 import QtCore, QtGui, QtOpenGL
import sys, urllib, webbrowser
class GraphicsView_1(QtGui.QGraphicsView):
def __init__(self, parent=None):
super(GraphicsView_1, self).__init__(parent)
gView = self
self.img_url = "http://ogt.oxadi.com/content/Client-Ban.jpg"
self.link = "http://ogt.oxadi.com/"
self.scene = QtGui.QGraphicsScene()
self.image = urllib.urlretrieve(self.img_url)[0]
self.scene.addPixmap(QtGui.QPixmap(self.image))
gView.setGeometry(QtCore.QRect(5, 30, 400, 72))
gView.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
gView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
gView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
gView.setObjectName("graphicsView")
gView.setViewport(QtOpenGL.QGLWidget())
gView.setScene(self.scene)
def goURL(self):
webbrowser.open(self.link)
def mousePressEvent(self, mouseEvent):
try:
self.goURL()
except:
print "Couldn't open URL"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
form = GraphicsView_1()
form.show()
app.exec_() |
Et voila mon setup.py :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import sys
assert sys.version >= '2', "Install Python 2.0 or greater"
import sys,os, string
from distutils.sysconfig import *
from distutils.core import setup,Extension
from distutils.command.build_ext import build_ext
from distutils.command.install import install
from distutils.command.install_data import install_data
import py2exe
ScriptNames = ["main.pyw"]
while ScriptNames:
setup(
windows=[{"script":ScriptNames.pop(),
"icon_resources": [(1, "data/ogt.ico")]
}],
options = {"py2exe": {"compressed": 1,
"optimize": 0,
"bundle_files": 1,
"includes":["sip","PyQt4.QtCore","PyQt4.QtGui","PyQt4.QtOpenGL","OpenGL"],
}
},
zipfile = None
) |
Merci.