Add settings for transifex

Julien LepillerThu Apr 12 22:02:20+0200 2018

79e20f0

Add settings for transifex

offlate/window.py

243243
244244
        tab = QTabWidget()
245245
        self.addTPTab(tab)
246+
        self.addTransifexTab(tab)
246247
247248
        buttonbox = QHBoxLayout()
248249
        cancel = QPushButton(self.tr("Cancel"))

256257
        cancel.clicked.connect(self.close)
257258
        ok.clicked.connect(self.ok)
258259
260+
    def addTransifexTab(self, tab):
261+
        formBox = QGroupBox(self.tr("Transifex"))
262+
        formLayout = QFormLayout()
263+
        self.TransifexToken = QLineEdit()
264+
265+
        if not "Transifex" in self.data:
266+
            self.data["Transifex"] = {}
267+
        try:
268+
            self.TransifexToken.setText(self.data["Transifex"]["token"])
269+
        except Exception:
270+
            pass
271+
272+
        self.TransifexToken.textChanged.connect(self.updateTransifex)
273+
        label = QLabel(self.tr("You can get a token from <a href=\"#\">https://www.transifex.com/user/settings/api/</a>"))
274+
        label.linkActivated.connect(self.openTransifex)
275+
276+
        formLayout.addRow(QLabel(self.tr("Token:")), self.TransifexToken)
277+
        formLayout.addRow(label)
278+
279+
        formBox.setLayout(formLayout)
280+
        tab.addTab(formBox, "Transifex")
281+
282+
    def openTransifex(self):
283+
        QDesktopServices().openUrl(QUrl("https://www.transifex.com/user/settings/api/"));
284+
285+
    def updateTransifex(self):
286+
        self.data["Transifex"] = {}
287+
        self.data["Transifex"]["token"] = self.TransifexToken.text()
288+
259289
    def addTPTab(self, tab):
260-
        formBox = QGroupBox("Form layout")
290+
        formBox = QGroupBox(self.tr("Translation Project"))
261291
        formLayout = QFormLayout()
262292
263293
        self.TPemail = QLineEdit()

266296
267297
        if not "TP" in self.data:
268298
            self.data["TP"] = {}
269-
        self.TPemail.setText(self.data["TP"]["email"])
270-
        self.TPuser.setText(self.data["TP"]["user"])
271-
        self.TPserver.setText(self.data["TP"]["server"])
299+
300+
        try:
301+
            self.TPemail.setText(self.data["TP"]["email"])
302+
            self.TPuser.setText(self.data["TP"]["user"])
303+
            self.TPserver.setText(self.data["TP"]["server"])
304+
        except Exception:
305+
            pass
272306
273307
        self.TPemail.textChanged.connect(self.updateTP)
274308
        self.TPuser.textChanged.connect(self.updateTP)