mardi 17 août 2010

Py2xe: how to hide your GUI application error box "See the logfile for details"


If for some reasons you need to hide that box while still logging the errors in myapp.exe.log, the following is a quick and dirty solution:


1) Find the file "boot_common.py" in your py2exe module (exemple: c:\python2x\Lib\site-packages\py2exe\boot_common.py) and make a backup copy in case of.

2) find the "def write" method and add a show_dialog parmeter this way:

def write(self, text, alert=sys._MessageBox, fname=sys.executable + '.log', show_dialog=False):


3) modify the following "else" block this way:


if show_dialog==True:
import atexit
atexit.register(alert, 0,"See the logfile '%s' for details" % fname,"Errors occurred")
else:
pass



To come back to the original behavior change to "show_dialog=True" in 2).

More informations on Py2exe error handling here.

dimanche 22 juin 2008

[french] Visualisation des séismes du RENASS via KML(s)

Ce post est un "Google docs export" => page orginale à jour ici, dossier KML(s)
> KML des derniers tremblements de Terre
  • visualisez le KML (lien ci-dessus) dans Google Earth, World Wind, Virtual Earth, etc
  • derniers tremblements de Terre en premier dans la liste
> Visualisation dans Google Maps Search:
  • Centré France, rendu "Terrain"
  • Centré Monde, rendu "Terrain"
> Visualisation via Google Maps API:
  • Centré France
  • Centré Monde
> Visualisation via Open Layers sur carte Open Street Map:
  • Centré France
> Flux RSS pour se tenir au courant des derniers séismes (expérimental)
  • Flux RSS





vendredi 30 mai 2008

OSMaware, visualising OpenStreetMaps mapping activity via KML(s)


More informations here: http://code.google.com/p/osmlab/

thanks for the "Lolcat of awesomeness" award :)

dimanche 25 mai 2008

OS X 10.5 Leppard: "express" Python, PIL and WxPython please

Python on OS X 10.5...

It is not recommended to mess-up with the Python 2.5 installed by default, and while wanting to install PIL and WxPython, I discovered and lost myself in the jungle of Python "distros" and their prerequisites (Fink, MacPorts, DarwinPorts, AciveState, MacPython ...)

In a hurry? go to the source: python.org (MacPython)

1) search and install the universal installer for OS X:
http://www.python.org/download/

This new Python will be the default one when you invoke "Python" in a shell.
It's installed in "/Library/Frameworks/Python.framework"
(the original OS X python is in: "/System/Library/Frameworks/Python.framework").
The new libs are in "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages"

2) download and install PIL, WxPython (or other packages) from:
http://pythonmac.org/packages/py25-fat

More informations about MacPython:
http://wiki.python.org/moin/MacPython

An interesting read about the Python distributions (especially in a scientific context)

samedi 16 février 2008

Flex: how-to access remote data (xml) through a proxy?

Flash player (used by Flex) has a very strict security policy: it's not possible to access public data from another domain than the one where your swf stands (unless a crossdomain.xml file is present on the distant server you want to access).


If the crossdomain file doesn't exist it is always possible to copy a minimal proxy file on your server (where your swf is present). This way flash player will communicate locally with the proxy, the proxy will give the result back to flashplayer, and there won't be any remote domain seen by flashplayer.

How-to use a proxy with Flex and Action Script3? (code and example)

http://docs.google.com/Doc?id=dgqhgsgm_154gfhwj5cn

vendredi 15 février 2008

How to programmatically draw in Flex 3?

I was surprised by the lack of documentation( and working example) for this simple task.

Here's what I've got so far:

  • Flex doesn't like "Shape" objects? replace them with "UIcomponent"
  • a "UI component" must be attached to a container (like a canvas, a panel,...)
  • the shape will be visible when it is added has a child of the container: myCanvas.addChild(myCircle)
Here's an example with 3 buttons (1 to create a rectangle, 1 to create a circle, 1 to move them appart):

Run (right click at runtime then "view source" to see the code):
http://francois.schnell.free.fr/flex/draw/draw.html

Code in plain text:
http://docs.google.com/Doc?id=dgqhgsgm_153dc6cvzf7

samedi 26 janvier 2008

Blogger: paste HTML, tags, code

Blogger is not really code friendly. You need to "escape" each tag (replacing <>). Also spaces disappear and you may need to add a "pre" tag.

As I'm learning Flex/Air I've developed a small on-line tool to automate the process if you need to paste HTML or tags/code:


BloggerPaste:
http://francois.schnell.free.fr/tools/BloggerPaste/BloggerPaste.html

If you have any comments or feature request thanks to let me know.

dimanche 23 décembre 2007

Controlling Google Earth with Python (API COM)

Google Earth is a powerful and beautiful application. Being able to control the globe, with few lines of Python code, makes you feel like you've got some god-like powers ;)

I've drafted here a short guide to show you how to start controlling Google Earth with Python (through its API COM):
http://docs.google.com/View?docid=dgqhgsgm_933rjw93

