Advertisement
Guest User

Untitled

a guest
Feb 7th, 2010
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. 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:
  2. - Does python add itself to Path environment automatically on windows?
  3. - There is text about executable permission so "python runnableprogram.py" vs " ./runnableprogram.py"
  4. -
  5.  
  6. [SIZE=5]Qt Designer/Python for Windows XP in 30 Mins[/SIZE]
  7.  
  8. 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]
  9.  
  10. The great news about using Python is there is no need to install the Maemo SDK. Python runs on
  11. Windows,MAC and Linux as is, and its just a matter of copying your Python Scripts to your N900 and run.
  12.  
  13. [B]1. Install the Tools[/B]
  14. [LIST]
  15. [*]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
  16. [IMG]http://farm5.static.flickr.com/4044/4337892570_91c711eaee_o.jpg[/IMG]
  17. [*]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.
  18. [/LIST]
  19. [INDENT]
  20. [LIST]
  21. [*][B]PyQt[/B] 4.7 The Python Qt bindings (note 4.7 is not the Qt Release version).
  22. [*][B]Qt4 Designer[/B] , the GUI editor and layout manager for Qt GUIs.
  23. [*][B]PyUIC4[/B] , Converts your Qt Designer files to PyQt.
  24. [/LIST]
  25. When you have this package installed you will have an entry in your start menu like this
  26. [/INDENT][IMG]http://farm5.static.flickr.com/4005/4337892490_23e23d70d9_o.jpg[/IMG]
  27.  
  28. Lets do a quick hello world that uses the above tools and links it all together.
  29.  
  30. [B]2. Create UI with Qt Designer[/B]
  31.  
  32. On Your Desktop machine
  33. [INDENT]1. Open Qt Designer from your start Menu.
  34. 2. Create a Main Window Form ,set its size to [B]800x400[/B]
  35. 3. Add a Label Widget, set the font to a 24 point, resize as needed.
  36. 4. Double click on the Label Widget to change its name to �Hello World !�
  37. 5. Use Control R to see how it will look.
  38. 6. Add buttons text and other widgets as you want by drag and drop from the widget menu.
  39. 7. Now save your form. File->Save As → �helloworld.ui�
  40. [/INDENT][IMG]http://farm3.static.flickr.com/2790/4337163813_34944f0f92_o.jpg[/IMG]
  41.  
  42.  
  43. [B]3.Generate your Python code.[/B]
  44.  
  45. 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.
  46.  
  47. [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".
  48.  
  49. You now have a full python Qt4 GUI application ready to rock!!
  50.  
  51. Just double Click your helloworld.py file in the file manager and presto you have your first PtQt app up and running.
  52. [B]
  53. 4. Deploy to your N900[/B]
  54.  
  55. To get Full file system access follow guide [URL="http://talk.maemo.org/showpost.php?p=482844&postcount=1"]Here[/URL].
  56. ( this method uses WinSCP to do a secure copy to N900)
  57.  
  58. After setting up your N900 and Windows run WinSCp and enter your ip address and root login details.
  59.  
  60. To query your N900's ip adrress run in terminal:
  61. [code]$ sudo gainroot
  62. # ifconfig | grep inet
  63. [/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
  64.  
  65. [IMG]http://farm5.static.flickr.com/4053/4337893010_31229c0b84_o.jpg[/IMG]
  66.  
  67.  
  68. Now you can just drag and drop files from your desktop to your N900.
  69.  
  70. [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
  71.  
  72. 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])
  73.  
  74. [CODE]$ python helloworld.py[/CODE][IMG]http://farm5.static.flickr.com/4061/4265575463_dff79c8bc7_o.png[/IMG]
  75.  
  76.  
  77. 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)
  78.  
  79. [B]5.Integrating into a Main Program[/B]
  80.  
  81. The above technique will allow you to prototype quickly and let you play with the QT Designer.
  82.  
  83. However you should not edit the python file generated by pyuic4.
  84.  
  85. To build a real application you want to create a Main.py programme that has your gui generated file included.
  86.  
  87. First generate the file without the -x option in windows command window.
  88.  
  89. [CODE]pyuic4 helloworld.ui -o helloworld.py[/CODE]Now we create a Main.py program that calls the generated file.
  90.  
  91. Sample Main.py (may not work depending what you called your form)
  92. [CODE]==============Main.py============================= =====
  93. #!/usr/bin/env python
  94. import sys
  95.  
  96. #Now we include our helloworld.py generated from pyuic4.
  97. from helloworld import *
  98.  
  99. # We instantiate a QApplication passing the arguments of the script to it:
  100. app = QtGui.QApplication(sys.argv)
  101. MainWindow = QtGui.QMainWindow()
  102. ui = Ui_MainWindow()
  103. ui.setupUi(MainWindow)
  104.  
  105. MainWindow.show()
  106.  
  107. # Now we can start it.
  108. sys.exit(app.exec_())
  109.  
  110. ===================================================[/CODE]Now just run the main.py from your n900
  111. python main.py.
  112.  
  113. [B]Using PySide[/B]
  114.  
  115. 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:
  116. [I]From PyQt4 import PyQtcore QtGui[/I]
  117.  
  118. with
  119.  
  120. [I]From [B]PySide[/B] import PyQtcore QtGui[/I]
  121.  
  122.  
  123. [B]Bringing it all together into a Graphical IDE[/B]
  124.  
  125. 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.
  126.  
  127. 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
  128.  
  129. [URL]http://eric-ide.python-projects.org/[/URL]
  130.  
  131. Using eric4 build your own browser in an Hour!!
  132. Heres the tutorial
  133.  
  134. [URL]http://eric-ide.python-projects.org/tutorials/MiniBrowser/index.html[/URL]
  135.  
  136.  
  137. [B]Additional Resources[/B]
  138.  
  139. some other tutorials I found helpful
  140.  
  141. [URL]http://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/[/URL]
  142.  
  143. [URL]http://lateral.netmanagers.com.ar/stories/BBS47.html[/URL]
  144.  
  145. And the Qt4 Design manual
  146. [URL]http://doc.trolltech.com/4.0/designe...component.html[/URL]
  147.  
  148. The Maemo Python Wiki Pages
  149.  
  150. [URL]http://wiki.maemo.org/PyMaemo[/URL]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement