📜 ⬆️ ⬇️

Programming under N900 in Python

Among the topics on Habré, I found only a guide to programming in Python for the S60 platform. Being the proud owner of N900 and a Python fan, I decided to fix it.

Introduction

This article assumes knowledge of Python syntax, as well as basic semantics. To write an application for Maemo 5, you need the following tools:

Openssh

Install the OpenSSH server from the Extras-Devel repository. During the installation process, you will need to enter a username and password: the username must be root,
set the password at its discretion (I would not advise using the Cyrillic in the password).

PluThon

Everyone knows that Maemo contains an out-of-box Python interpreter. A simple script can be written on the device itself. But, you see, it is much more convenient to program in the IDE with underlining syntax, debugging, and other buns. One of the best options is to use IDE PluThon: it is based on Eclipse and allows you to develop an application on your computer, and then sends it over SSH to the N900 and runs there. To install PluThon, you need to download two archives from pluthon.garage.maemo.org/2nd_edition/installation.html for your OS.
After downloading, unpack both archives in the same folder and run:

Note: if you are using Ubuntu 9.10+, Fedora 11 or another system based on GTK + 2.18, then problems with running PluThon are possible: only an empty window will be launched that cannot be closed. To fix this, locate the pluthon.ini file in the pluton directory and add a line to the end of the file:

-Dorg.eclipse.swt.browser.XULRunnerPath = / dev / null
')
PluThon is now ready to go!

PyMaemo + PyQt4

Out of the box, Python comes only with standard modules, so you need to install additional libraries. Also, to create a GUI, you must install the Qt library for Python. To do this, perform the following operations in the terminal N900 (rootsh must be installed):

sudo gainroot
apt-get install python2.5-runtime
apt-get install python2.5-qt4-core python2.5-qt4-gui

We agree to the proposal to install and wait for the end of the installation. Now everything is ready for development!

Development

As befits the good old tradition of our first application will be called Hello World. To do this, run the OpenSSH server on the N900:

sudo gainroot
/etc/init.d/ssh start

Next, we launch PluThon and create a new project (menu File -> Pluthon Project -> Empty Python Project), then click Next and select the method of remote connection to the N900. Connection method: WLAN ad-hoc, also do not be lazy to enter the settings. Here you must correctly specify the IP-address of the device (it can be found with the command of ifconfig from under the root), as well as the user name (root) to work in the system. In order to avoid problems with access rights, I usually debug programs under the root, although this may be unsafe. Next, click the Next button and in the window that appears, you can select the version of Python. It is best to leave 2.5, for better compatibility with the N900 (Python interpreter version 2.5.4 there. Next, by clicking the Finish button, we create a project. In the src folder, add a new module: PCM -> New -> Pydev Module. Specify any name and click Finish .

# :
import sys # , Qt-
from PyQt4.QtCore import * # Qt-
from PyQt4.QtGui import *

# . QMainWindow.

class MainWindow (QMainWindow):
def __init__ ( self , * args):
apply (QMainWindow . __init__, ( self ,) + args) #
self . setWindowTitle( 'N900 Buttons!' ) #
self . bn1 = QPushButton( "Hello World" , self ) # 'Hello world'
# ( Qt) ()
self . bn1 . setFlat( 1 ) #
self . setCentralWidget( self . bn1) # ,
#
self . bn1 . clicked . connect( exit ) # -
#

# , ,

app = QApplication(sys . argv) #
win = MainWindow() #
win . show() #
sys . exit(app . exec_()) #


Now run the application Run -> Run As -> PluThon Application. Now we look at our N900 and something like this should appear there:

image

This button can be clicked, after which the application ends. Do not forget to turn off the SSH server after work:

root
/etc/init.d/ssh stop

Source: https://habr.com/ru/post/111370/


All Articles