samedi 22 décembre 2007

Wrap my head around unicode for Python

Most interesting tutorial I've found: http://boodebr.org/main/python/all-about-python-and-unicode

Keypoints:

  • unicode are "symbols" or "objects" (no fixed computer representation, don't think bytes) and codecs transform them into binary strings (so you can print, store in disk, sent across network...).
  • a unicode string example with some greek characters: unicodeString = u"abc_\u03a0\u03a3\u03a9.txt"
  • you shouldn't 'print' a unicode string without encoding it first (by default Python will encode in ascii which can leads to errors if there are non ascii characters)
  • you can print a unicode "representation": print repr(unicodeString)
  • you encode with the .encode method: binary = unicodeString.encode("utf-8")
  • you can see the binary result like this: print "UTF-8", repr(unicodeString.encode('utf-8'))
  • print "ASCII",unicodeString.encode('ascii','replace') #will replace non-codable characters with '?'
  • from binary to unicode: unicode(utf8_string,'utf-8') # you must specify the encoding if not Python assumes it's ascii
  • once you have a Unicode object, it behaves exactly like a regular string object, so there is no new syntax to learn (other than the \u and \U escapes)
Other links:
* http://www.jorendorff.com/articles/unicode/python.html
* http://evanjones.ca/python-utf8.html
* http://vim.sourceforge.net/tips/tip.php?tip_id=246
* http://farmdev.com/thoughts/23/what-i-thought-i-knew-about-unicode-in-python-amounted-to-nothing/
from my wikinote

dimanche 16 décembre 2007

Iron Python Studio (Python, .Net and the power of Visual Studio for free)

Iron Python Studio is a free IDE for Iron Python (Python for .Net).

You can develop command-line applications, Windows forms and WPF/XAML applications (see the project IronPythonScreenCast (wmv)).

Iron Python Studio has a visual designer for your GUI, code completion, debugger, etc (the usual tools of Visual Studio which makes in particular GUI development so simple).

It can use all the classes of .Net and also use the classic CPython (version 2.4 for now since this first version of the Studio is based on Iron Python 1.1)

More informations on my wiki note

dimanche 20 mai 2007

[Win] Quick access to favorite folders

"Folder Guide" is a handy windows freeware to keep the most common folders you use at your fingertip.

Folder Guide is a free handy utility that provides fast access to your frequently used and favorite folders. It can operate as the part of your context menu in your Windows Explorer.

samedi 3 mars 2007

[Python]: optparse -- powerful command line option parser

I find optparse much better than getopt to get command line options.
The beast is explained here:
http://python.org/doc/lib/module-optparse.html

For example:

from optparse import OptionParser

parser=OptionParser()

parser.add_option("-f", "--file",dest="filename",help="a file to process")
parser.add_option("-r", "--repeat",dest="repeat",help="an integer")
parser.add_option("--dp",dest="directory",help="picture directory")
parser.add_option("-v",help="verbosemode",action="store_true",
dest="verbose",default=True)

(options,args)=parser.parse_args()

print options.filename
print options.repeat
print options.verbose
print options.directory

For flags, 'action' can be "store_true" or "store_false"

[Python]: find files of a certain type in a folder.

To search for .jpg files in the folder "myfoder" you can do:


import os,fnmatch

for fileName in os.listdir ( "myfolder" ):
if fnmatch.fnmatch ( fileName, '*.jpg' ):
print "Found fileName ",fileName

lundi 26 février 2007

Write GPS data on your photos with Exiftool

Exiftool is a Windows/Mac command-line app (or a muti-plateform Perl librairy) to read and write EXIF metadatas on certain file types.

In the following I will use .jpg files from my camera and the Windows .exe version of Exiftool that I will control in a DOS shell.

Want to see some EXIF metadata in your picture ?

$ exiftool mypicture.jpg

Want to extract the precise date and time when this picture was taken ?

$ exiftool -CreateDate mypicture.jpg
( Returns something "2007:02:10 21:19:43")

Want to write your picture was on the Eastern part of Greenwich meridian ?

$ exiftool -GPSLongitudeRef="E" mypicture.jpg

Want to write the exact the longitude value ?

$ exiftool -GPSLongitude="7.422809" mypicture.jpg

Want to write your picture is in the northern latitudes ?

$ exiftool -GPSLatitudeRef="N" mypicture.jpg

and give the exact latitude value ?

$ exiftool -GPSLatitude="48.419973" mypicture.jpg

Obviously you can combine the four tags above in just one line.

You can check everything went well with another exiftool mypicture.jpg (warning: if the app. doesn't understand what to do it didn't return me any error message by default ).

More informations about the GPS tags can be found here.

With this Free Software GPL command-line version it's now easy to integrate geolacalisation capabilities in a Python script for example.

I can upload my pictures on Flickr and they will show on the Flick maps but I still need to use the geocoding bookmarklet if I want to add the geotagged tags and the google maps.

PS: -n option gives you the latitude/longitude in the decimal form when reading these tags
PS: Python also have a nice similar library but I didnt' succeed to write GPS data with it,
http://www.emilas.com/jpeg/

mercredi 21 février 2007

[Python] Callback examples with FTP

From the wikipedia article:

In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level software layer to call a function defined in a higher-level layer.

Usually, the higher-level code starts by calling a function within the lower-level code passing to it a pointer or handle to another function. While the lower-level function executes, it may call the passed-in function any number of times to perform some subtask. In another scenario, the lower-level function registers the passed-in function as a handler that is to be called asynchronously by the lower-level at a later time in reaction to something.

Two examples with the FTP module of Python:

from ftplib import FTP

ftp = FTP("the_host")
ftp.login('ftpuser', 'ftppass')
ftp.cwd("folder")

# To obtain the list of files in a variable (not just the standard output) :

fileList=[]
command=ftp.retrlines("LIST",fileList.append)

# To download the file :

file = open("myfile.exe", 'wb')
ftp.retrbinary("RETR myfile.exe",file.write)
ftp.quit()
file.close()

mardi 20 février 2007

[Python] How to get the output from os.system() into a variable ?

A quick solution using popen :

import os
result=os.popen('command').read()
print result

where command is your command (expl. on windows: dir,ipconfig,...)

If you expect more than a line and want each word in a list:

import os,string
result=string.split(os.popen('dir/w').read())

Source of this

samedi 17 février 2007

Clipboard and all-in-one system information for windows

Two useful free software to complete my list of windows utilities :

Ditto is a very useful Open Source clipboard:

- history of text copies, images, screenshots
- enable hot keys, network sync, etc

SIW is a freeware which stands for "System Information for Windows"

- no installation required (can run on a USB key)
- hardware informations, temperature sensors, license keys, process, etc, etc.

jeudi 11 janvier 2007

[Python] Generating an html doc for your script(s)

Pydoc
Python comes with a "pydoc" utility. On windows it is lacated in C:\Python2X\Lib (you may want to add this directory to your system path)

To produce an html documentation of a script or module type in a DOS shell (at the level of your script) :

pydoc.py -w nameOfYourScript

Warning:
- don't type the .py extension in the command above
- respect the uppercase and small caps even on windows.
- your script must have some docstrings

The above command produce a nameOfYourScript.html doc with the classes, methods, functions, etc.

Epydoc
For a more powerful and complete alternative I use the excellent Epydoc that you can download here:
http://epydoc.sourceforge.net/

On windows after the installation you can find the epydoc script in C:\Python2X\Scripts (you may want to add this directory to your system path)

To use epydoc just type in a shell in the folder containing your script(s):

epydoc.py scriptNameWithoutPyExtension

This will produce an "html" folder : read the index.html in your browser and enjoy :)

