Pyqt calling a custom dialog and returning the vars

M

Marcpp

I call a dialog from a principal program but cannot return the value
of the
variables (text box's). Here is a example...



from ui import Agenda
from dialog1 import dialogo1
from PyQt4 import *
import dbm
import sys

class principal (QApplication):

def __init__(self, args):
""" In the constructor we're doing everything to get our
application
started, which is basically constructing a basic
QApplication by
its __init__ method, then adding our widgets and finally
starting
the exec_loop."""
QApplication.__init__(self,args)

# We pass None since it's the top-level widget, we could in
fact leave
# that one out, but this way it's easier to add more dialogs
or widgets.
self.maindialog = ag(None)

self.setMainWidget(self.maindialog)
self.maindialog.show()
self.exec_loop()

class ag (Agenda):
....
....
def _slotAddClicked(self):
d=dialogo1()
d.exec_()
d.connect(d.buttonOk,SIGNAL("clicked()"),self._procesadialog1)

def _procesadialog1():
d=dialogo1()
drempresa = d.dempresa.text()
print drempresa #
<-------------------------------------------------------- Nothing
appears
....
....
if __name__ == "__main__":
app = principal(sys.argv)
 
D

Diez B. Roggisch

Marcpp said:
I call a dialog from a principal program but cannot return the value
of the
variables (text box's). Here is a example...



from ui import Agenda
from dialog1 import dialogo1
from PyQt4 import *
import dbm
import sys

class principal (QApplication):

def __init__(self, args):
""" In the constructor we're doing everything to get our
application
started, which is basically constructing a basic
QApplication by
its __init__ method, then adding our widgets and finally
starting
the exec_loop."""
QApplication.__init__(self,args)

# We pass None since it's the top-level widget, we could in
fact leave
# that one out, but this way it's easier to add more dialogs
or widgets.
self.maindialog = ag(None)

self.setMainWidget(self.maindialog)
self.maindialog.show()
self.exec_loop()

class ag (Agenda):
...
...
def _slotAddClicked(self):
d=dialogo1()
d.exec_()
d.connect(d.buttonOk,SIGNAL("clicked()"),self._procesadialog1)

Shouldn't you connect the signal _before_ the dialog is shown?

def _procesadialog1():
d=dialogo1()
drempresa = d.dempresa.text()
print drempresa #
<-------------------------------------------------------- Nothing
appears
...
...
if __name__ == "__main__":
app = principal(sys.argv)

Diez
 
D

David Boddie

I call a dialog from a principal program but cannot return the value
of the
variables (text box's). Here is a example...
[...]

class ag (Agenda):
...
...
def _slotAddClicked(self):
d=dialogo1()
d.exec_()
d.connect(d.buttonOk,SIGNAL("clicked()"),self._procesadialog1)

def _procesadialog1():
d=dialogo1()
drempresa = d.dempresa.text()
print drempresa #

Without seeing more of what you've done, it's difficult to tell, but
you are just creating a new dialog in _procesadialog1() and reading
the default text in its "dempresa" attribute which I presume is a
QLineEdit widget.

Assuming everything else is working correctly, I think you should
remove the second method and rewrite the first one in the following
way:

class ag (Agenda):
....
....
def _slotAddClicked(self):
d=dialogo1()
if d.exec_() == QDialog.Accepted:
drempresa = d.dempresa.text()
print drempresa #

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top