PDA

View Full Version : QPixMap doesn't show one of two images !



ladiesfinger
10th January 2011, 14:58
( Lang : Python 3.1 )
I have implemented two QPixmap widgets and intended to show images via them.
The first one shows the input image the user has chosen & the second one will show the output file of an image processing tool . You will understand easily if u see the code :


#First image - Input selected through a file dialog ( self.input is filename )
self.item1=QtGui.QGraphicsPixmapItem(QtGui.QPixmap (self.input))
self.scene1.addItem(self.item1)
self.view1.show()
#The processing Tool - a commandline utility
subprocess.Popen(self.com,shell=True)
#Second Image- Output After processing ( I get filename-self.output from LineEdit )
self.item2=QtGui.QGraphicsPixmapItem(QtGui.QPixmap (self.output))
self.scene2.addItem(self.item2)
self.view2.show()


Problem:
First Image Shows without any problem .
Output image never shows . But it is generated by the processing tool as usual.

Plz , help me . I can't figure it out

wysota
10th January 2011, 15:04
What happens between lines 6 and 8? Do you allow the external tool to finish its job before trying to show the other pixmap? If not then simply the output pixmap is not there at the time Qt tries to show it.

ladiesfinger
10th January 2011, 15:11
For that case , i tried to use Timer to delay some 30 secs . But i can't . The inserted lines :


t=Timer(30.0)
t.start()

It gives error as :


Traceback (most recent call last):
File "gui.py", line 138, in processimg
t=Timer(30.0)
NameError: global name 'Timer' is not defined


Can you show me the right way to use Timer ? Or any other idea ?

wysota
10th January 2011, 15:13
Use QProcess to govern your subprocess. It has a finished() signal. Connect to that signal and run lines #8-9 of your original snippet after the method is triggered by the signal.

ladiesfinger
10th January 2011, 15:48
I had it running . But through Timer .
All i had to do is "import timeit " and run . ( I encountered some fearful errors in QProcess )
Thank you Wysota....

wysota
10th January 2011, 16:29
What if it takes longer for the subprocess to finish its task?