Active Topics

 


Reply
Thread Tools
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#1
Qt Designer/Python for Windows XP in 30 Mins

This is guide for noobs who would like to get started in Qt development using Python on Windows XP. For Linux users I have created a separate thread Link

The great news about using Python is there is no need to install the Maemo SDK. Python runs on
Windows,MAC and Linux as is, and its just a matter of copying your Python Scripts to your N900 and run.

1. Install the Tools
  • Get Python 2.6 from Python.org Here. This will install the Python interpretor and associated tools. Access from your start menu



  • Get the Binary Packages for PyQt from Riverbank computing Here. Select the Python 2.6 version which is the latest version compatible with Python on the N900. This will install a number of tools, but in particular the ones we are interested in for this Tutorial.
  • PyQt 4.7 The Python Qt bindings (note 4.7 is not the Qt Release version).
  • Qt4 Designer , the GUI editor and layout manager for Qt GUIs.
  • PyUIC4 , Converts your Qt Designer files to PyQt.
When you have this package installed you will have an entry in your start menu like this



Lets do a quick hello world that uses the above tools and links it all together.

2. Create UI with Qt Designer

On Your Desktop machine
  • Qt Designer from your start Menu.
  • Create a Main Window Form ,set its size to 800x400
  • Add a Label Widget, set the font to a 24 point, resize as needed.
  • Double click on the Label Widget to change its name to ìHello World !î
    Use Control R to see how it will look.
  • Add buttons text and other widgets as you want by drag and drop from the widget menu.
  • Now save your form. File->Save As → ìhelloworld.uiî



3.Generate your Python code.

Open a command window from your start menu->accessories (also winkey+r type cmd) and cd into the directory where you stored the ui file, and type in the following.

Code:
pyuic4 -x helloworld.ui -o helloworld.py
the -x generates additional code to allow you to test the ui element the -o tells it where to store the python "executable".

You now have a full python Qt4 GUI application ready to rock!!

Just double Click your helloworld.py file in the file manager and presto you have your first PyQt app up and running.

4. Deploy to your N900


Make sure you have installed Python and PyQt on your n900. Easiest way of doing this is to install the PyQt documentation package from the installation manager. This will pull in all the dependancies that you will need. Don't forget you will need to enable exrtras development repository.


To get Full file system access follow guide Here.
( this method uses WinSCP to do a secure copy to N900)

After setting up your N900 and Windows run WinSCp and enter your ip address and root login details.

To query your N900's ip adrress run in terminal:
Code:
$ sudo gainroot
  #  ifconfig | grep inet
You will get a GUI to SCP like this. make sure that you drop files to the /opt directory on your N900




Now you can just drag and drop files from your desktop to your N900.

!! dont forget to copy your python files to /opt on N900. If you copy to Mydocs directory you will not be able to change the permissions to Linux execute permissions as Mydocs is a FAT file system, it does not understand permissions.
Copy your helloworld.py file to your N900 /home/opt directory

Once your helloworld.py file is on your opt directory on your n900 you can execute like this from the Xterm. Like this (run as user)

Code:
$ python helloworld.py



If your helloworld does not have the look and feel of Fremantle make sure that you have installed latest PyQt from the application manager (Thanks Atilla)


5. Connecting UI to your Application

OK now that you have done your first prog, you will want to create an app that actually does something with the UI. Jump to Fatalsaints post in this thread for your next tutorial

http://talk.maemo.org/showpost.php?p...8&postcount=59



6.Integrating into a Main Program

The above technique will allow you to prototype quickly and let you play with the QT Designer.

However you should not edit the python file generated by pyuic4.

To build a real application you want to create a Main.py programme that has your gui generated file included.

First generate the file without the -x option in windows command window.

Code:
pyuic4 helloworld.ui -o helloworld.py
Now we create a Main.py program that calls the generated file.

Sample Main.py (may not work depending what you called your form)
Code:
==============Main.py============================= =====
#!/usr/bin/env python
import sys

#Now we include our helloworld.py generated from pyuic4.
from helloworld import *

# We instantiate a QApplication passing the arguments of the script to it:
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)

MainWindow.show()

# Now we can start it.
sys.exit(app.exec_())

===================================================
Now just run the main.py from your n900
python main.py.


Customize your GUI
If you want to take your Qt design skills a bit further, then see my second 30mins installment on customizing Qt look and feel and Python

http://wiki.maemo.org/Customising_Qt...hon_in_30_Mins


PyQt Versions
The latest PyQt 4.7 has now been released for N900 and will only work with Qt4.5 which is standard on firmware PR1.1.1
Qt4.6 will be supported when firmware PR1.2 is released


http://talk.maemo.org/showthread.php?t=42754

Using PySide

Pyside is not quit ready for Windows yet


Bringing it all together into a Graphical IDE

Now you have got your helloworld working its time to dive into a full blown IDE(Integrated development environment) (Wiki) and do a serious example.

First we need to install an IDE that will pull all of our tools together. Eric4 works really well with Qt Designer. Install from here

http://eric-ide.python-projects.org/

Using eric4 build your own browser in an Hour!!
Heres the tutorial

http://eric-ide.python-projects.org/...ser/index.html


Additional Resources

some other tutorials I found helpful

http://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/

http://lateral.netmanagers.com.ar/stories/BBS47.html

