Posts

Showing posts with the label Python for Mobile Phone

Py2SIS create sis file to make standalone application

You have coded the program and tested it using PyS60 emulator or in your mobile phone. Now you want to make standalone application out of your Python code to deploy in mobile phones. You have to create SIS (Symbian Installation System) file. Format of the command is: py2sis [sisfile] [--uid=0x12345678] [--appname=myapp] [--presdk20] [--leavetemp] I used the following command to create SIS file for my program: F:\Nokia\Tools\Python_for_Series_60\py2sis>py2sis.exe dse_stock_tracker.py dse.sis --uid 0x12345678 --appname=DSEStockPriceTracker If you want to know details about py2sis, get the book (ebook is there) "Programming with Python for Series 60 Platform" and go to chapter 14. The book is freely available.

PyS60 - download file using urlretrieve

The following function written in Python downloads a remote file to mobile phone. import urllib def download_file(): remoteFileName = u"http://example.com/a.txt" # set the url here localFileName = u"c:\\items.txt" urllib.urlretrieve(remoteFileName, localFileName) download_file() The code was used in my 'DSE Price Tracker' application in order to download the list of companies.

Create selection list from a file in PyS60

Image
Let's come back to the project - DSE price tracker. The next step was to load all the company names from a file (stored in the mobile phone memory) and display in the selection list. The file contains the company names, one per line. So I wrote the following code: import appuifw def get_data_from_file(): fp = open('c:\\names.txt', 'r') li = fp.readlines() fp.close() compList = [] for item in li: item = item.decode("utf-8") compList.append(item) return compList L = get_data_from_file() index = appuifw.selection_list(choices=L , search_field=1) Yes, it works. Note that you must decode each line to unicode (utf-8). ( item = item.decode("utf-8") ) But wait, what are those small boxes beside each name? I guess it's the newline character ('\n') after each line. So I need to replace '\n' with a blank ''. Here is the modified get_data_from_file() def get_data_from_file(): fp = open...

Create a selection list in PyS60

Image
Creating a selection list for my software - 'DSE Stock Tracker' was very important task. It will show the list of companies of Dhaka Stock Exchange. So for demo I tried to create a list of four companies. Here is the code: import appuifw L = ['DHAKABANK', 'AIMS1STMF', 'EXIMBANK', 'TRUSTBANK'] index = appuifw.selection_list(choices=L , search_field=1) I tried to run the program but got the following error: SymbianError: [Errno -6] KErrArgument Oh, I forgot to add the 'u' (u for unicode) before each string. So I changed my code and it works. import appuifw L = [u'DHAKABANK', u'AIMS1STMF', u'EXIMBANK', u'TRUSTBANK'] index = appuifw.selection_list(choices=L , search_field=1) Now, as there are hundreds of companies, it's not wise to write every name in the code. So the next to-do is load the list from a file.

First problem I faced in PyS60

When I tried to connect to a website using Python from my mobile phone, I got into trouble. Every time I tried a simple program I got the following error message: IOError:[Errno socket error](0, 'getaddrinfo failed') Here is the code I tried: import urllib usock = urllib.urlopen("http://example.com") data = usock.read() usock.close() I tried Google but couldn't find any good solution. Then I did some trial-n-error myself and got rid of the problem! Actually when I connect to Internet from my mobile phone I have 3 access points - GP-WAP, GP-MMS and GP-Internet. When I browse from my mobile phone (it's Nokia N70), I use GP-WAP. So when the python program asked for the option I selected that and got the error. When I selected GP-Internet, I got rid of the problem. Now I can connect the Internet using Python from mobile!!!

py60 - Python for S60

Yes, I have started using Python in my mobile phone !!! Python for S60 is Nokia's port of the Python language to the S60 smartphone platform. In addition to the standard features of the Python language, PyS60 provides access to many of the phone's uniquely smartphone-y functions, such as camera, contacts, calendar, audio recording and playing, TCP/IP and Bluetooth communications and simple telephony. (from http://wiki.opensource.nokia.com/projects/Python_for_S60 ) You can use emulator or your mobile phone (S60 platform) to run/test python programs. I use my Nokia N70 to run python and so far it's great fun! You can write the program in your computer and transfer it to your mobile phone. There is an interactive console in the mobile phone so that you can write your program directly in the mobile phone. There is another blue-tooth based console which I haven't tried yet. You can download the latest version of pyS60 from sourceforge . And I am using this tutorial in my p...