jeudi 4 janvier 2007

Firefox extensions

A selection of useful Firefox extensions (updated 19 Fev 2007):

* Google Toolbar 3 (beta)
* Gutil a "Google Start Menu"
* Super DragAndGo for tabs
* Greasemonkey
* Flashblock
* gTranslate
* Key Scrambler
* Python Sidebar

vendredi 29 décembre 2006

Switching from a Linux to a Windows Desktop

When I'm using a WinXP desktop I'm searching for an equivalent "Linux experience". Here's what I find useful so far (a mix of freeware and Free Software).

1) Look and feel

I don't like WinXP theme. CristalXP.net have great themes, wallpaper, icons, etc. I use the Microsoft "Royale Noir" a nice dark and sober theme.

Also very handy is iColorFolder to manage folders icons and the ability to quickly set their color for a better visual organisation.

You may also be interested by a Virtual Desktops Manager or want to access the "contextual" command line window from a right click on a folder or maybe to customize completely you're right click menu.

2)Shell and processes

This was the weakest point of winXP for me. Microsoft now released Power Shell and I must admit I find it good (it is just a little long to start). There are also aliases for usual Linux command (ls, pwd, cd /, etc) but I think Power Shell commands are very neat and clear.

Also, if you want to see the running processes in a graphical way Process Explorer is a great tool to replace the Task manager.

3)Copy/Paste and Screenshots

WinXP doesn't keep an history of your cut and paste actions and this can result in a loss of data. Cliptray is a freeware which solve this problem.

Linux distros always come with handy screenshots utilities. Cliptray can also do it but I prefer to use irfanview (tuto).

4)Security

Microsoft OS is unfortunately a big target. Apart from an antivirus and a firewall I feel safer to use Firefox and this KeyScrambler extension against eventual data loggers for login/passwords.

5)Applications

Software are not a problem since I'm using either web services (gmail, google reader,etc) and/or multi platform software (Vim,Python,OOo,Firefox,etc).

Also to work with a Linux PC or server Putty and WinSCP are a must.