And the Qt4 Design manual
http://doc.trolltech.com/4.0/designe...component.html

The Maemo Python Wiki Pages


http://wiki.maemo.org/PyMaemo

Package your application to go into the repositories

https://wiki.maemo.org/Py2deb
__________________
N900_Email_Options Wiki Page

Last edited by mikec; 2011-02-20 at 12:28. Reason: Reformat and Tidy
 

The Following 115 Users Say Thank You to mikec For This Useful Post:
adhiemsumitro, ammyt, Arrancamos, attila77, bald.eagle.one, Berserk, biggzy, binu_ji, born2wonder, buurmas, candas1, casper27, ccarter, cduv, cfh11, cheve, Chrome, clasificado, coosbaytv, Cue, DanielMartin, danielwilms, dbl2010, Dexter1759, di1in, ejasmudar, El Amir, et3rnal, Fargus, fatalsaint, fatdat888, fmo, frals, gabby131, gilipter, godofwar424, gonediscin, harp, Helmuth, iKneaDough, ingvay7, inkirby, InoHacker, ioan, ivyking, jcharpak, joshv06, jule, kevinp93, kik, kojacker, kopte3, krc209, krk969, kwotski, luflux, Lullen, m1lan, maegon9y00, makel, MaLKaV, Mara, mark_ireland, McRae, MOC, mrmoosehead, msa, mscion, Munk, Netweaver, nikolajhendel, nikul.padhya, Nmigaz, noobmonkey, Omkar, Osilayer, ossipena, Patola, petibub, plastik, qwerty12, Rauha, realcomix, revamped, rpgAmazon, sadfist, saned, sifo, sixwheeledbeast, slender, snookh, Soder, Sopwith, Spotfist, techno2001, Texrat, TheAccountant, thecursedfly, Tiboric, tissot, tom047, v0id, v13, vdx29, verhagke, vkv.raju, wheatbisc, witchole, wizbowes, yerga, ymb, YoDude, zappa
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#2
Great walkthrough ! One tiny note - PyQt is even simpler nowadays, you don't even need root console or apt-get, just install the python2.5-qt4-doc package from the app manager.
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following 7 Users Say Thank You to attila77 For This Useful Post:
Texrat's Avatar
Posts: 11,700 | Thanked: 10,045 times | Joined on Jun 2006 @ North Texas, USA
#3
Sweet! I'll try this out in a little bit.
__________________
Nokia Developer Champion
Different <> Wrong | Listen - Judgment = Progress | People + Trust = Success
My personal site: http://texrat.net
 
Posts: 11 | Thanked: 1 time | Joined on Dec 2009 @ Lisbon, Portugal
#4
Exactly what I was looking for to start programming my N900
 
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#5
I'm missing something, as far as Im aware I don't have a root username and password. You have to go easy on me, Im a spoonfed windows boy.

I've got the ip address and have put it in WinSCP, I've tried username and password blank, and also username "root" and password blank but Im getting "connection refused" errors. Obviously I dont have the right details, is there a step I've missed out on?

It mentions in the OP that "default root password is not set on N900" - does that mean it's just blank and unused, or is there some sort of generic password, or does it mean I have to set one up somehow?

Last edited by kojacker; 2010-02-07 at 20:15.
 
Posts: 2,829 | Thanked: 1,459 times | Joined on Dec 2009 @ Finland
#6
ohh. There should be guide for setting up ssh server. Try search.

Could you mikec add that to your guide and perhaps it´s time for little wiki-page
 

The Following 2 Users Say Thank You to slender For This Useful Post:
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#7
Originally Posted by kojacker View Post
I'm missing something, as far as Im aware I don't have a root username and password. You have to go easy on me, Im a spoonfed windows boy.

I've got the ip address and have put it in WinSCP, I've tried username and password blank, and also username "root" and password blank but Im getting "connection refused" errors. Obviously I dont have the right details, is there a step I've missed out on?

It mentions in the OP that "default root password is not set on N900" - does that mean it's just blank and unused, or is there some sort of generic password, or does it mean I have to set one up somehow?
You have to install openssh-server on the N900, during the installation process, IIRC, it should ask you for a password. That becomes the "root" password for the device and you will use "root" and that password for WinSCP.

You won't be able to SSH to the device until openssh-server is installed.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 

The Following 4 Users Say Thank You to fatalsaint For This Useful Post:
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#8
Great, that makes sense - thanks Slender and FatalSaint for the help
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#9
Sorry.. I just realized someone new might be reading my post wondering WTF SCP has to do with SSH...

SCP is the file-transfer protocol for SSH. It relies on it. That way all of your file transfers are encrypted... so it's like FTP but secure.

In order to SCP you need SSH and to get SSH you need openssh-server.

Just trying to head off a question I am sure was going to crop up..
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 

The Following 8 Users Say Thank You to fatalsaint For This Useful Post:
Texrat's Avatar
Posts: 11,700 | Thanked: 10,045 times | Joined on Jun 2006 @ North Texas, USA
#10
Originally Posted by fatalsaint View Post
Just trying to head off a question I am sure was going to crop up..
More of that in general, please!
__________________
Nokia Developer Champion
Different <> Wrong | Listen - Judgment = Progress | People + Trust = Success
My personal site: http://texrat.net
 

The Following User Says Thank You to Texrat For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 12:24.