View Full Version : Windows Python and Qt in 30 mins
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 (http://talk.maemo.org/showthread.php?p=461347#post461347)
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 (http://python.org/download/releases/2.6.4/). This will install the Python interpretor and associated tools. Access from your start menu
http://farm5.static.flickr.com/4044/4337892570_4724d4abdf.jpg
Get the Binary Packages for PyQt from Riverbank computing Here (http://www.riverbankcomputing.co.uk/software/pyqt/download). 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
http://farm5.static.flickr.com/4005/4337892490_973d5bcb48.jpg
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î
http://farm3.static.flickr.com/2790/4337163813_3da33c11e3.jpg
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.
pyuic4 -x helloworld.ui -o helloworld.pythe -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 (http://talk.maemo.org/showpost.php?p=482844&postcount=1).
( 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:
$ 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
http://farm5.static.flickr.com/4053/4337893010_31229c0b84_o.jpg
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)
$ python helloworld.pyhttp://farm5.static.flickr.com/4061/4265575463_1743df942c.jpg
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=515218&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.
pyuic4 helloworld.ui -o helloworld.pyNow we create a Main.py program that calls the generated file.
Sample Main.py (may not work depending what you called your form)
==============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_look_and_feel_and_Python_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 (http://en.wikipedia.org/wiki/Integrated_development_environment)) 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/tutorials/MiniBrowser/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
attila77
2010-02-07, 16:33
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.
Sweet! I'll try this out in a little bit. :)
Exactly what I was looking for to start programming my N900
kojacker
2010-02-07, 20:04
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?
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 :)
fatalsaint
2010-02-07, 20:21
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.
kojacker
2010-02-07, 20:24
Great, that makes sense - thanks Slender and FatalSaint for the help :)
fatalsaint
2010-02-07, 20:28
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..
Just trying to head off a question I am sure was going to crop up..
More of that in general, please! :D
Mike, in that first post, it should be "(note 4.7 is not the Qt Release version)"... not the other way around :-)
kojacker
2010-02-07, 20:46
I've got my file copied across and can see it in WinSCP sitting in the /opt/ folder on my n900, along with bounce and some other stuff. When I exit sudo gainroot to "run as user" (thats right?) and type in the command by the $ prompt "python helloworld.py" it cant find the file ("No such file or directory"). Do I have to navigate first to the /opt/ folder and run it from there?
BTW my next question would be, how do I navigate in xterm .. but you knew that already ;) :p
fatalsaint
2010-02-07, 20:48
I've got my file copied across and can see it in WinSCP sitting in the /opt/ folder on my n900, along with bounce and some other stuff. When I exit sudo gainroot to "run as user" (thats right?) and type in the command by the $ prompt "python helloworld.py" it cant find the file ("No such file or directory"). Do I have to navigate first to the /opt/ folder and run it from there?
BTW my next question would be, how do I navigate in xterm .. but you knew that already ;) :p
Yes.. using either of these two options:
cd /opt/
python helloworld.py
OR
python /opt/helloworld.py
For Future reference.. I would recommend while testing.. to just copy it to your home directory, or under your home directory make a "projects" folder to dump it in. No reason to clutter your /opt/ until your ready to actually package it for deployment.
ETA: I see the OP and I have a disagreement there as that's where he tells you to put it. *shrug* I just don't see a reasoning for it.. better to fill the 30GB area with junk and leave the /opt/ 2GB for ready-to-go apps IMHO.
kojacker
2010-02-07, 20:54
Thanks fatalsaint, everything's up and running :) I had been trying "cd opt" (like cmd in Windows) for the past 5 mins, I should have thought to add the slashes...
Only problem is I notice the app isn't working in portrait mode..
.. ssssh just kidding! :cool:
I'm gonna like this ^ guy.
fatalsaint
2010-02-07, 21:01
I'm gonna like this ^ guy.
Agreed! That made me laugh.
PS: I know it was a joke... but, as far as python goes, getting that functionality is actually supposed to be really easy ('http://wiki.maemo.org/PyMaemo/Portrait_mode'). ;)
ETA: I just realized that looks more for GTK than QT.. I'm sure it could be adapted though since the actual heart of it is the dbus.
ETA: I see the OP and I have a disagreement there as that's where he tells you to put it. *shrug* I just don't see a reasoning for it.. better to fill the 30GB area with junk and leave the /opt/ 2GB for ready-to-go apps IMHO.
But he said
!! 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.
.edit
But that doesn't probably matter if you use "python2.5 runnablescript.py" command?
fatalsaint
2010-02-07, 21:05
But he said
.edit
But that doesn't probably matter if you use "python2.5 runnablescript.py" command?
Ah.. well it's a good point but yes you're correct.. since you're passing "python" first it won't matter.
Where it *would* matter is if you tried to run it as so:
./helloworld.py
This is just for mikec and Iīm just trying to make it look nicer. Couple of things:
- Does python add itself to Path environment automatically on windows?
- There is text about executable permission so to avoid confusion "python runnableprogram.py" or " ./runnableprogram.py"?
http://pastebin.com/m4beb4c07
(copy from lower part)
And Thanks for this nice guide!
goriofab
2010-02-07, 21:55
Can anyone help me, please..
I'm a windows 7 (x64) user and i got this message when i try to convert my .ui file to .py
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\PyQt4\uic\pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
Thanks
noobmonkey
2010-02-07, 22:08
Wow i'm soooooooooo close!
This is the closest i have got to getting a program working! - i know i have whinged in the past - as i used to do VB programming, so like it all in one place, on a plate so to speak - but this seems almost as good!
Well until i missed something most likely.
Getting a trackback error
ImportError: No module named PyQt4
This happens when i run my demo hello world file.
I'm assuming i need to install something extra on my n900? (I'm guessing an apt-get thingymebob-doodaaa?!?)
Have tried googling, but they all point at me not having something, and they all seem to be linux desktopy related, not sure what the fix would be on my n900. (I know they are similar, but best to ask to make sure!) :S
Must say i can run it on my pc, so not the same error as above :)
fatalsaint
2010-02-07, 22:11
Getting a trackback error
ImportError: No module named PyQt4
sudo gainroot
apt-get install python2.5-qt4-gui
noobmonkey
2010-02-07, 22:15
OMG!!!
I did it!!! - (And in case someone has posted before me - i havnt refreshed!)
Sreached these forums a bit more specifically and found this thread (http://talk.maemo.org/showthread.php?t=42400)
Now working fine!!!
noobmonkey
2010-02-07, 22:16
sudo gainroot
apt-get install python2.5-qt4-gui
Haha, thank you very much - knew someone would beat me too it - but did do it without your post (Not being rude, but feeling slightly proud!!) hehehe
Thankyou so much! :) - will post screeny of my app soon - (How many hello worlds have you seen before! lol!)
fatalsaint
2010-02-07, 22:18
Haha, thank you very much - knew someone would beat me too it - but did do it without your post (Not being rude, but feeling slightly proud!!) hehehe
Thankyou so much! :) - will post screeny of my app soon - (How many hello worlds have you seen before! lol!)
Hey.. no big deal.. it was my answer in both threads :D.
noobmonkey
2010-02-07, 22:18
ANd here's my first ever n900 app!!!
http://farm5.static.flickr.com/4006/4339034432_c673144669_o.png
edit - thanks saint, again :) :) - all help in both threads is very appreciated!!
My question is, what sort of GUI design capability do we have (via Python) without the SDK?
noobmonkey
2010-02-07, 22:22
My question is, what sort of GUI design capability do we have (via Python) without the SDK?
tex, don't get all geeky-techno on me now!! lol (Ok i know that q wasn't aimed at me!)
I personally now need to know how to actually code in python i assume...... as in windows/VB i would just double click the form, and code.... (damn there's that plate of easyness again!)
fatalsaint
2010-02-07, 22:25
My question is, what sort of GUI design capability do we have (via Python) without the SDK?
You just have to code the GUI calls yourself instead of using Qt-Designer. It's more of a pain but still doable.
Have a look here:
http://zetcode.com/tutorials/pyqt4/firstprograms/
All of those are self-contained examples that do all of the drawing and layout right in the code.. instead of importing it from a pyuic4 created py from a UI file.
Obviously.. designing a UI inside Qt-Designer and using pyuic4 is extremely recommended for heavier duty windows.
You actually don't need the SDK at all.. on any machine that runs QT Designer you can use that, then use pyuic4 to convert it to a py and send it to your N900.. then code your main app on your N900 using that py file as a module to be imported.
I did all development of pypianobar in my sig using VIM. Some (myself included) would call that masochistic and crazy.. but I was too lazy to setup an IDE environment and VIM gave me syntax highlighting and indenting.. which is all I needed.
Technically.. that could have all been done on the device itself.
fatalsaint
2010-02-07, 22:27
I personally now need to know how to actually code in python i assume...... as in windows/VB i would just double click the form, and code.... (damn there's that plate of easyness again!)
This is how QT4 Designer works. You just open a Main Window (FORM) and drag drop your widgets into place and save it.
Then you use pyuic4 as described in the op to automatically convert that to python code for you.
But yes.. at that point you'll need to know how to code Python to actually work with it.
Original post needs expanding. :D
Amd yeah, it's wiki time.
goriofab
2010-02-07, 22:34
I'll post a picture from my error..
OBS. i'm on Windows 7 64 bits
fatalsaint
2010-02-07, 22:37
Original post needs expanding. :D
Amd yeah, it's wiki time.
A better example of an app other than Hello World should be done.
Maybe something like a very basic list/note app that lets you add/remove text from a list box or something.
I've always found those kinds of examples to be much more useful than a simple "hello world"... The thing with PyQt4 though.. is nearly *any* tutorial you find anywhere will work fine. Python is Python is Python.. the same code will run on Desktop, SDK, Laptop, Netbook, to Tablet. Windows, Mac or Linux.
No code changes for me were needed to run my apps on my N810, or my Desktop.. this is what makes interpreted languages so simple. As long as the libraries and modules are there.. it will "just work".
Good example would be app that communicates with some of phones devices or fetches information from address book.
Or a simple twitter app, since that will likely be my first attempt. :D
sudo gainroot
apt-get install python2.5-qt4-gui
"Could not open lock file /var/lib/dpkg/lock - open (13 permission denied) yadda yadda yadda... are you root?"
:rolleyes:
noobmonkey
2010-02-07, 23:03
loving this, figured out how to do a message box :)
(It loads on program load tho) - got a button on the screen now, going to try and get the messagebox loading after a press! - wish me luck!!
fatalsaint
2010-02-07, 23:06
"Could not open lock file /var/lib/dpkg/lock - open (13 permission denied) yadda yadda yadda... are you root?"
:rolleyes:
Do you have the app manager open?
Do you have the app manager open?
Did earlier, but not now. Still get error. Maybe I need to reboot?
fatalsaint
2010-02-07, 23:15
Did earlier, but not now. Still get error. Maybe I need to reboot?
shouldn't have to... that usually just means *something* is open that is tying up apt.. most common case is app manager.. if you're installing someone with dpkg that could do it..
But.. obviously a reboot will clear any of the problems and would probably be faster than trying to figure it.
---------------
I'm working really quickly on a "first program" tutorial that will just have two list boxes and an input box.. you can add items to the box on the left and move them to the box on the right with buttons.
This will show examples of how to connect functions to signals and what-not.. I don't do wiki's though.. I'll post it here. Someone else can take the OP and then my screenshots and stuff and make a wiki article.
noobmonkey
2010-02-07, 23:19
wow.... indents ... evil things!!!
Figured out the code i need, but using wordpad..... keeps giving me indent errors! lol!
noobmonkey
2010-02-07, 23:27
beaten for 5 minutes, but not out!!!
Now i have a program that has an input field, and a button. You press the button and it has a popup message as follows! :)
http://farm3.static.flickr.com/2764/4338494955_942179db15_o.png
fatalsaint
2010-02-07, 23:32
wow.... indents ... evil things!!!
Figured out the code i need, but using wordpad..... keeps giving me indent errors! lol!
Yes. This one thing that annoys me about Python. It's not so much the indenting, I do like structure, but there is no "end" tag.
I really prefer ruby for that. Python can get.. so ugly.
noobmonkey
2010-02-07, 23:32
keep forgetting it's open source - and someone (Tex?) may want to have a look? :)
import PyQt4
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class HelloWindow(QtGui.QMainWindow):
def __init__(self, win_parent = None):
#Init the base class
QtGui.QMainWindow.__init__(self, win_parent)
self.create_widgets()
def create_widgets(self):
#Widgets
self.label = QtGui.QLabel("Say hello:")
self.hello_edit = QtGui.QLineEdit()
self.hello_button = QtGui.QPushButton("Push Me!")
#connect signal
QtCore.QObject.connect(self.hello_button
, QtCore.SIGNAL("clicked()")
, self.on_hello_clicked)
#Horizontal layout
h_box = QtGui.QHBoxLayout()
h_box.addWidget(self.label)
h_box.addWidget(self.hello_edit)
h_box.addWidget(self.hello_button)
#Create central widget, add layout and set
central_widget = QtGui.QWidget()
central_widget.setLayout(h_box)
self.setCentralWidget(central_widget)
def on_hello_clicked(self):
QtGui.QMessageBox.information(self
, "Hello!"
, "Hello %s" % self.hello_edit.displayText()
, QtGui.QMessageBox.Ok)
if __name__ == "__main__":
# Someone is launching this directly
# Create the QApplication
app = QtGui.QApplication(sys.argv)
#The Main window
main_window = HelloWindow()
main_window.show()
# Enter the main loop
app.exec_()
this is my py file - i think my first steps have to be learning the layout of python, even before the code - seems simple enough at the moment though....
attila77
2010-02-07, 23:45
"Could not open lock file /var/lib/dpkg/lock - open (13 permission denied) yadda yadda yadda... are you root?"
:rolleyes:
Hey, see post #2, you're overdoing it. Just install python2.5-qt4-doc from the application manager, no root/console funk needed.
The apt-get way of installing a basic PyQt is (sort of) officially deprecated, as then you would have to just through the same hoops to uninstall it. it's much cleaner to do via the App Manager.
PS. And if you don't happen see python2.5-qt4-doc/PyQt in the application manager, blame Extras testing procedures and wait ~24 hours (we're day 9 of the 10 day quarantine period).
fatalsaint
2010-02-07, 23:47
Hey, see post #2, you're overdoing it. Just install python2.5-qt4-doc from the application manager, no root/console funk needed.
The apt-get way of installing a basic PyQt is (sort of) officially deprecated, as then you would have to just through the same hoops to uninstall it. it's much cleaner to do via the App Manager.
PS. And if you don't happen see python2.5-qt4-doc/PyQt in the application manager, blame Extras testing procedures and wait ~24 hours (we're day 9 of the 10 day quarantine period).
How many of python's bindings does that depend on? If all you need is qt4-gui why get all the rest? Waste of space. IMHO.
Thanks attila, and no, I didn't see python2.5-qt4-doc/PyQt in app manager. But I downloaded the bulk package earlier. Maybe that's why I got the error?
this is my py file - i think my first steps have to be learning the layout of python, even before the code - seems simple enough at the moment though....
What I like about Python is that it's so intuitive for a VB.Net programmer. I read through my books and everything makes quick and easy sense. Object orientation for the win! :)
noobmonkey
2010-02-07, 23:59
What I like about Python is that it's so intuitive for a VB.Net programmer. I read through my books and everything makes quick and easy sense. Object orientation for the win! :)
hehe - well kinda, OOP has allways been my nemesis, and i struggled a bit to begin with in .net, but i suppose that patience is paying of for this patience :)
this does feel a bit more like home for me. Tried the madde approach, and just couldnt figure it out. And the hello world, + installs took me 15 minutes in this example! :)
and an extra 20 to get extra buttons etc....
I think over the next few weeks i'll start playing with all the widgets before i kick off trying to make a proper application :) (Allthough i wonder how many hellow worlds we could fit in the repositories?!) hehe
attila77
2010-02-08, 00:22
How many of python's bindings does that depend on? If all you need is qt4-gui why get all the rest? Waste of space. IMHO.
Please, let's not confuse people.
I intentionally threw out a lot of dependencies of that package so they could start off with a reasonable minimum. That means Core, GUI, XML and Help. Core and XML are IIRC part of PR1.1. GUI is needed anyway. Help is maybe an overkill as not many would have Qt Docs on the N900 anyway, and you are free to improve on the demo app inherited from upstream to rid it of the QtHelp dependency (as Nokians say, patches welcome :) ).
The *advantages* of going through the app manager instead of apt-getting IMHO outweigh the 10 megs of optified space you save:
You get automatic updates
You can uninstall cleanly without potential sideeffects
No need for root user and console operations
You get about 50 examples of various Qt classes implemented in a Qt App
You get html documentation of the Python implementation of Qt classes
You get a demo app, which shows the examples from above in a user-friendly manner, again, no console-mongering needed
Now, if you KNOW what you need PyQt for and need no examples, no Maemo integration, updates, whatever, you are, of course, free to install through apt-get, but that is not the point of this thread (how to START developing in Python and Qt).
kojacker
2010-02-08, 00:27
Can anyone help me, please..
I'm a windows 7 (x64) user and i got this message when i try to convert my .ui file to .py
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\PyQt4\uic\pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
Thanks
Double check you are not trying to run the 32 version on your 64 machine. There are two installers on the page, it might sound silly but make sure you've got the proper version :)
goriofab
2010-02-08, 00:34
Double check you are not trying to run the 32 version on your 64 machine. There are two installers on the page, it might sound silly but make sure you've got the proper version :)
I installed a virtual machine with winxp but i don't know now how to fix this error..
Traceback (most recent call last):
File "hello.py", line 10, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
Where can i get it ?
Thks
kojacker
2010-02-08, 00:46
I think it means that PyQt4 is either missing or not installed properly. You can get it for your desktop machine from http://www.riverbankcomputing.co.uk/software/pyqt/download.
Im not sure if, by running XP as a virtual machine, how that may effect the installation.
On the n900, you can download it from app manager or it'll come with other applications you install that make use of python. I think gpodder is one of them..
fatalsaint
2010-02-08, 00:49
I intentionally threw out a lot of dependencies of that package so they could start off with a reasonable minimum. That means Core, GUI, XML and Help. Core and XML are IIRC part of PR1.1.
Ok, Fair enough.. I wasn't trying to argue with you. I don't have one and didn't go look at it in the web-based extras-testing to see the dependencies. I didn't know if you depended on just "python2.5-qt4" for example which pulls a whole stream of stuff, or specifically python2.5-qt4-gui.
So it's cool.. install from app manager.. fair enough.
goriofab
2010-02-08, 00:52
Traceback (most recent call last):
File "hello.py", line 10, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
this erro start when i type in my n900
python hello.py
I already installed PyQt-Py2.6-gpl-4.7-1
kojacker
2010-02-08, 00:56
hmm.. you are using 2.6 and im using 2.5
Maybe you could try installing the 2.5 package to see if it helps?
apt-get install python2.5-qt4-gui
Edit: Scratch that, I don't think it would make any difference... hmm
Im afraid I dont know enough to help you out with this one..
If you just type "python" at the n900 terminal, do you get the python info returned? You might just need reinstall the pyqt package again...
fatalsaint
2010-02-08, 00:58
To show attila for a third time now:
http://talk.maemo.org/showpost.php?p=515107&postcount=45
Install from App Manager instead of Apt-get like I suggested.. it has benefits.
goriofab
2010-02-08, 01:07
hmm.. you are using 2.6 and im using 2.5
Maybe you could try installing the 2.5 package to see if it helps?
apt-get install python2.5-qt4-gui
Edit: Scratch that, I don't think it would make any difference... hmm
Im afraid I dont know enough to help you out with this one..
If you just type "python" at the n900 terminal, do you get the python info returned? You might just need reinstall the pyqt package again...
Python 2.5.4 (r254:67916, Nov, 26 2009, 22:24:46)
[GCC 4.2.1] on linux2
I installed now with apt-get install python2.5-qt4-gui and my software was running 100% :)
Is there anyway do make a package from my software ?
fatalsaint
2010-02-08, 01:45
Ok, here's a quick tutorial on creating your first app and connecting some signals. The OP shows you how to set everything up so this is going to assume you already have Qt Designer and pyuic4 setup correctly. Screenshots are from the Ubuntu Virtual Machine with the SDK.. but same logic would apply to windows or anything.
So here we go, open up QT designer and create a Main Window:
http://packages.linuxniche.net/pyimg/qt-designer-open.png
http://packages.linuxniche.net/pyimg/create-main-window.png
Lets set the Main Window size to 800x400:
http://packages.linuxniche.net/pyimg/set_size.png
Now we want to create a "Quit" menu item just to show how they work later on in python code.
http://packages.linuxniche.net/pyimg/quit_menu.png
Now, using the widget selector screen
http://packages.linuxniche.net/pyimg/designer_buttons.png
We click and drag 2 ListWidgets, on either side of the Main Window, and then 5 pushbuttons and a LineEdit in between them. I named the two listWidgets "listRight", and "listLeft" as so:
http://packages.linuxniche.net/pyimg/name_right.pnghttp://packages.linuxniche.net/pyimg/name_left.png
Using the same screens, I named the buttons:
"btnAdd", "btnAllAdd", "btnRemove", "btnAllRemove", "btnAddNew" and the LineEdit to "lineNew".
Because I like to make things expandable to fit the screen (in case it needs to be resized or is run on something other than a static 800x400 window), we are going to do some grouping too (this is all just for show case). So we add a vertical spacer widget select all the buttons in the middle with the Line Edit and do a Layout Vertically, as so:
http://packages.linuxniche.net/pyimg/layout.png
Then add two Vertical Spacer widgets to the top and bottom, select them all, and do a layout vertically again.
http://packages.linuxniche.net/pyimg/layout_middle.png
Now add the Horizontal Spacer widgets shown above to either side, right click on the background Main Window page, and do a "Layout in a Grid". What we end up with is:
http://packages.linuxniche.net/pyimg/list_example_finished.png
Now we're done with QT Designer! So we want to save, and I called it "list_example.ui":
http://packages.linuxniche.net/pyimg/list_example.png
This gives us a standard QT .ui file which would normally be used by a C++ app. But we want python code, so, doing what the OP and every other tutorial tells us to we use pyuic4:
http://packages.linuxniche.net/pyimg/pyuic4.png
pyuic4 -o list_example_ui.py list_example.ui
That gives us new python file. Unfortunately, we can't run that file directly as all it is is the GUI - we need to launch it somehow, so we create the main python app and I called it "list_example.py" with the following code:
#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from list_example_ui import *
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
#This function means this was run directly, not called from another python file.
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
http://packages.linuxniche.net/pyimg/list_example_ui_basic.png
Now we can run list_example.py directly. If it's on the N900, use "python list_example.py", if you're in the SDK/Scratchbox and want to see it show up properly in Xephyr you use "run-standalone.sh python list_example.py" and voila! We get:
http://packages.linuxniche.net/pyimg/list_example_ui_basic_run.png
But, of course, nothing works! So we close out and decide we want those buttons to actually do something. We know we have 5 buttons, and 1 menu item, so we know we are going to need 6 connects. So lets try some:
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#connect buttons
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
QtCore.QObject.connect(self.ui.btnAllAdd, QtCore.SIGNAL('clicked()'), self.doAllAdd)
QtCore.QObject.connect(self.ui.btnRemove, QtCore.SIGNAL('clicked()'), self.doRemove)
QtCore.QObject.connect(self.ui.btnAllRemove, QtCore.SIGNAL('clicked()'), self.doAllRemove)
QtCore.QObject.connect(self.ui.btnAddNew, QtCore.SIGNAL('clicked()'), self.doAddNew)
QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))
Now, we've connected all 6 items to something. But python has no idea what the things like "self.doAdd" and "self.doAllAdd" are. The only one of those connects that will work is the last one for the "Quit" menu item because we connected it to a built-in qt "quit" slot.
So, now we create various functions (also called methods) that correspond to the names we connected the buttons to:
#Create Sub's
def doAdd(self):
add = 1
for i in range(self.ui.listRight.count()): #let's not create duplicates, so lets do a search.
if self.ui.listRight.item(i).text() == self.ui.listLeft.currentItem().text():
add = 0
if add: #Okay, it wasn't found. Let's add it.
self.ui.listRight.addItem(self.ui.listLeft.current Item().text())
def doAllAdd(self): #This ones easy, just clear the right one, go through all the left items and add them.
self.ui.listRight.clear()
for i in range(self.ui.listLeft.count()):
self.ui.listRight.addItem(self.ui.listLeft.item(i) .text())
def doRemove(self): #Easy again, just remove the selected item.
self.ui.listRight.takeItem(self.ui.listRight.curre ntRow())
def doAllRemove(self): #Super Easy.
self.ui.listRight.clear()
def doAddNew(self): #Pretty easy, just add to the left what is in the text box, then clear it out.
self.ui.listLeft.addItem(self.ui.lineNew.text())
self.ui.lineNew.clear()
So, we put it all together and we have (without the above comments):
#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from list_example_ui import *
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#connect buttons
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
QtCore.QObject.connect(self.ui.btnAllAdd, QtCore.SIGNAL('clicked()'), self.doAllAdd)
QtCore.QObject.connect(self.ui.btnRemove, QtCore.SIGNAL('clicked()'), self.doRemove)
QtCore.QObject.connect(self.ui.btnAllRemove, QtCore.SIGNAL('clicked()'), self.doAllRemove)
QtCore.QObject.connect(self.ui.btnAddNew, QtCore.SIGNAL('clicked()'), self.doAddNew)
QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))
#Create Sub's
def doAdd(self):
add = 1
for i in range(self.ui.listRight.count()):
if self.ui.listRight.item(i).text() == self.ui.listLeft.currentItem().text():
add = 0
if add:
self.ui.listRight.addItem(self.ui.listLeft.current Item().text())
def doAllAdd(self):
self.ui.listRight.clear()
for i in range(self.ui.listLeft.count()):
self.ui.listRight.addItem(self.ui.listLeft.item(i) .text())
def doRemove(self):
self.ui.listRight.takeItem(self.ui.listRight.curre ntRow())
def doAllRemove(self):
self.ui.listRight.clear()
def doAddNew(self):
self.ui.listLeft.addItem(self.ui.lineNew.text())
self.ui.lineNew.clear()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
And our final application:
http://packages.linuxniche.net/pyimg/finished.png
Yay, not the most useful app.. this is entirely just a "look, it works".. leave it up to you guys to make something useful. ;)
I don't know if anyone will actually *find* any of this any more/less useful than other tutorials.. but maybe some of the images can be used for whoever does the wiki article.
Thanks fatalsaint.
I need to turn my pseudocode into Python for my twitter idea (http://talk.maemo.org/showthread.php?t=37458), and everything in this thread should get me to the next point. :)
kojacker
2010-02-08, 01:54
Superb tutorial, fatalsaint :)
Guys
lots of activity while I was alseep :D
i'll update the orignial post based on all the comments so far, and look to pushing into a wiki, and build in Fatalsaints additonal intermediate Howto. I was thinking of doing the same, as I have been knocking up a simple calculator app as an example. I;ll use Fatalsaints example though, and will Windowize it as its clear you non linux blokes cant cope :D
kojacker
2010-02-08, 12:12
It wouldn't do any harm to have the calculator example too, mikec, Im greedy for code :cool:
Im hoping somebody might make an example for game dev, I miss my easy-peasy symbian GameCanvas class. Possibly not in this thread, but maybe some simple examples using QT or pygame like tiling, animated sprite handling, keyboard input controls, yadda yadda would be brill
attila77
2010-02-08, 13:02
PyQt examples are your friend. You have (among many other goodies) both a calculator (widgets/calculator) and a canvas-based sprite animaton example (graphicsview/collidingmice).
PyQt examples are your friend. You have (among many other goodies) both a calculator (widgets/calculator) and a canvas-based sprite animaton example (graphicsview/collidingmice).
And just to save you doing a search. Once you have installed PyQt the examples live In:-
Windows
"Start" -> "All Programs" -> "PyQt GPL v4.x.x" -> "Examples Source" for many tutorials and examples ported from C++/QT to Python/PyQt.
attila77
2010-02-08, 17:56
...and if you're looking for them on the N900, they live under /usr/share/python2.5-qt4-doc/examples
kojacker
2010-02-08, 18:10
Thanks Atilla, I already had them and they are great to have.
It would still be nice to see these individual tutorials expand into other topics because I find I learn more from them. For example, from the examples pack what they lack (to me) is the specific focus on individual topics and the step by step/author's thoughts/reasoning/ability to ask questions like we can get here which helps so much with the "why we do" aswell as learning "what to do".
Aswell as the game dev topics mentioned earlier, I'd like to maybe see a quick tutorial on using PyQt to create/write to and read from a database on the device, capturing an image from the camera to store or use in an application, and other stuffs i cant think of at the mo'.
hi,
everything works fine for me. are there some examples to make a desktop widget with python and qt?
Here is a Python Calculator Example. A few things still not quite working but I figured you guys would want to fix the Bugs :D
Download from Here
http://www.megaupload.com/?d=ZCFJ99VS
Unzip the directory to get to the source code. Still very untidy from a Python beginner :)
Main Prog is ncalc.py
Ui File is in the UI directory called calc.ui (load up in qt designer to play with)
UI_calc.py is generated by pyuic4
calcstub.py contains all the program logic to handle the keys
copypaste.py is a stub file to handle menu options (not yet implemented)
To run on your N900 just type
$ python ncalc.py
Here is what you might get with the N900 shiny theme
http://farm5.static.flickr.com/4035/4341862520_68e4d8f008.jpg
noobmonkey
2010-02-08, 22:11
heya... probably a stupid question....
But i understand the QT creator part (Just about) and can create a form/window screen bit.....
Is there any good tools for editing the python file? (Still struggling with the indents etc...)
Getting very confused searching for pyqt and tools....... i'm getting lost in the world of other languages/tools/code examples..... :| :( :( :|
noobmonkey
2010-02-08, 22:15
oh and as a starter i'm trying to figure out simple things like how to get the battery status....
Seen terminal commands that bring it up, and think i need to parse that to get what i need out.... but kinda annoying there isnt what i would call a system api? - or am i being all microsofty?! :D
other things - like ip addresses etc....
Can find bits and bobs like this : QNetworkInterface::IsUp
But without examples that pretty much means nothing to me :(
fatalsaint
2010-02-08, 22:16
Eric4 should auto-indent for you.. and have syntax highlighting and I (think) auto-completion too?
heya... probably a stupid question....
But i understand the QT creator part (Just about) and can create a form/window screen bit.....
Is there any good tools for editing the python file? (Still struggling with the indents etc...)
Getting very confused searching for pyqt and tools....... i'm getting lost in the world of other languages/tools/code examples..... :| :( :( :|
eric4 includes a python editor and full integration with qt designer. As a noob myself I found it quite easy to get to grips with and it does a lot of the grunt work for you. In particular it generates the stub files from your ui so you can start banging code in.
See the OP for how to get started with it.
Mike C
noobmonkey
2010-02-08, 22:23
eric4 includes a python editor and full integration with qt designer. As a noob myself I found it quite easy to get to grips with and it does a lot of the grunt work for you. In particular it generates the stub files from your ui so you can start banging code in.
See the OP for how to get started with it.
Mike C
and being typical, there is no easy way to install on windows... lol.. why can't people just make things easier :( - it's like burning through a ring of fire just to see another 500 rings of fire.......
meh...... Grumpy...... just wish common sense and simplicity was used.... (Yes being all microsofty again.....) :(
fatalsaint
2010-02-08, 22:29
and being typical, there is no easy way to install on windows... lol.. why can't people just make things easier :( - it's like burning through a ring of fire just to see another 500 rings of fire.......
meh...... Grumpy...... just wish common sense and simplicity was used.... (Yes being all microsofty again.....) :(
Try getting the iPhone SDK on your Windows.. or Linux computer :D.
I agree though.. something cross-platform should be easy.
There has to be good IDE's for windows for python.
I've heard good things about netbeans ('http://netbeans.org/')..
PyDev ('http://pydev.org/download.html') looks decent.
They don't offer the integration with QT Designer though..
For Eric there is a .zip file here:
http://sourceforge.net/projects/eric-ide/files/eric4/stable
Find the one ending in ".zip" and has a picture of windows next to it.
Extract that somewhere and using python run the "install.py" file.
noobmonkey
2010-02-08, 22:30
wohoooooo , ok only took 5 minutes, after trying python install.py in dos and failing, i ran the python shell, and installed from there!
A hairy troll is now on my desktop! :)
noobmonkey
2010-02-08, 22:33
Try getting the iPhone SDK on your Windows.. or Linux computer :D.
I agree though.. something cross-platform should be easy.
There has to be good IDE's for windows for python.
I've heard good things about netbeans ('http://netbeans.org/')..
PyDev ('http://pydev.org/download.html') looks decent.
They don't offer the integration with QT Designer though..
For Eric there is a .zip file here:
http://sourceforge.net/projects/eric-ide/files/eric4/stable
Find the one ending in ".zip" and has a picture of windows next to it.
Extract that somewhere and using python run the "install.py" file.
Hehe, thanks for being patient with me :D - i suppose i'm soo new to it, that i'm not going to understand it at all, and i really have to go bit by bit, but i just don't like things being made difficult for the sole reason of, well, just to be difficult :) (Just because lots of people are experts, not all of us are!) :D :D
working my way through the funky troll setup now :)
Qt Designer/Python for Windows XP in 30 Mins
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
The link in this part is invalid! Could someone update the op and fix it please?
kthxbai ;)
fatalsaint
2010-02-09, 19:15
The link in this part is invalid! Could someone update the op and fix it please?
kthxbai ;)
Working link here ('http://talk.maemo.org/showthread.php?p=515218#post515218') :D.
I can't update the OP.
Working link here ('http://talk.maemo.org/showthread.php?p=515218#post515218') :D.
I can't update the OP.
You the man! ;)
noobmonkey
2010-02-09, 19:17
ok, took me a while to realise. but python isnt far from ada! and i remember that!! just struggling to figure out any apis or system calls...
this is great! Thanks for this tutorial. Very usefull for people (noob) like me :-)
noobmonkey
2010-02-09, 21:39
sure this has probably been mentioned before - but definitely enjoying this read :) - Python for newbies (http://www.themaemo.com/python-for-newbies/#What%20is%20Python)(Maemo twist)
attila77
2010-02-09, 22:08
Good news, everyone ! As of tonight, PyQt is available to the general public as a simple Extras install (look for python2.5-qt4-doc) from the Application Manager !
PS. Future versions will have a more intuitive package name but I did not want to break the quarantine waiting period :)
noobmonkey
2010-02-11, 15:16
Anyone know which python module will help me determine what repo an app is from? (Jaffa? :D - as you have experience in this field!)
p.s. seen your post in another thread pointing to the python modules - tried hunting through them all, but it's hard work :D - would be useful to have a simplified english description next to each :D
attila77
2010-02-11, 15:31
That's not as easy to find out as it seems... There is python-apt, but that is not ported to Maemo as of yet. The nasty part is that you have no info which repo has an app been actually installed from, only which repos contain it NOW, which is not necessarily what you want. Plus, just to add a spin to it, there is good chance repositories will start to get cleaned up, so you might have an app installed whose (installed) version is currently not present in any of the repositories.
noobmonkey
2010-02-11, 15:54
Woah...........
But i suppose i am still interested in finding out which currently installed applications are currently in a certain repo - so it's a start!
noobmonkey
2010-02-11, 22:41
There is python-apt, but that is not ported to Maemo as of yet.
Hmmm just re-read that bit... how about just getting a list of installed apps then :D ? - any specific module?
attila77
2010-02-12, 09:36
might be easier just to parse the output of `dpkg -l`
noobmonkey
2010-02-12, 09:47
ahaaaaa getting somewhere :) - Will go google dpkg :D (Sorry, new to linux, but actually understanding python!) - so getting somewhere.
Actually got a listwidget thingy being filled by a loop, and its working fine, so this is my next step :D (Slow and steady tis the way to go!)
Thank you very much Attila
Good news, everyone ! As of tonight, PyQt is available to the general public as a simple Extras install (look for python2.5-qt4-doc) from the Application Manager !
PS. Future versions will have a more intuitive package name but I did not want to break the quarantine waiting period :)
I do see python2.5-qt4-doc in the Application Manager.
Unfortunately I get an error of message stating missing packages
python2.5-qt4-core (=4.7 maemo2).
Anyone getting similar results?
PS : Found this thread,
http://talk.maemo.org/showthread.php?t=43953&highlight=python2.5-qt4-cor
looks like the solution is not ready yet.
fatalsaint
2010-02-12, 22:41
I do see python2.5-qt4-doc in the Application Manager.
Unfortunately I get an error of message stating missing packages
python2.5-qt4-core (=4.7 maemo2).
Anyone getting similar results?
PS : Found this thread,
http://talk.maemo.org/showthread.php?t=43953&highlight=python2.5-qt4-cor
looks like the solution is not ready yet.
http://talk.maemo.org/showthread.php?p=522667#post522667
toucan murphy
2010-02-13, 08:49
cheers for an excellent intro to python. I was put off at first after past nokia experience of the complexity of installing the symbian setup but this was a breeze in comparison and i wrote my first app yesterday! (creates an m3u playlist of all songs once provided with a starting folder)
Nice one guys!
Hey fatalsaint,
This VMWare Development Environment can be downloaded?
Ok, here's a quick tutorial on creating your first app and connecting some signals. The OP shows you how to set everything up so this is going to assume you already have Qt Designer and pyuic4 setup correctly. Screenshots are from the Ubuntu Virtual Machine with the SDK.. but same logic would apply to windows or anything.
So here we go, open up QT designer and create a Main Window:
http://packages.linuxniche.net/pyimg/qt-designer-open.png
http://packages.linuxniche.net/pyimg/create-main-window.png
Lets set the Main Window size to 800x400:
http://packages.linuxniche.net/pyimg/set_size.png
Now we want to create a "Quit" menu item just to show how they work later on in python code.
http://packages.linuxniche.net/pyimg/quit_menu.png
Now, using the widget selector screen
http://packages.linuxniche.net/pyimg/designer_buttons.png
We click and drag 2 ListWidgets, on either side of the Main Window, and then 5 pushbuttons and a LineEdit in between them. I named the two listWidgets "listRight", and "listLeft" as so:
http://packages.linuxniche.net/pyimg/name_right.pnghttp://packages.linuxniche.net/pyimg/name_left.png
Using the same screens, I named the buttons:
"btnAdd", "btnAllAdd", "btnRemove", "btnAllRemove", "btnAddNew" and the LineEdit to "lineNew".
Because I like to make things expandable to fit the screen (in case it needs to be resized or is run on something other than a static 800x400 window), we are going to do some grouping too (this is all just for show case). So we add a vertical spacer widget select all the buttons in the middle with the Line Edit and do a Layout Vertically, as so:
http://packages.linuxniche.net/pyimg/layout.png
Then add two Vertical Spacer widgets to the top and bottom, select them all, and do a layout vertically again.
http://packages.linuxniche.net/pyimg/layout_middle.png
Now add the Horizontal Spacer widgets shown above to either side, right click on the background Main Window page, and do a "Layout in a Grid". What we end up with is:
http://packages.linuxniche.net/pyimg/list_example_finished.png
Now we're done with QT Designer! So we want to save, and I called it "list_example.ui":
http://packages.linuxniche.net/pyimg/list_example.png
This gives us a standard QT .ui file which would normally be used by a C++ app. But we want python code, so, doing what the OP and every other tutorial tells us to we use pyuic4:
http://packages.linuxniche.net/pyimg/pyuic4.png
pyuic4 -o list_example_ui.py list_example.ui
That gives us new python file. Unfortunately, we can't run that file directly as all it is is the GUI - we need to launch it somehow, so we create the main python app and I called it "list_example.py" with the following code:
#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from list_example_ui import *
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
#This function means this was run directly, not called from another python file.
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
http://packages.linuxniche.net/pyimg/list_example_ui_basic.png
Now we can run list_example.py directly. If it's on the N900, use "python list_example.py", if you're in the SDK/Scratchbox and want to see it show up properly in Xephyr you use "run-standalone.sh python list_example.py" and voila! We get:
http://packages.linuxniche.net/pyimg/list_example_ui_basic_run.png
But, of course, nothing works! So we close out and decide we want those buttons to actually do something. We know we have 5 buttons, and 1 menu item, so we know we are going to need 6 connects. So lets try some:
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#connect buttons
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
QtCore.QObject.connect(self.ui.btnAllAdd, QtCore.SIGNAL('clicked()'), self.doAllAdd)
QtCore.QObject.connect(self.ui.btnRemove, QtCore.SIGNAL('clicked()'), self.doRemove)
QtCore.QObject.connect(self.ui.btnAllRemove, QtCore.SIGNAL('clicked()'), self.doAllRemove)
QtCore.QObject.connect(self.ui.btnAddNew, QtCore.SIGNAL('clicked()'), self.doAddNew)
QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))
Now, we've connected all 6 items to something. But python has no idea what the things like "self.doAdd" and "self.doAllAdd" are. The only one of those connects that will work is the last one for the "Quit" menu item because we connected it to a built-in qt "quit" slot.
So, now we create various functions (also called methods) that correspond to the names we connected the buttons to:
#Create Sub's
def doAdd(self):
add = 1
for i in range(self.ui.listRight.count()): #let's not create duplicates, so lets do a search.
if self.ui.listRight.item(i).text() == self.ui.listLeft.currentItem().text():
add = 0
if add: #Okay, it wasn't found. Let's add it.
self.ui.listRight.addItem(self.ui.listLeft.current Item().text())
def doAllAdd(self): #This ones easy, just clear the right one, go through all the left items and add them.
self.ui.listRight.clear()
for i in range(self.ui.listLeft.count()):
self.ui.listRight.addItem(self.ui.listLeft.item(i) .text())
def doRemove(self): #Easy again, just remove the selected item.
self.ui.listRight.takeItem(self.ui.listRight.curre ntRow())
def doAllRemove(self): #Super Easy.
self.ui.listRight.clear()
def doAddNew(self): #Pretty easy, just add to the left what is in the text box, then clear it out.
self.ui.listLeft.addItem(self.ui.lineNew.text())
self.ui.lineNew.clear()
So, we put it all together and we have (without the above comments):
#!/usr/bin/python2.5
import sys
from PyQt4 import QtGui,QtCore
from list_example_ui import *
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
#build parent user interface
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#connect buttons
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
QtCore.QObject.connect(self.ui.btnAllAdd, QtCore.SIGNAL('clicked()'), self.doAllAdd)
QtCore.QObject.connect(self.ui.btnRemove, QtCore.SIGNAL('clicked()'), self.doRemove)
QtCore.QObject.connect(self.ui.btnAllRemove, QtCore.SIGNAL('clicked()'), self.doAllRemove)
QtCore.QObject.connect(self.ui.btnAddNew, QtCore.SIGNAL('clicked()'), self.doAddNew)
QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))
#Create Sub's
def doAdd(self):
add = 1
for i in range(self.ui.listRight.count()):
if self.ui.listRight.item(i).text() == self.ui.listLeft.currentItem().text():
add = 0
if add:
self.ui.listRight.addItem(self.ui.listLeft.current Item().text())
def doAllAdd(self):
self.ui.listRight.clear()
for i in range(self.ui.listLeft.count()):
self.ui.listRight.addItem(self.ui.listLeft.item(i) .text())
def doRemove(self):
self.ui.listRight.takeItem(self.ui.listRight.curre ntRow())
def doAllRemove(self):
self.ui.listRight.clear()
def doAddNew(self):
self.ui.listLeft.addItem(self.ui.lineNew.text())
self.ui.lineNew.clear()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
And our final application:
http://packages.linuxniche.net/pyimg/finished.png
Yay, not the most useful app.. this is entirely just a "look, it works".. leave it up to you guys to make something useful. ;)
I don't know if anyone will actually *find* any of this any more/less useful than other tutorials.. but maybe some of the images can be used for whoever does the wiki article.
fatalsaint
2010-02-17, 17:53
Hey fatalsaint,
This VMWare Development Environment can be downloaded?
Yes ('http://tablets-dev.nokia.com/maemo-dev-env-downloads.php')
(Don't need to copy my entire tutorial.. it's quite big to be constantly repeated.)
1st, thx for the tutorials, they are great, I think. Why? >>> Read on.
Sigh, This is what I get for going 64 bit?
C:\Widget>pyuic4 -x untitled.ui -o untitled.py
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\PyQt4\uic\pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
C:\Widget>
I have python 2.6 installed like adviced in the tutorial on page 1,
and the PyQt for python 2.6, but no go.
I am frustrated!
1st, thx for the tutorials, they are great, I think. Why? >>> Read on.
Sigh, This is what I get for going 64 bit?
C:\Widget>pyuic4 -x untitled.ui -o untitled.py
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\PyQt4\uic\pyuic.py", line 4, in <module>
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
C:\Widget>
I have python 2.6 installed like adviced in the tutorial on page 1,
and the PyQt for python 2.6, but no go.
I am frustrated!
Have a look at this post
http://talk.maemo.org/showpost.php?p=515191&postcount=58
Might help
Have a look at this post
http://talk.maemo.org/showpost.php?p=515191&postcount=58
Might help
I don't think so, he is talking about stuff not working on his n900,
I am having problems converting the UI file to PY file on my windows 7 machine... way before putting anything on my n900.
I know I can install windows xp vm / ubuntu / but for the 1st time since years, I actually have an OS on my PC (windows 7) that I really like, and really enjoy working on. (Iv'e tried ubutnu several times...).
Eddie1802
2010-02-20, 21:57
Sigh, This is what I get for going 64 bit?
Did you find a solution? I have the same problem on my 64 bits windows7 machine... :confused:
EDIT:
I found the solution!
It's quite simple... We got an error because we installed the 64 bits version of python 2.6. I removed the 64 bits version and installed the 32 bits one and Presto! It works fine... :cool:
Did you find a solution? I have the same problem on my 64 bits windows7 machine... :confused:
EDIT:
I found the solution!
It's quite simple... We got an error because we installed the 64 bits version of python 2.6. I removed the 64 bits version and installed the 32 bits one and Presto! It works fine... :cool:
O'G - it works!!! you are my hero
Dexter1759
2010-02-25, 12:12
Hi All,
Thanks for the examples and tutorials, done the Hello world and list examples and started on eric4 now.
That was a wierd install, just running install.py to install eric4, then I have to run eric4.bet to start the program! Is that normal?
Also, when I've put the mini browser example on my N900 (that works on my PC) i get an error "cannot import name QtWebKit" even though I installed PyQt Full Install (that said in the details it had QtWebKit!) from devel using app manager, it is still coming up with this error!
Any help would be much appreciated!
[Edit] In addition, I initially installed PyQt through XTerm, using the apt get method towards the start of this thread. Then did the install from devel after getting the error message the first time. Now the PyQt Full Install isn't listed in app manager, under Uninstall (which apps normally do don't they?)!
Thanks.
attila77
2010-02-25, 14:24
[Edit] In addition, I initially installed PyQt through XTerm, using the apt get method towards the start of this thread. Then did the install from devel after getting the error message the first time. Now the PyQt Full Install isn't listed in app manager, under Uninstall (which apps normally do don't they?)!
A bit confusing what's going on. The 'full install' does depend on webkit, so it should not be missing. Can you post the output of 'dpkg -l |grep qt4' and 'apt-cache policy python2.5-qt4-webkit' so we would know what's the existing state of packages over there ?
Dexter1759
2010-02-25, 14:40
OK, typing "dpkg -l |grep qt4" gives me this...
/home/user # dpkg -l |grep qt4
ii libqt4-core 4.5.3~git20090723-0maemo6+0m5 Qt 4 core module
ii libqt4-dbus 4.5.3~git20090723-0maemo6+0m5 Qt 4 D-Bus module
ii libqt4-gui 4.5.3~git20090723-0maemo6+0m5 Qt 4 GUI module
ii libqt4-network 4.5.3~git20090723-0maemo6+0m5 Qt 4 network module
ii libqt4-opengl 4.5.3~git20090723-0maemo6+0m5 Qt 4 OpenGL module
ii libqt4-phonon 4.5.3~git20090723-0maemo6+0m5 Qt 4 Phonon Libraries
ii libqt4-sql 4.5.3~git20090723-0maemo6+0m5 Qt 4 SQL module
ii libqt4-sql-sqlite 4.5.3~git20090723-0maemo6+0m5 Qt 4 SQLite plugin
ii libqt4-svg 4.5.3~git20090723-0maemo6+0m5 Qt 4 SVG module
ii libqt4-xml 4.5.3~git20090723-0maemo6+0m5 Qt 4 XML module
ii python2.5-qt4-common 4.7-maemo7 Shared files for PyQt4
ii python2.5-qt4-core 4.7-maemo7 Python bindings for Qt4 Core components.
ii python2.5-qt4-gui 4.7-maemo7 Python bindings for Qt4 Core
components.
And "apt-cache policy python2.5-qt4-webkit" gives me this:
/home/user # apt-cache policy python2.5-qt4-webkit
python2.5-qt4-webkit:
Installed: (none)
Candidate: 4.7-maemo7
Version table:
4.7-maemo7 0
500 http://repository.maemo.org fremantle/free Packages
500 http://repository.maemo.org fremantle/free Packages
4.7-maemo6 0
500 http://repository.maemo.org fremantle/free Packages
500 http://repository.maemo.org fremantle/free Packages
4.7-maemo5 0
500 http://repository.maemo.org fremantle/free Packages
500 http://repository.maemo.org fremantle/free Packages
4.7-maemo3 0
500 http://repository.maemo.org fremantle/free Packages
4.7-maemo2 0
500 http://repository.maemo.org fremantle/free Packages
4.7 0
500 http://repository.maemo.org fremantle/free Packages
None of which makes much sense to me (well I kinda see what "apt-cache policy python2.5-qt4-webkit" is returning) except that it confirms webkit isn't installed (i think!)
Dexter1759
2010-02-25, 14:48
Aha, I just thought I'd search in App Manager for "webkit" in title and description and it listed "PyQt4 Fulle install" so it must not have installed correctly the first time round! I'm just trying again, I'll pay more attention for error messages this time!
Dexter1759
2010-02-25, 14:55
Yay it worked! Sort of!
Running the actual example using eric4 (rather than the version I created myself following the tutorial!). This is how it looks:
http://i365.photobucket.com/albums/oo93/Dexter1759/Screenshot-20100225-144923.png
Should the buttons and text boxes look like that?
attila77
2010-02-25, 16:05
Qt4.5 has various styling issues, so do not be surprised if things look a bit odd. Qt4.6 (coming with PR1.2) is better in that regard.
matristain
2010-02-25, 16:16
maybe this is quite a big step, but what about creating a widget that turns on / off bluetooth, Is this to much to ask for a tutorial ?
attila77
2010-02-25, 16:28
Yes :) But jokes aside, you really want to wait for Qt4.6 and QtMobility for such things. With the current versions, that tutorial would be more about low level X and DBUS programming than Qt and Python.
Just some added some minor updates to OP, with some additional links.
Dexter1759
2010-03-01, 16:12
Just some added some minor updates to OP, with some additional links.
Thank you once again! Once I have the time I shall continue looking into PyQt development, using eric4, but first need to worry about managing my current workload and moving house.
Your tutorials/guides are exactly the sort of thing I have been looking for!
Just need to think myself up a little "project" to get me started with!
[Edit] Infact, after moving house I shall have a project to work on. I plan on getting a QNAP NAS drive, that I shall be setting up a MySQL db on for logging my hours. Would it be possible to create an app for my N900, that could connect to the MySQL database from any internet connection in the world (3G or wifi), with the ability to append, view & edit data?
Apologies for the specific question, just want to know it's possible, not how it's done.
I got a project for you Dexter. (no killing involved though).
Write a desktop widget that reminds you that you left the camera slide open.
- Check first that the camera or flash has not been used for 2 min.
- Prevents scratches to reckless people like me :)
- Some flashi text on the desktop telling you, camera slider is open you doosh!
Dexter1759
2010-03-01, 16:20
I got a project for you Dexter. (no killing involved though).
Write a desktop widget that reminds you that you left the camera slide open.
- Check first that the camera or flash has not been used for 2 min.
- Prevents scratches to reckless people like me :)
- Some flashi text on the desktop telling you, camera slider is open you doosh!
LOL - just edited my previous post (because I don't like double posting) but that seems like a slightly more reasonable project to work on first!
Though I have NO idea how to create a desktop widget, only just got to grips (very loosely too!) with making a "normal" app!
noobmonkey
2010-03-01, 16:22
Thank you once again! Once I have the time I shall continue looking into PyQt development, using eric4, but first need to worry about managing my current workload and moving house.
Your tutorials/guides are exactly the sort of thing I have been looking for!
Just need to think myself up a little "project" to get me started with!
[Edit] Infact, after moving house I shall have a project to work on. I plan on getting a QNAP NAS drive, that I shall be setting up a MySQL db on for logging my hours. Would it be possible to create an app for my N900, that could connect to the MySQL database from any internet connection in the world (3G or wifi), with the ability to append, view & edit data?
Apologies for the specific question, just want to know it's possible, not how it's done.
Yup you can :D as long as the database is accessible externally - got it working with mine last week - just tested the connection :) (Also tested MSSQL fine)
Dexter1759
2010-03-01, 16:32
Yup you can :D as long as the database is accessible externally - got it working with mine last week - just tested the connection :) (Also tested MSSQL fine)
Cool, thanks. Looking forward to getting my NAS! Long term, I'd like to use MySQL, with a web front, to replace my current Access DB, with logging hours, invoicing, basic accounts, etc. But in the short term, a nice little N900 app that can just input my hours will do nicely. That can easily be imported into my Access DB.
Anyway, that's far enough off-topic, sorry. I'm sure in a month or so I'll have plenty of questions to ask!
attila77
2010-03-01, 17:14
Cool, thanks. Looking forward to getting my NAS! Long term, I'd like to use MySQL, with a web front, to replace my current Access DB, with logging hours, invoicing, basic accounts, etc. But in the short term, a nice little N900 app that can just input my hours will do nicely. That can easily be imported into my Access DB.
Anyway, that's far enough off-topic, sorry. I'm sure in a month or so I'll have plenty of questions to ask!
You can do all sorts of fun stuff. I also have a QNap and regularly use my N900 in combination with it, mostly with some custom scripts for the download station. You also have wizard mounter, which makes NFS shares a breeze. Twonky is not fully cooperating, but I believe that has more to do with my hackery than QNap :)
omeriko9
2010-03-01, 17:16
I don't think so, he is talking about stuff not working on his n900,
I am having problems converting the UI file to PY file on my windows 7 machine... way before putting anything on my n900.
I know I can install windows xp vm / ubuntu / but for the 1st time since years, I actually have an OS on my PC (windows 7) that I really like, and really enjoy working on. (Iv'e tried ubutnu several times...).
Is that Win7 64bit?
I've managed to use pyuic4 with a windows 7 32bit.
Dexter1759
2010-03-01, 19:12
You can do all sorts of fun stuff. I also have a QNap and regularly use my N900 in combination with it, mostly with some custom scripts for the download station. You also have wizard mounter, which makes NFS shares a breeze. Twonky is not fully cooperating, but I believe that has more to do with my hackery than QNap :)
Cool, I hope twonky works properly with my N900, the initial reason for me wanting a QNAP is to store all my Music, Videos & Photos to stream to my PS3 and N900 (I was hoping that using OpenVPN, I'd be able to access the shares & Twonky from anywwhere).
low life
2010-04-09, 09:50
I'm testing my wings on this coding stuff (never done anything apart from some crude command line C++ programs) and with my luck on the <20 lines I wrote I already managed to use syntax that apparently isn't supported in the Python version found on N900.
It's mentioned in the Python documentation that the "with ... as ... :" statement (recommended for reading files) should be available in Python 2.5, but apparently "the with statement is only allowed when the with_statement feature has been enabled.". Can I somehow enable that feature or should I just change it to something else?
attila77
2010-04-09, 11:01
Hm, maybe this can help:
from __future__ import with_statement
low life
2010-04-09, 11:41
That did it, thanks!
I just found these powerpoint slides and thought that link to this probably belongs here:
Andreas Jakl, Qt Symbian Maemo Quickstart:
http://www.slideshare.net/NokiaAppForumAlps/andreas-jakl-qt-symbian-maemo-quickstart
Looks like quite fresh.
4242-564
2010-04-15, 08:37
Just wondering, would meego (if the n900 ever gets it) support python and qt development?
attila77
2010-04-15, 15:17
Certainly. A bit early to say what exact features will (not) be supported, but I'd be surprised if we did not have both PyQt and PySide on MeeGo.
In reply of post #59 (http://talk.maemo.org/showpost.php?p=515218&postcount=59):
Lets set the Main Window size to 800x400:
http://packages.linuxniche.net/pyimg/set_size.png
I'm not sure. Has anybody said this in this Tread before?
I think we can set the Main Window size without any problem to 800x425 pixel and use the space for more useful applications. ;)
Our Screen Resolution is 800x480 pixel. And the Top Menu is 55 pixel height.
fatalsaint
2010-04-22, 20:09
I'm not sure. Has anybody said this in this Tread before?
I think we can set the Main Window size without any problem to 800x425 pixel and use the space for more useful applications. ;)
Our Screen Resolution is 800x480 pixel. And the Top Menu is 55 pixel height.
The way I designed the interface in the tutorial it was ultimately irrelevant. With the use of the spacers and the dynamic layouts it will expand and shrink as needed to fit whatever size you are launching it.
So on a Desktop it'll default to the 800x400 but on the N900 it'll simply be those 25 pixels taller but all of the buttons and stuff with adjust making it look identical.
You can of course set whatever settings you want in there; design your interface; then launch it on an N900 and see how it looks.
Ah, okay. Thanks a lot fatalsaint. :)
What about PyQt and Screen Rotation?
Listening to DBus is not so hard. It works just fine. But I get a "Segmentation fault" with only this code added:
import hildon
So I can't request the portrait Mode for the UI:
hildon.hildon_gtk_window_set_portrait_flags(self._ get_main_window(), hildon.PORTRAIT_MODE_REQUEST)
Okay. We have here a Qt application and the code example is GTK. But my question is, how works this in Qt? :)
attila77
2010-04-25, 21:29
rootwidget.setAttribute(Qt.WA_Maemo5PortraitOrient ation, True)
Sorry, I don't want to create a extra Thread:
Could someone post me a hint how to show up a yellow note on the screen?
I wan't a small popup notifiaction that my program is at the moment storing some data. But I don't know how to get it.
Also I want to hide a verticalSlider at the ui in some moments.
I'm a Python and Qt beginner. From other Languages I worked with before the elements of the graphical UI has all a "visible" property (True and False). - Exists a similar mechanism at PyQt?
attila77
2010-05-21, 08:47
Yellow note:
import sys
from PyQt4.QtMaemo5 import QMaemo5InformationBox
from PyQt4.QtGui import QApplication
app = QApplication(sys.argv)
QMaemo5InformationBox.information(None, "Boxy !")
sys.exit(app.exec_())
As for the scrollbar, sure, you can call for example myscrollarea.verticalScrollBar().setVisible(False) on it and off you go ! Note that Qt4.6 mostly does this automatically.
witchole
2010-05-23, 20:34
Get Python 2.6 from Python.org Here (http://python.org/download/releases/2.6.4/).
Quick question: does it have to be version 2.6?
I see there is a 2.7 beta 2 available on python.org.
The version on my N900 is 2.5.4
Livinmalife
2010-05-30, 17:14
This thread is top!!!
Thanks for everyones input... I'm not a coder and can only do VBA so this is a BIG step up!
When I enter "python helloworld.py" it shows the app but very basic, with a plain background and terminal displays the message:
"Maemo applications must be run with the run-standalone.sh script!"
"QGtkstyle was unable to detect the current GTK+ theme."
Any ideas?
attila77
2010-05-30, 18:00
These are not really errors. The first line just says that in order to be able to correctly cooperate with some system services you should be starting the app with 'run-standalone.sh python helloworld.py'. As for the non-maemo styled background - I had that issue when starting apps as root, always start them as 'user' to avoid rights/paths issues that can result in all sorts of funkiness.
Livinmalife
2010-05-30, 18:07
Thanks attila77.
gabby131
2010-05-30, 18:22
Yes!!!!!! what a user friendly tutorial!!! i will try this! and ready to re-flash my n900 a hundred times!!! :D
Livinmalife
2010-05-30, 20:14
sure this has probably been mentioned before - but definitely enjoying this read :) - Python for newbies (http://www.themaemo.com/python-for-newbies/#What%20is%20Python)(Maemo twist)
Cheers for that link noobmonkey. I need to learn Python language from scratch so gonna do plenty of reading...
Will be back in a few days when im stuck!! :D
can somebody help me. ive followed the guide to connect by SSH but i cannot get a connection. ive followed the guide, is there anything i should keep in mind when doin this?
can somebody help me. ive followed the guide to connect by SSH but i cannot get a connection. ive followed the guide, is there anything i should keep in mind when doin this?
Could you please describe in detail what do you exactly mean by "cannot get connection" also preconditions would be appreciated (in same lan,firewall etc.)
Network error: Connection refused.
this is the error message i am getting
fatalsaint
2010-06-08, 21:55
Network error: Connection refused.
this is the error message i am getting
Did you install the openssh-server on the N900?
Also.. more details. Just "SSH fails, network error" doesn't tell us much. Are you trying to copy a QT4 app you wrote from your computer to the N900? From the N900 to the Computer? Are both on the same network? Is your N900 on the 3G/Data network?
... details.
i only get that error message. well i wanted to transfer an app from my computer. ive folllowed the instruactions so yes i installed the open ssh server and i put in my password. ive downloaded winscp and i entered the details. i then press login and i get that error message. Both my computer and n900 are connected to my home wifi
Are the N900 and the computer from you are trying to make connection behind same LAN (don't know correct term but i have wifi/network switch in home where my computers are connected and they can communicate with each other, inbound connections from outside networks are blocked by service provider, some switch/adsl modems block connection between wifi and ethernet)
You have installed openssh server from repositories and gave it password in install and youa re sure that password is correctly entered to winscp(or whatever you are using to connect n900) username is root. Try to reboot n900.
fatalsaint
2010-06-08, 22:00
i only get that error message. well i wanted to transfer an app from my computer. ive folllowed the instruactions so yes i installed the open ssh server and i put in my password. ive downloaded winscp and i entered the details. i then press login and i get that error message. Both my computer and n900 are connected to my home wifi
Try pinging the N900 from your computer. Also ping your computer from the N900.
Double check IP addresses.
ive tried restarting the same thing happens.
how to a 'ping'?
winkey+r
cmd
ping n900ipaddress
should give you results if not then something is wrong.
winkey+r
cmd
ping n900ipaddress
should give you results if not then something is wrong.
tried this. it works but the application still doesnt work
Try to also ping your computer from n900 x-terminal. (don remember if ping works only for root)
Some things to check
http://winscp.net/eng/docs/message_connection_refused
Double check firewall from your pc (3rd party, av-software might have it integrated and windows own)
i have tried disabling the firewall and letting the program through but it still doesnt work. is there any other way i can transfer the file to my device?
You can always connect it with usb cable and copy stuff from desktop to /Mydocs and then move it on device to /home/opt dir.
Still itīs weird that you canīt connect with winscp. Could it be that your home wifi block connections on some ports. ssh uses 22.
no idea.... you no how computers are sometimes!!!!! il try sending it over that wayyyyyy.i really wana start developing apps for my n900.....any tips????
any tips? Read first post :| and read click links and give yourself lots of time to read and read and read and then try coding with some little app. There is probably other how to start developing threads here just use power search for talk and wiki area.
Something went wrong with my installation. When I try to run pyuic4, it gives me an error message that qtcore4.dll can't be found. When I check pyqtconfig.py under PyQt4 installation dir it seems to have configs like 'qt_dir': 'C:\\Qt\\4.6.2'.. I have this dir, but it seems to contain only python and ruby related .api files (maybe related to Eric).
Should the PyQt use Qt provided by Nokia SDK or Qt libs installed with PyQt?
you should only need to install the pyqt from riverbank computing
you should only need to install the pyqt from riverbank computing
Actually managed to get it working, but pyuic4 succeeds only when run from the dir where it's located.
Thanks much to the OP 'MikeC' ? for this great guide.
Im currently trying to get to grips with all sorts of tech. stuf [not tech. fluent] so SDK and XML is all new to me. Yes, this is a big challenge.
Thanks to resources like this and the community as a whole people like me can learn and implement thier creative ideas into the world.
I hope this is a feature of the MeeGo community when it arrives, maemo.org is a good place to be.
Spotfist
2010-09-14, 14:34
Sorry for the dumb question but why can't I view the code of a form in designer, it says there is an error with uic?
I assume as shown in the demo we use pyuic to translate this into python and then alter the code in notepad ore something? How can I then run the code on my windows machine do I have to install scratchbox or sdk? it's huge?!?! is there no ways to run in the designer?
fatalsaint
2010-09-14, 15:27
Sorry for the dumb question but why can't I view the code of a form in designer, it says there is an error with uic?
I assume as shown in the demo we use pyuic to translate this into python and then alter the code in notepad ore something? How can I then run the code on my windows machine do I have to install scratchbox or sdk? it's huge?!?! is there no ways to run in the designer?
You're missing something... you'll do all your layout (and possibly signal connection if you want) in the QT Designer which will make the .ui file. You'll use pyuic4 to translate the .ui file to a .py file.
Now you need a seperate (main) .py file that will import in your UI and display it to the screen. To run it on Windows, Linux, Mac, whatever you can just run it through python:
python mainprog.py
Which will display your UI.
Or, if you use the -x switch (like in the OP tutorial), there is no need for the second .py file as pyuic4 will generate a py that calls your UI for you. You just need to run your .py file from there.
QT Designer is built to work with C++, not python. There is no way (that I'm aware) to run or load the .py files back into QT Designer, only the .UI files. That is why I recommend the first way above, keep your UI .py file separate from your main program and never edit it directly. That way you make changes to your UI in Designer, save it, and convert it using pyuic4 overwriting your old ui.py file whenever you want to change it and not worry about losing all your code inside the main program.
As an example you would have
my_fancy_program_ui.py #generated from my_fancy_program.ui with pyuic4
my_fancy_program.py #contains code to load my_fancy_program_ui.py
Spotfist
2010-09-14, 15:32
Sweet! Thanks, that answers my questions I was a bit confused about the "unable to compile" error but now I know it's for C++ I can see why.
One last question, is scratchbox/SDK then just for graphical purposes? I want to write a game or ap that requires a ui so I assume that if I run it in python it will look similar to what is show in QT designer and the sdk is to view it as it would be on the n900?
attila77
2010-09-14, 15:36
Correct, the only reason for using scratchbox in case of a PyQt/PySide app is to see how the app actually looks. Though at that point it's probably less fuss to run what you want to see on the device itself and not bother with scratchbox :)
fatalsaint
2010-09-14, 16:56
Agree with attila77. Scratchbox is really quite useless when developing in PyQt/PySide.
You can run the app directly on your Windows or Linux system just to make sure it works (no segfaults, syntax errors, etc). It won't look exactly like on Maemo but it'll be close.
Once you have it running properly you just copy your .py files over the N900 (either via SCP or Mass Storage Mode, whatever.) and then run your program right on the N900.
That is actually easier than dealing with Scratchbox.
Spotfist
2010-09-14, 21:23
Well I know what Im doing at work tomorrow! ;) thanks guys. Im sure I'll be asking more questions tomorrow though lol!
Hi,
has anyone understood what is the correct/optimal size for a main window?
I use 800x450 which doesn't look that bad. Still though it doesn't look correct on the bottom and I have some space on the sides.
I've tried several but haven't figured if an aspect ratio is needed to be kept etc.
Thanks.
Edit: forgot to mention that with the above setting I have to keep some space free/unused at the bottom otherwise those elements are cut. That makes it quite non-intuitive and more trial and error than it needs.
Spotfist
2010-09-15, 07:35
It's in the first post of this thread, "800x400"
yamakasi
2010-09-16, 03:05
i am getting this error while converting the ui file to py
an unexpected error occurred.
check that you are using the latest version of PyQt and send .. ."alot of text":
*your version of PyQt (4.7.6)
*the UI file that caused this error
*the debug output of pyuci4 (use the -d flag when calling pyuic4
EDIT : did i download the wrong packages :confused:?
Spotfist
2010-09-16, 10:20
I get the same error, I wondered if I had downloaded the wrong packages too but I downloaded python 2.6 as suggested and then the latest version of qt designer, when I tried to install QT designer it said it detected an older version of python so I downloaded the 2.6 matching version of qt designer and that work without an error message. I assumed then that the version were correct...
I added a few images into the resource I created, could this casue the error?
fatalsaint
2010-09-16, 13:17
Did either of you try the -d flag like it suggests to get the debug output?
It might give us more info. For reference I use 4.6.2 QT and QT Designer on my desktop (Linux). But my python-qt4 packages are 4.7.2. They seem to work ok.
It's in the first post of this thread, "800x400"
Thanks, I definitely read the first post. On later posts other people have been wondering too but there wasn't any conclusion.
In any case, the optimal with the maximum screen estate (an not cut anything) was to set it at 800x410 and the tab widget to have the geometry [(5,2), 791 x 386]
Hope it is useful.
fatalsaint
2010-09-16, 21:07
Thanks, I definitely read the first post. On later posts other people have been wondering too but there wasn't any conclusion.
In any case, the optimal with the maximum screen estate (an not cut anything) was to set it at 800x410 and the tab widget to have the geometry [(5,2), 791 x 386]
Hope it is useful.
If you design your UI properly and align all the widgets to the background and proper use of spacers (and min/max sizes of widgets).. it should auto-resize to most screens without making it look funny.
yamakasi
2010-09-17, 01:32
Did either of you try the -d flag like it suggests to get the debug output?
It might give us more info. For reference I use 4.6.2 QT and QT Designer on my desktop (Linux). But my python-qt4 packages are 4.7.2. They seem to work ok.
here is the output:
trackback (most recent call last):
file"C:\program files\python26\lib\site-packages\PyQt4\uic\port_v2\invoke.py", line 12 in invoke
exit_status = driver.invoke()
file"C:\program files\python26\lib\site-packages\PyQt4\uic\port_v2\driver,py", line 7 in invoke
self.generate()
file"C:\program files\python26\lib\site-packages\PyQt4\uic\port_v2\driver,py", line 60 in _generate
pyfile = open(self.opt.output, "wt", encoding="utf8")
typeError: "encoding" is an invalid keyword argument for this function
IceJunior
2010-09-18, 11:49
i am getting this error while converting the ui file to py
EDIT : did i download the wrong packages :confused:?
got the same error...
attila77
2010-09-18, 16:38
Can you attach the .ui file ?
erniadeldesktop
2010-09-18, 16:49
I know that i'm offtopic, but any news on pyqt destop widget? can someone point me to some example?
yamakasi
2010-09-19, 08:25
Can you attach the .ui file ?
i didn't write the file manually i used Qt designer to generate the file,
i am using these packages:
python 2.6
PyQt GPL v4.7.6 for Python v2.6
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>220</x>
<y>110</y>
<width>261</width>
<height>111</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>24</pointsize>
</font>
</property>
<property name="text">
<string>Hello World!</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>18</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
louispires
2010-09-19, 20:43
Well i didn't get far, after step 3 i get an unknown error
13847
I followed step by step!
Please help
13848Just remove .txt
yamakasi
2010-09-20, 04:09
*sigh* i am really disappointed i have been waiting for 4 days now and no tried to help us :(
fatalsaint
2010-09-20, 04:16
*sigh* i am really disappointed i have been waiting for 4 days now and no tried to help us :(
Sorry, but I can't reproduce the problem. Copy/paste from the code above and:
pyuic4 -o test.py -x test
python test.py
Produces a Hello World screen with no errors. So, something is wrong with your pyuic4, but I don't know how to help.
Same for the hw.ui.txt, gives Hello World with a "Click Me!" button.
yamakasi
2010-09-20, 04:23
can you give us the links for the packages you are using ?
fatalsaint
2010-09-20, 04:43
can you give us the links for the packages you are using ?
I use Ubuntu Linux.
$ pyuic4 --version
Python User Interface Compiler 4.7.2 for Qt version 4.6.2
bentech4u
2010-09-21, 09:21
i am very new to this
i tried the procedures and installed all packages
PyQt GPL v4.7.6 for Python v3.1 and python 3.1.0
when i tried to compile the ui, i got an error like
D:\python>pyuic4 -x benvin.ui -o benvin.py
Traceback (most recent call last):
File "C:\Python31\Lib\site-packages\PyQt4\uic\pyuic.py", line 4,
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
my os is windows 7 64 bit
please help me :(
noobmonkey
2010-09-21, 14:45
i am very new to this
i tried the procedures and installed all packages
PyQt GPL v4.7.6 for Python v3.1 and python 3.1.0
when i tried to compile the ui, i got an error like
D:\python>pyuic4 -x benvin.ui -o benvin.py
Traceback (most recent call last):
File "C:\Python31\Lib\site-packages\PyQt4\uic\pyuic.py", line 4,
from PyQt4 import QtCore
ImportError: DLL load failed: %1 is not a valid Win32 application.
my os is windows 7 64 bit
please help me :(
I haven't used pyuic for a while, but from what was posted above
pyuic4 -o test.py -x test
Compared to yours, there is a difference
pyuic4 -x benvin.ui -o benvin.py
To me it looks like you are trying to run pyuic from with a python console? i thought it needs to be run from within the dos prompt - also, the example has the .py first, and you put the.ui first....
a few bits, not got time to test and show at the moment though.
fatalsaint
2010-09-21, 23:22
The reversal of the ui and the .py should not matter (as long as the .py follows the -o). That DLL import error and the "not valid win32 app" looks like PyQt itself is not installed properly.
My first guess would be that you are on 64-bit and the PyQt may be requiring 32. This ('http://code.google.com/p/pyqt4-win64-binaries/issues/detail?id=2#c1') came up with a quick google and it appears you aren't the only one with that problem.
There is a possible workaround in the second comment.. but as I don't have windows I have no idea if there's an easier way or that problems actually supposed to have been resolved by now (last post in Feb).
Spotfist
2010-09-22, 08:41
I am running 32 bit and get the error I will uninstall python and try a newer version if I can find one... As I said in my earlier post though, I installed pythong 2.6 I think and then the latest version of QT designer and an error came up saying the version where different...
Spotfist
2010-09-22, 09:55
Re-installed python, no result. Re-installed QT designer 2.6 v4.7.7.1 from the link in the first post and it now works. No change from the first time but for some odd reason it works... ;)
Biglines
2010-10-16, 21:20
I've got the py file, but after copying to /home/opt/ and going to xterminal, typing
python helloworld.py
it says:
python: can't open file 'helloworld.py': [Errno 2] No such file or directory
where should I put the python files in order to run them?
edit: nevermind, I should navigate to /home/opt/ before running the file
ejasmudar
2010-11-26, 04:18
I wanted to try this, but first, is QT designer portable? Or is a portable version available? I want to carry it on a flash drive so that I can code while travelling. I did find a portable python IDE so I can write console based apps on the go. So is there something similar for GUI designing with QT?
I wanted to try this, but first, is QT designer portable? Or is a portable version available? I want to carry it on a flash drive so that I can code while travelling. I did find a portable python IDE so I can write console based apps on the go. So is there something similar for GUI designing with QT?
Qt Designer is not portable, But, You can use PySide or PyQt
to code GUI and everything for N900 using Python, no just terminal apps.
You can write a full app with Python and it will have everything a C++ app has.
Python you can write anywhere you want :)
You can even write these apps on your n900 :)
When it came to running the command "pyuic4 -x helloworld.ui -o helloworld.py" using windows, I got the following error:
"H:\folder1\Dec 30 Module test\python" is not recognized as an internal or external command, operable program or batch file.
I have seen many articles of people executing this line and having no issues. I do not know what I am doing wrong.
When it came to running the command "pyuic4 -x helloworld.ui -o helloworld.py" using windows, I got the following error:
"H:\folder1\Dec 30 Module test\python" is not recognized as an internal or external command, operable program or batch file.
I have seen many articles of people executing this line and having no issues. I do not know what I am doing wrong.
am sure somebody knows more than me, but pyuic is no longer the command used. Qt has come a long way since this video and uses QML
shawn_garcia
2019-10-28, 05:11
Thanks for sharing your views with us this will surely help me a lot in future!!
vBulletin® v3.8.8, Copyright ©2000-2025, vBulletin Solutions, Inc.