mardi 26 mai 2009

wxPython wx.dc.DrawText Multiline

Je viens de développer un dc.DrawText mais multiligne !

Je mettrais le code en ligne quand ça sera bien fignolé.

Paramètres :
Taille : largeur, hauteur (-1 pour libre), hauteur max
Alignement : Droite, Gauche et Justifié :-)
font
cadre
couleur fonte, cadre, fond

Cela permettra de faire mon propre module d'impression de wxGrid
pour remplacer printout.py qui fait un boulot de goret.

lundi 18 mai 2009

Bug wxPython Mac OSX ComboBox

Normalement la touche [TAB] fait passer d'un champ à l'autre.
et [Shift][TAB] dans le sens inverse.

Sur MAC, depuis un controle wx.ComboBox
[Shift][TAB] passe au champs suivant au lieu du précédent.

Bug wxPython Mac OSX TextCtrl align TE_RIGHT

Voila un gros bug
(en fait non puisque c'est signaler dans la doc)


http://docs.wxwidgets.org/stable/wx_wxtextctrl.html#wxtextctrl


wxTE_LEFT  The text in the control will be left-justified (default).
wxTE_CENTRE The text in the control will be centered
(currently wxMSW and wxGTK2 only).
wxTE_RIGHT The text in the control will be right-justified
(currently wxMSW and wxGTK2 only).


Sous windows on peut aligner correctement les caractères dans le control.
Sous Mac OSX, c'est pas possible. :-(

C'est très curieux car StaticText autorise bien un alignement gauche/centre/droit.

Je ne peux utiliser masked.NumCtrl
car ce controle gère pas la saisie d'un champ vide. (si on ajoute des décimales)
Et puis aussi il renvoie en Float avec une perte de précision...

Je vais m'en inspirer pour faire ma propre saisie de numérique.
La saisie sera classique puis padder avec des espaces en sortie

[1234.5 ] -> [ 1 234.50]

jeudi 14 mai 2009

Install MySQL Python (Mac OS X)

Environement :
Python 2,6
MySQL 5.xx
(pis aussi wxpython 2.8)

Référence :
http://antoniocangiano.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/
http://www.keningle.com/?p=11
http://www.sebastien-verbois.be/python/mysql-python

Installer MySQL (et le truc d'administration GUI Tools)

Question :
Est ce nécessaire si ce poste ne dois pas faire tourner une base mais seulement se connecter à une base MySQL sur un autre poste ???

Trouver cette archive :
MySQL-python-1.2.2.tar


L'ouvrir, puis se placer dedans depuis un Terminal

$cd MySQL-python-1.2.2


Modifier le fichier : _mysql.c

Commenter les lignes 37, 38 , 39

//#ifndef uint

//#define uint unsigned int

//#endif


Normalement y a ça aussi à faire mais bon j'ai rien fait...

    
- uint port = MYSQL_PORT;
- uint client_flag = 0;
+ unsigned int port = MYSQL_PORT;
+ unsigned int client_flag = 0;

Toujours dans mon répertoire :
MySQL-python-1.2.2


$ sudo python setup.py build


Si merdouille concernant setuptools :
This script requires setuptools version 0.6c5 to run 


Voir cette page :
http://pypi.python.org/pypi/setuptools

setuptools-0.6c9-py2.6.egg

Le fichier à une extension : .sh
donc si :

$ sh setuptools-0.6c9-py2.6.egg.sh
Please rename it back to setuptools-0.6c9-py2.6.egg and try again.

référence : http://gleeda.blogspot.com/2009/03/pyflag-installation-on-centos-52.html
Renommer le fichier, (en fait virer le .sh à la fin)

$sh setuptools-0.6c9-py2.6.egg

Processing setuptools-0.6c9-py2.6.egg
Copying setuptools-0.6c9-py2.6.egg to /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.6/bin
Installing easy_install-2.6 script to /Library/Frameworks/Python.framework/Versions/2.6/bin

Installed /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9

Ok, on recommence donc ...


$sudo python setup.py build


sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 16, in
metadata, options = get_config()
File "/Users/utilisateur1utilisateur1/Desktop/MySQL-python-1.2.2/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/Users/utilisateur1utilisateur1/Desktop/MySQL-python-1.2.2/setup_posix.py", line 24, in mysql_config
raise EnvironmentError, "%s not found" % mysql_config.path
EnvironmentError: mysql_config not found

Si ça couince comme ça alors... faut corriger le fichier :
setup_posix.py


- mysql_config.path = "mysql_config"
+ mysql_config.path = "/opt/local/bin/mysql_config5"


Note : il y a bien un lien vers l'installation MySQL

Faire ce truc là aussi : (pourquoi ? et pourquoi pas... ça sert à quoi ???)

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

Remarque root / sudo :
http://www.osxfacile.com/singleuserroot.html
je dis ça parce que bon, j'ai bien cherché" encore... (humour : osx facile....)

Encore une merde :

> sudo python setup.py build
running build
running build_py
creating build
creating build/lib.macosx-10.3-fat-2.6
copying _mysql_exceptions.py -> build/lib.macosx-10.3-fat-2.6
creating build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
creating build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.3-fat-2.6
Compiling with an SDK that doesn't seem to exist: /Developer/SDKs/MacOSX10.4u.sdk
Please check your Xcode installation
gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch i386 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1

Apres recherche...
il faut installer Xcode à partir du 2° CD d'install (sur mon Mac Mini)

sudo python setup.py build
Password:
running build
running build_py
.....
gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -Dversion_info=(1,2,2,'final',0) -D__version__=1.2.2 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.3-fat-2.6/_mysql.o -g -Os -arch i386 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -bundle -undefined dynamic_lookup build/temp.macosx-10.3-fat-2.6/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc -o build/lib.macosx-10.3-fat-2.6/_mysql.so
ld: warning in build/temp.macosx-10.3-fat-2.6/_mysql.o, file is not of required architecture
ld: warning in /usr/local/mysql/lib/libmysqlclient_r.dylib, file is not of required architecture
ld: warning in /usr/local/mysql/lib/libmygcc.a, file is not of required architecture

Je laisse tomber les warnings...

$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
deleting MySQL_python.egg-info/native_libs.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.3-fat/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb
running build_ext
creating build/bdist.macosx-10.3-fat
creating build/bdist.macosx-10.3-fat/egg
copying build/lib.macosx-10.3-fat-2.6/_mysql.so -> build/bdist.macosx-10.3-fat/egg
copying build/lib.macosx-10.3-fat-2.6/_mysql_exceptions.py -> build/bdist.macosx-10.3-fat/egg
creating build/bdist.macosx-10.3-fat/egg/MySQLdb
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/__init__.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/connections.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
creating build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/__init__.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/CLIENT.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/CR.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/ER.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/FLAG.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/constants/REFRESH.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb/constants
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/converters.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/cursors.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/release.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
copying build/lib.macosx-10.3-fat-2.6/MySQLdb/times.py -> build/bdist.macosx-10.3-fat/egg/MySQLdb
byte-compiling build/bdist.macosx-10.3-fat/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/connections.py to connections.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/CR.py to CR.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/ER.py to ER.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/converters.py to converters.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/cursors.py to cursors.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/release.py to release.pyc
byte-compiling build/bdist.macosx-10.3-fat/egg/MySQLdb/times.py to times.pyc
creating stub loader for _mysql.so
byte-compiling build/bdist.macosx-10.3-fat/egg/_mysql.py to _mysql.pyc
creating build/bdist.macosx-10.3-fat/egg/EGG-INFO
copying MySQL_python.egg-info/PKG-INFO -> build/bdist.macosx-10.3-fat/egg/EGG-INFO
copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.macosx-10.3-fat/egg/EGG-INFO
copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.macosx-10.3-fat/egg/EGG-INFO
copying MySQL_python.egg-info/top_level.txt -> build/bdist.macosx-10.3-fat/egg/EGG-INFO
writing build/bdist.macosx-10.3-fat/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg' and adding 'build/bdist.macosx-10.3-fat/egg' to it
removing 'build/bdist.macosx-10.3-fat/egg' (and everything under it)
Processing MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg
Copying MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg to /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages
Adding MySQL-python 1.2.2 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg
Processing dependencies for MySQL-python==1.2.2
Finished processing dependencies for MySQL-python==1.2.2

Ca roule, (si, si !, c'est écrit)

> python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg/_mysql.pyc, but /Users/utilisateur1utilisateur1/Desktop/MySQL-python-1.2.2 is being added to sys.path
MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet


Yeehaaa...
Test :

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import MySQLdb

base = "filcine"
user = "toto"
pwd = "toto"
port = 3306
host="192.168.0.6"

b = MySQLdb.connect( db = base , user = user , passwd = pwd , host = host , port = port )

c = b.cursor( )

sql = "select id from ref "
c.execute( sql )
print c.fetchall( )

sql = "select * from refd "
print c.execute( sql )
# print c.fetchall( )


>>> ================================ RESTART ================================
>>>

Warning (from warnings module):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.2-py2.6-macosx-10.3-fat.egg/MySQLdb/__init__.py", line 34
DeprecationWarning: the sets module is deprecated
((420L,), (421L,), (422L,), (423L,), (424L,), (425L,), (426L,), (427L,), (428L,), (429L,), (430L,), (431L,), (432L,), (433L,), (434L,), (435L,))
578
>>>

C'est tout bon, avec le même warning que sous windows.

Super, maintenant comment savoir ou les fichiers se sont barrées ?
comment faire une install simple et rapide de tout ce merdier sur un poste client ?

(j'veux pas être taquin mais sur windows... et ben c'est un poil + simple)

Toutes les remarques sont les bienvenues