def __init__(self):
     QtGui.QDialog.__init__(self)
     # Set up the user interface from Designer.
     self.ui = Ui_RandomLayer()
     self.ui.setupUi(self)
     settings = QtCore.QSettings()
     self.ui.txtCrs.setText(settings.value('/RandomLayerPlugin/crs', ""))
     self.ui.txtNPoints.setText(settings.value('/RandomLayerPlugin/npoints', ""))
     self.ui.txtFilepath.setText(settings.value('/RandomLayerPlugin/filepath', ""))
class RandomLayerDialog(QtGui.QDialog):

    def __init__(self):
        QtGui.QDialog.__init__(self)
        # Set up the user interface from Designer.
        self.ui = Ui_RandomLayer()
        self.ui.setupUi(self)
        settings = QtCore.QSettings()
        self.ui.txtCrs.setText(settings.value('/RandomLayerPlugin/crs', ""))
        self.ui.txtNPoints.setText(settings.value('/RandomLayerPlugin/npoints', ""))
        self.ui.txtFilepath.setText(settings.value('/RandomLayerPlugin/filepath', ""))


    def accept(self):
        self.filepath = self.ui.txtFilepath.text()
        authid = self.ui.txtCrs.text()
        self.crs = QgsCoordinateReferenceSystem(authid)
        if not self.crs.isValid():
            self.setYellowBackground(self.ui.txtCrs)
            return
        try:
            self.npoints = int(self.ui.txtNPoints.text())
        except ValueError:
            self.setYellowBackground(self.ui.txtNPoints)
            return
        if self.npoints < 1:
            self.setYellowBackground(self.ui.txtNPoints)
            return

        self.ok = True    
        settings = QtCore.QSettings()
        settings.setValue('/RandomLayerPlugin/crs', self.ui.txtCrs.text())
        settings.setValue('/RandomLayerPlugin/npoints', self.ui.txtNPoints.text())
        settings.setValue('/RandomLayerPlugin/filepath', self.ui.txtFilepath.text())  
        QtGui.QDialog.accept(self)        
        
    def reject(self):       
        self.ok = False
        QtGui.QDialog.reject(self)   

    def setYellowBackground(self, widget):
        widget.setStyleSheet("QLineEdit{background: yellow}")