disable button in new window when all fields are not filled

Julien LepillerFri Apr 20 15:26:55+0200 2018

0c17aa1

disable button in new window when all fields are not filled

offlate/window.py

201201
        self.combo.addItem(self.tr("Transifex"))
202202
        self.formLayout.addRow(self.combo)
203203
204+
        self.nameWidget.textChanged.connect(self.modify)
205+
        self.langWidget.textChanged.connect(self.modify)
206+
204207
        hhbox = QHBoxLayout()
205208
        cancel = QPushButton(self.tr("Cancel"))
206-
        ok = QPushButton(self.tr("OK"))
209+
        self.okbutton = QPushButton(self.tr("OK"))
210+
        self.okbutton.setEnabled(False)
207211
        hhbox.addWidget(cancel)
208-
        hhbox.addWidget(ok)
212+
        hhbox.addWidget(self.okbutton)
209213
        contentbox.addWidget(formbox)
210214
        contentbox.addLayout(hhbox)
211215
        hbox.addLayout(predefinedbox)

215219
        self.additionalFields.append([])
216220
        self.additionalFields.append([])
217221
        self.transifexOrganisation = QLineEdit()
222+
        self.transifexOrganisation.textChanged.connect(self.modify)
218223
        transifexOrganisationLabel = QLabel(self.tr("Organization"))
219224
        self.additionalFields[1].append({'label': transifexOrganisationLabel,
220225
            'widget': self.transifexOrganisation})

223228
224229
        self.predefinedprojects.currentItemChanged.connect(self.fill)
225230
        cancel.clicked.connect(self.close)
226-
        ok.clicked.connect(self.ok)
231+
        self.okbutton.clicked.connect(self.ok)
227232
        self.searchfield.textChanged.connect(self.filter)
228233
        self.combo.currentIndexChanged.connect(self.othersystem)
229234

249254
                item.setData(Qt.UserRole, d)
250255
                self.predefinedprojects.addItem(item)
251256
257+
    def modify(self):
258+
        enable = False
259+
        if self.nameWidget.text() != '' and self.langWidget.text() != '':
260+
            enable = True
261+
            for widget in self.additionalFields[self.combo.currentIndex()]:
262+
                if widget['widget'].text() == '':
263+
                    enable = False
264+
                    break
265+
        self.okbutton.setEnabled(enable)
266+
252267
    def wantNew(self):
253268
        return self.askNew
254269

279294
            self.formLayout.addRow(widget['label'], widget['widget'])
280295
            widget['widget'].show()
281296
            widget['label'].show()
297+
        self.modify()
282298
283299
class SettingsWindow(QDialog):
284300
    def __init__(self, preferences, parent = None):