Comment réaliser une application autonome de Pyromaths sur Mac OS X à partir du programme développé avec PyQt
Avec PyQt, il est possible de réaliser des programmes multi-plateformes. Cependant, le programme obtenu est un script Python qui nécessite la présence de Python, de PyQt et d'autres librairies et ne ressemble donc pas tout à fait à une application native du système.
Avec
py2app, il est possible d'obtenir une véritable application autonome sur Mac OS X à partir du programme réalisé avec PyQt.
py2app n'est malheureusement pas capable de réaliser une application autonome à partir de la version de Python fournie avec Mac OS X. Il va donc falloir installer une nouvelle version de Python ainsi que PyQt avec les dépendances nécessaires et bien sûr py2app.
La méthode la plus simple est d'utiliser MacPorts.
L'installation de MacPorts se fait en téléchargeant une image disque et en utilisant l'installateur fourni (attention, les prérequis sont d'avoir installé X11 avec le package “X11 User” et les outils de développement pour Mac OS X)
Une fois MacPorts installé, il faut taper les commandes suivantes dans le terminal pour installer Python, SIP, PyQt et py2app :
Code : Tout sélectionner
sudo port install python25
sudo port install python_select
sudo python_select python25
sudo port install py25-macholib-devel
sudo port install py25-sip
sudo port install py25-pyqt4
sudo port install py25-py2app-devel
sudo port install py25-lxml
Dans le dossier source, on crée un sous-dossier qu'on peut appeler "mac" dans lequel on va placer l'icone 'pyromaths.icns', un fichier de configuration pour py2app nommé setup.py :
Code : Tout sélectionner
from setuptools import setup
APP = ['../pyromaths.py']
DATA_FILES = ['pyromaths.icns']
OPTIONS = dict(
plist='Info.plist',
argv_emulation=True,
includes=['sip', 'PyQt4._qt']
)
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
ainsi qu'un fichier info.plist :
(Pour en savoir plus sur les fichiers "Information Property List" :
http://developer.apple.com/documentatio ... onfig.html)
Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Globally unique identifier -->
<key>CFBundleIdentifier</key>
<string>org.pyromaths.pyromaths</string>
<!-- Used by py2app to generate application bundle -->
<key>CFBundleName</key>
<string>Pyromaths</string>
<!-- Package type is an Application -->
<key>CFBundlePackageType</key>
<string>APPL</string>
<!-- Version number -->
<key>CFBundleShortVersionString</key>
<string>08.11</string>
<!-- Build number -->
<key>CFBundleVersion</key>
<string>08.11</string>
<!-- Copyright notice -->
<key>NSHumanReadableCopyright</key>
<string>© Jérôme Ortais</string>
<!-- Icon file name -->
<key>CFBundleIconFile</key>
<string>pyromaths</string>
<!-- Development region -->
<key>CFBundleDevelopmentRegion</key>
<string>French</string>
<!-- Executable name -->
<key>CFBundleExecutable</key>
<string>pyromaths</string>
<!-- Bundle display name -->
<key>CFBundleDisplayName</key>
<string>pyromaths</string>
<key>CFBundleSignature</key>
<string>PYTS</string>
</dict>
</plist>
Pour réaliser l'application avec py2app :