Thursday, July 24, 2008

Go internationalize your Facebook application now

If you are a Facebook app developer, having more and more users to install your application is (hopefully) one of the main goal. If this applies to you, then here, take this tip. Facebook is going international. And, as always, it does not forget its fellow developers! Yes, actually it is going international for (almost) free, and it is now taking all of you to internationalize for (absolutely) free! The idea to achieve this is sort of slick, it is done via a official application called Translations. It has been there for quite a while already. As a normal user, you can install this application and pick a language to translate Facebook into a certain non-English language. So far some excellent work has been done. The Official part of Facebook (including the basic interface and official apps) speaks more than 15 languages today. But that's of course not the end of the story: Translations is now open to all third-party Facebook applications! I can't think of any reason not to do this: go install Translations and click Admin Panel. There you choose the language whose users you want (tick them all!). And your app will get internationalize in a couple of days! It is that easy.

Sunday, July 6, 2008

Launching the default web brower with Python

I found this in standard modules. So I put it here for a record: To open a certain web page(google.com, for example) with the system default web browse programmatically, do the following:
import webbrowser webbrowser.open('http://google.com')
Python didn't let me down this time.....again!

Thursday, July 3, 2008

Using py2exe and wxPython on Windows XP

In my opinion, wxPython is practically the most acceptable platform-crossing GUI toolkit. However neither it nor python are shipped with MS Windows. Since we can't expect our users to have python and wxPython installed, py2exe is no doubt a decent deal to make our python applications standalone. I had some trouble on the first trying it out on Windows XP, so I decided to write the solution here in case someone else encounters the same problem. Let me start at the very beginning. First of all you need to make sure everything needed is installed, for that matter, at least python, wxPython and py2exe must be there in our case. The versions of my installed packages are as following: Python: 2.5.2 py2exe: 0.6.6 for win32 python2.5 wxPython: unicode-2.8.7.1 for python 2.5 Just to be safe, you need to install python before the rest of the two packages. Now, I assume you have already tested & debugged your application into a satisfying status. All you need now is to make it standalone. Another assumption here is you know the path where python is installed.(I will use python25\ and emit the previous part in this essay) To achieve that, you need to write a setup.py script, which takes advantage of the method setup in standard module distutils.core. You can find instructions on py2exe's website for this step. Another good resource to learn it is the samples that come with py2exe, they are under the path Python25\Lib\site-packages\py2exe\samples You may want to refer to the python library reference to learn about distutils.core, but, before you get confused (which I did), I need to point out that py2exe added some additional options to the setup mothed, which will probably be all you'll be using. OK, a simplistic, but generally always working example of the setup.py would be:
from distutils.core import setup import py2exe setup(['MainScript.py']) # Replace MainScript.py with your script
Save the setup.py script in your app dictionary. Next thing is to make sure that you can run python in a command terminal. Which requires the path of python to be added in the Environment Variable PATH: 1 From the desktop, right-click My Computer and click properties. 2 In the System Properties window, click on the Advanced tab. 3 In the Advanced section, click the Environment Variables button. 4 Finally, in the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. Add a semicolon to the end if there isn't one, and then your python path. Open a command prompt(by running cmd), go to your app path, run the setup.py with the argument py2exe:
python setup.py py2exe
A lot of information shows up and then you will find two new dictionary in your app path, here you just need dist. If you wonder what's in there, check out the Official FAQ. But you won't find your exe working, because msvcp71.dll is missing, and changing the name of MSVRP71.DLL won't work. I think this is probably a bug of py2exe. So you need to copy 'Python\Lib\site-packages\wx-2.8-msw-unicode\msvcp71.dll' manually here. That's how I made my wxPython application work so far. Farther information is surely welcomed :).