Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is just for mikec and I�m just trying to make it look nicer with tools given. I will delete this if mikec finds this useful. And couple of things:
- - Does python add itself to Path environment automatically on windows?
- - There is text about executable permission so "python runnableprogram.py" vs " ./runnableprogram.py"
- -
- [SIZE=5]Qt Designer/Python for Windows XP in 30 Mins[/SIZE]
- 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 [URL="http://talk.maemo.org/showthread.php?p=461347#post461347"]Link[/URL]
- 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.
- [B]1. Install the Tools[/B]
- [LIST]
- [*]Get Python 2.6 from Python.org [URL="http://python.org/download/releases/2.6.4/"]Here[/URL]. This will install the Python interpretor and associated tools. Access from your start menu
- [IMG]http://farm5.static.flickr.com/4044/4337892570_91c711eaee_o.jpg[/IMG]
- [*]Get the Binary Packages for PyQt from Riverbank computing [URL="http://www.riverbankcomputing.co.uk/software/pyqt/download"]Here[/URL]. 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.
- [/LIST]
- [INDENT]
- [LIST]
- [*][B]PyQt[/B] 4.7 The Python Qt bindings (note 4.7 is not the Qt Release version).
- [*][B]Qt4 Designer[/B] , the GUI editor and layout manager for Qt GUIs.
- [*][B]PyUIC4[/B] , Converts your Qt Designer files to PyQt.
- [/LIST]
- When you have this package installed you will have an entry in your start menu like this
- [/INDENT][IMG]http://farm5.static.flickr.com/4005/4337892490_23e23d70d9_o.jpg[/IMG]
- Lets do a quick hello world that uses the above tools and links it all together.
- [B]2. Create UI with Qt Designer[/B]
- On Your Desktop machine
- [INDENT]1. Open Qt Designer from your start Menu.
- 2. Create a Main Window Form ,set its size to [B]800x400[/B]
- 3. Add a Label Widget, set the font to a 24 point, resize as needed.
- 4. Double click on the Label Widget to change its name to �Hello World !�
- 5. Use Control R to see how it will look.
- 6. Add buttons text and other widgets as you want by drag and drop from the widget menu.
- 7. Now save your form. File->Save As → �helloworld.ui�
- [/INDENT][IMG]http://farm3.static.flickr.com/2790/4337163813_34944f0f92_o.jpg[/IMG]
- [B]3.Generate your Python code.[/B]
- Open a command window from your start menu->accessories (also winkey+r type [B]cmd[/B]) and cd into the directory where you stored the ui file, and type in the following.
- [CODE]pyuic4 -x helloworld.ui -o helloworld.py[/CODE]the [B]-x[/B] generates additional code to allow you to test the ui element the [B]-o[/B] 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 PtQt app up and running.
- [B]
- 4. Deploy to your N900[/B]
- To get Full file system access follow guide [URL="http://talk.maemo.org/showpost.php?p=482844&postcount=1"]Here[/URL].
- ( 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
- [/code]You will get a GUI to SCP like this. make sure that you drop files to the[B] /opt[/B] directory on your N900
- [IMG]http://farm5.static.flickr.com/4053/4337893010_31229c0b84_o.jpg[/IMG]
- Now you can just drag and drop files from your desktop to your N900.
- [quote]!! 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.[/quote]Copy your helloworld.py file to your N900 [B]/home/opt[/B] directory
- Once your helloworld.py file is on your opt directory on your n900 you can execute like this from the Xterm. Like this ([B]run as user[/B])
- [CODE]$ python helloworld.py[/CODE][IMG]http://farm5.static.flickr.com/4061/4265575463_dff79c8bc7_o.png[/IMG]
- If your helloworld does not have the look and feel of Fremantle [U]make sure that you have installed latest PyQt from the application manager[/U] (Thanks Atilla)
- [B]5.Integrating into a Main Program[/B]
- 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[/CODE]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_())
- ===================================================[/CODE]Now just run the main.py from your n900
- python main.py.
- [B]Using PySide[/B]
- If you want to use Pyside (Nokias Bindings for Qt4 for Python), you will need to replace the line in your helloworld.py file that says:
- [I]From PyQt4 import PyQtcore QtGui[/I]
- with
- [I]From [B]PySide[/B] import PyQtcore QtGui[/I]
- [B]Bringing it all together into a Graphical IDE[/B]
- Now you have got your helloworld working its time to dive into a full blown IDE(Integrated development environment) ([URL="http://en.wikipedia.org/wiki/Integrated_development_environment"]Wiki[/URL]) and do a serious example.
- First we need to install an IDE that will pull all of our tools together. [B]Eric4[/B] works really well with Qt Designer. Install from here
- [URL]http://eric-ide.python-projects.org/[/URL]
- Using eric4 build your own browser in an Hour!!
- Heres the tutorial
- [URL]http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html[/URL]
- [B]Additional Resources[/B]
- some other tutorials I found helpful
- [URL]http://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/[/URL]
- [URL]http://lateral.netmanagers.com.ar/stories/BBS47.html[/URL]
- And the Qt4 Design manual
- [URL]http://doc.trolltech.com/4.0/designe...component.html[/URL]
- The Maemo Python Wiki Pages
- [URL]http://wiki.maemo.org/PyMaemo[/URL]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement