I hate to ask for help debugging this code, but this is my first little pyqt 
project, and I'm stumped.

This little form has a text input widget, and a button marked 'dowload'.  I 
connected the text input "returnPressed" to one method, and connected the 
download button "clicked" to another method.

When I hit return in the text input, both methods trigger!  Can anyone give me 
a hint?
#!/usr/bin/env python

"""PyQt4 port of the dialogs/findfiles example from Qt v4.x"""

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class Form (QDialog):
    def __init__(self, parent=None):
        super (Form, self).__init__(parent)

        self.addr_label = QLabel(self.tr("addr:"))
        self.addr_edit = QLineEdit ("0x")
        addr_reg = QRegExp (r'0x[0-9a-f]*')
        self.addr_edit.setValidator (QRegExpValidator (addr_reg, self))

        addr_layout = QHBoxLayout()
        ##addr_layout.addStretch()
        addr_layout.addWidget(self.addr_label)
        addr_layout.addWidget(self.addr_edit)

        self.val_label = QLabel(self.tr("value:"))
        self.val_edit = QLineEdit ("0x")
        val_reg = QRegExp (r'0x[0-9a-f]*')
        self.val_edit.setValidator (QRegExpValidator (val_reg, self))
        
        val_layout = QHBoxLayout()
        val_layout.addWidget(self.val_label)
        val_layout.addWidget(self.val_edit)

        layout = QVBoxLayout()
        layout.addLayout (addr_layout)
        layout.addLayout (val_layout)

        addr_val_box = QGroupBox ("Register")
        addr_val_box.setLayout (layout)

        quit_button = QPushButton ("Quit")
        dl_button = QPushButton ("DownLoad")

        button_layout = QHBoxLayout()
        button_layout.addStretch()
        button_layout.addWidget (dl_button)
        button_layout.addWidget (quit_button)
        
        top_layout = QVBoxLayout()
        top_layout.addWidget (addr_val_box)
        top_layout.addLayout (button_layout)
        
        self.setLayout(top_layout)

        self.connect (self.addr_edit, SIGNAL ("returnPressed()"), self.accept)
        self.connect (dl_button, SIGNAL ("clicked()"), self.download_button)
        self.connect (quit_button, SIGNAL ("clicked()"), qApp, SLOT("quit()"))
        
    def accept (self):
        print "accept", self.addr_edit.text()
        return
    
    def download_button (self):
        fileName = QFileDialog.getOpenFileName(self, "Open Image", "/home/nbecker", "Image Files (*.png *.jpg *.bmp)")
        return
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    sys.exit(app.exec_())

_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to