Installation for Mac OS X Users
1. Install the downloaded .SIS files to your phone
Connect your phone to your computer using the USB cable, then select
‘Data transfer’ or ‘Mass storage’ mode on the phone screen. The memory
card of the phone is mounted as an external ‘hard drive’ and its content
can be accessed by the Finder application on the Mac. You must have
the memory card inserted into your phone.
Copy the downloaded installation files to any folder on the memory
card of your phone, for example, to the root. Safely remove (un-mount)
the phone’s drive from your computer in the same way as with any
external hard drive.
On the phone, open the File Manager application (usually found on
the desktop of the phone or inside a subfolder e.g. ‘Tools’) and go to
the directory of the memory card where you have stored the installation
files. Click on the installation files. First, install the PyS60 interpreter
(PythonForS60) and then the user interface for the PyS60 interpreter
(PythonScriptShell). Follow the on-screen instructions on the phone – for
instance, select ‘Yes’ if a security warning appears on the phone screen.
Also, make sure the date is set correctly on the phone.
After the installation is complete, your phone shows the Python icon
on the desktop or inside one of the desktop folders (Figure 2.1). Your
phone is now ready to execute Python scripts. Let’s prepare a ‘Hello
world’ script.
2. Write a Python Script
You can write a Python script on your computer with any text editor.
Useful editors are, for example, SubEthaEdit, TextMate or BBEdit. We do
not recommend using Mac’s TextEdit application, as it might place some
invisible characters in your code which throw an error when executing
the script.
Write the following line in your text editor:
print "Hello world!"
After the code is typed, save the file under the name hello.py. Make
sure that the file ending is .py and not .txt.
The file is now ready to be executed on your phone! You do not have
to build or compile it any way. However, it must be copied to the phone
first.
3. Upload a Python Script to a Phone
Again, connect the phone to your computer as an external ‘hard drive’.
Create a folder called Python on the phone’s memory card (drive E:)
using the Mac’s Finder application. Copy the hello.py file from your
computer to the E:\Python folder on the phone.
Safely remove (un-mount) the phone as an external hard drive from
the computer. You can now test the script.
If your Mac has built-in Bluetooth, you can use it to upload the
hello.py file to your phone. Click on the Bluetooth icon at the top
of the Mac screen (see Figure 2.8), select ‘Browse device’ and choose
your phone’s nickname from the list (Bluetooth must be switched on
on the phone). Then select ‘Browse’ to open a window showing the
phone’s memory card E:\. Drag and drop hello.py from the location
in your Finder application to the E:\Python folder in the newly opened
window. This saves you having to use the USB cable and mount and
un-mount the phone as an external ‘hard drive’.
4. Test a Python Script
Start the PyS60 interpreter by clicking on the Python icon (Figure 2.1) on
the desktop or inside the appropriate subfolder on your phone. Once the
PyS60 interpreter has started up, select ‘Options’ (Figure 2.4(a)) and ‘Run
script’ (Figure 2.4(b)). Choose your script name, e:hello.py, from the
list and select ‘OK’. Your script should now start up and you should see
a green line stating Hello world! (Figure 2.5).
Congratulations! You have successfully written and executed your
script with PyS60! To go through all the examples in the book, just repeat
steps 2–4 for each new script. Have fun with it!
No comments:
Post a Comment