View Single Post
Posts: 376 | Thanked: 511 times | Joined on Aug 2009 @ Greece
#3
Originally Posted by ahmadka View Post
Hey all ... Well I've finally found some time to start trying to develop stuff for the N900, but there are some things which are confusing me which I need some assistance on ...

Firstly, I see there are two ways I can program for the N900: C++ and Python ... I've heard devloping using Python is somewhat easier, but since I dont know python and have been using c++ for 6-7 years now, I think C++ is the better option here ... Do you agree ?
What you heard is correct. I suggest you go with python first. I find python+qt to be easier than it should :-)

Open an ssh connection to your N900 and write this to a file:

Code:
#!/usr/bin/python

# Convenience imports
from PyQt4.QtCore import *
from PyQt4.QtGui import *

import sys

# This is a decorator class
class WinUi:
  # With only one function to decorate a window
  def setupUi(self, parent):
    self.centralwidget=QWidget(parent)
    parent.setCentralWidget(self.centralwidget)

    # A horizontal layout
    self.layout=QHBoxLayout(self.centralwidget)
   
    # With three items
    self.label=QLabel("Name:", self.centralwidget)
    self.txt=QLineEdit(self.centralwidget)
    self.but=QPushButton(self.centralwidget)

    l=self.layout

    # Add them to the layout
    l.addWidget(self.label)
    l.addWidget(self.txt)
    l.addWidget(self.but)
        
    # Se the label of the button
    self.but.setText("OK")

class Win(QMainWindow):
  def __init__(self):
    QMainWindow.__init__(self)

    # Setup the UI using the decorator class
    self.ui=WinUi()
    self.ui.setupUi(self)

    # Connect the mouse "clicked" event to a function
    self.ui.but.clicked.connect(self.click)

  def click(self):
    txt=self.ui.txt.text()
    if txt=='':
      QMessageBox.critical(self, "Error", "Please type something")
    else:
      QMessageBox.information(self, "Success", "You typed: %s" % txt)

# Standard things
# Create an application then create a window.
# Show the window and run the main loop
app=QApplication(sys.argv)
win=Win()
win.show()
app.exec_()
Take care of the spaces. They matter in python. Then run:

Code:
python myfile.py
where myfile.py is the filename you used.

The WinUi class will come from qt-designer so your program will be just the Win class and some standard stuff.

Being able to develop directly on N900 is an extra bonus of using python.