| 1   2   | Next
maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   pyqt + Opening new windows query (https://talk.maemo.org/showthread.php?t=48178)

noobmonkey 2010-03-24 08:34

pyqt + Opening new windows query
 
Hi everyone, i spent about 5 hours last night trying to open new windows within pyqt.

Managed to get hildon stackables working fine, but my app is qt :D ... so i'm trying to be sensible and not mix and match! :D

I've got to the point where the window loads fine..! Yay! - but on exit of that window, the original' window goes into a loop of hang'y'ness....

So in pseudo my aim is

Load main window
click button
open new window
<allow things to happen>
user clicks exit on that window
close sub window
return to main window...
(Allow user to continue using that window!!!!)


Ok... so in code.....
My button calls this sub
(Note my many attempts to sort out the closing - as the window is full screen at time of pressing exit)
Code:

 
def show_new_window(self):
        appt=QtGui.QApplication(sys.argv)
        win=HelloWindow()
        win.show()
        win.showFullScreen()
        appt.connect(appt, SIGNAL("lastWindowClosed()"),appt, SLOT("quit()"))
        appt.exec_loop()

The class for the new window and exit function are....

Code:

class HelloWindow(QtGui.QMainWindow):

    def __init__(self, *args):
        apply(QtGui.QMainWindow.__init__, (self,) + args)

        self.exitb = QtGui.QPushButton('Exit', self)
        self.exitb.move(10, 210)
        self.connect(self.exitb, QtCore.SIGNAL('clicked()'), self.exitB)

    def exitB(self):
        #win.hide()
        #sys.exit(app.exec_())
        self.showMaximized()
        #MainWindow.show()
        #self.hide()

I'm sure i'm doing this in a non-sensible way and would appreciate someone sorting me out :D

Hope that is enough info :D

attila77 2010-03-24 09:24

Re: pyqt + Opening new windows query
 
... but.... where is this other window you're talking about ? In the code above you just make one. Also, I think what you want to do with the clicked signal is:

self.connect(self.exitb, QtCore.SIGNAL('clicked()'), self.close)

EDIT: So off the top of my head, do you want something like this ?

Code:


class HelloWindow(QtGui.QMainWindow):

    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)

        self.exitb = QtGui.QPushButton('Exit', self)
        self.exitb.move(10, 210)
        self.connect(self.exitb, QtCore.SIGNAL('clicked()'), self.close)

def show_new_window():
        appt=QtGui.QApplication(sys.argv)
        basewin = QtGui.QMainWindow()
        basewin.show()
        win=HelloWindow(basewin)
        win.showFullScreen()
        sys.exit(appt.exec_())

show_new_window()


noobmonkey 2010-03-24 10:16

Re: pyqt + Opening new windows query
 
Quote:

Originally Posted by attila77 (Post 579943)
... but.... where is this other window you're talking about ? In the code above you just make one. Also, I think what you want to do with the clicked signal is:

self.connect(self.exitb, QtCore.SIGNAL('clicked()'), self.close)

EDIT: So off the top of my head, do you want something like this ?

Code:


class HelloWindow(QtGui.QMainWindow):

    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)

        self.exitb = QtGui.QPushButton('Exit', self)
        self.exitb.move(10, 210)
        self.connect(self.exitb, QtCore.SIGNAL('clicked()'), self.close)

def show_new_window():
        appt=QtGui.QApplication(sys.argv)
        basewin = QtGui.QMainWindow()
        basewin.show()
        win=HelloWindow(basewin)
        win.showFullScreen()
        sys.exit(appt.exec_())

show_new_window()


Thankeee very much - getting a segmentation fault with that one at the moment, will take a proper look tonight though :D

Quote:

where is this other window you're talking about ?
I've setup a MainWindow earlier, and was just trying to create this new window from within a function.... probably not the best way :|

mikec 2010-03-24 11:11

Re: pyqt + Opening new windows query
 
@noobmonkey

maybe you are confusing hildon stackable windows with qt windows.

if you parent your second window to your main window then Maemo will convert your second window to a hildon stackable for you, and you dont need to mess with close window events, bringing windows to the top etc. just hit the back button at the top left of second window and it will close and de-stack.

as per my code in this thread

http://talk.maemo.org/showpost.php?p=577316&postcount=9

As there is no hildon specific code I am assuming come PR1.2 this will continue to work.

krk969 2010-03-24 11:48

Re: pyqt + Opening new windows query
 
Quote:

Originally Posted by mikec (Post 580084)
@noobmonkey

...... just hit the back button at the top leftright of second window and it will close and de-stack.

corrected that for you :)...

*EDIT* QT4.6
set the folllowing attribute Qt::WA_Maemo5StackedWindow as well on both windows to see that nice back button else you will see a cross :p

noobmonkey 2010-03-24 23:18

Re: pyqt + Opening new windows query
 
Quote:

Originally Posted by mikec (Post 580084)
@noobmonkey

maybe you are confusing hildon stackable windows with qt windows.

if you parent your second window to your main window then Maemo will convert your second window to a hildon stackable for you, and you dont need to mess with close window events, bringing windows to the top etc. just hit the back button at the top left of second window and it will close and de-stack.

as per my code in this thread

http://talk.maemo.org/showpost.php?p=577316&postcount=9

As there is no hildon specific code I am assuming come PR1.2 this will continue to work.

heya, nope got hildon and gtk working, removed them to use qt :D

As i'm setting it as full screen (to test dead pixels) there is no back button, but i have a normal movable button the screen that i am using to close it... (That also works fine) - but the program hangs once the window closes :(


Tried your code :( - also didn't work :(
was telling me that i was passing an invalid variable (My Main window...... ) :( :(

(Argument 1 has unexpected type)

noobmonkey 2010-03-24 23:19

Re: pyqt + Opening new windows query
 
Quote:

Originally Posted by krk969 (Post 580123)
corrected that for you :)...

*EDIT* QT4.6
set the folllowing attribute Qt::WA_Maemo5StackedWindow as well on both windows to see that nice back button else you will see a cross :p

erm, that looks c code? - tried searching for that in python with no luck :| :|
but still, dont want the back button as i have it full screen :D

noobmonkey 2010-03-24 23:27

Re: pyqt + Opening new windows query
 
3 Attachment(s)
screenshot.....
when i close it falls back to app list screen.
healthcheck still running. but hanging.........

noobmonkey 2010-03-24 23:35

Re: pyqt + Opening new windows query
 
ok sorted it i think.......... fresh mind and all :D

Well, i was calling it all from the def function.
Moved the window setup etc down to main initialisation (Where my other window is called....... Made more sense) - and then just ran window.show.....

Doesnt hang, no cpu spikes and all back to normal :D

attila77 2010-03-24 23:52

Re: pyqt + Opening new windows query
 
Quote:

Originally Posted by krk969 (Post 580123)
corrected that for you :)...

*EDIT* QT4.6
set the folllowing attribute Qt::WA_Maemo5StackedWindow as well on both windows to see that nice back button else you will see a cross :p

One teenzy note, the Maemo5 symbols (and well, general Qt4.6) support will appear in PyQt *after* the PR1.2 release. Just saying this so people using PyQt from pre-PR1.2 Extras don't wonder why this doesn't work for them.


| 1   2   | Next
All times are GMT. The time now is 19:32.

vBulletin® Version 3.8.8