Wed, 18 Nov 2020 20:16:06 +0100
Started implementing pybabel translations support.
# -*- coding: utf-8 -*- # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to edit the PyBabel configuration. """ from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtWidgets import QDialog, QDialogButtonBox from E5Gui.E5PathPicker import E5PathPickerModes from E5Gui.E5Application import e5App from .Ui_PyBabelConfigDialog import Ui_PyBabelConfigDialog class PyBabelConfigDialog(QDialog, Ui_PyBabelConfigDialog): """ Class implementing a dialog to edit the PyBabel configuration. """ def __init__(self, configuration, parent=None): """ Constructor @param configuration current pybabel configuration @type dict @param parent reference to the parent widget @type QWidget """ super(PyBabelConfigDialog, self).__init__(parent) self.setupUi(self) e5project = e5App().getObject("Project") self.configFilePicker.setMode(E5PathPickerModes.OpenFileMode) self.configFilePicker.setFilters(self.tr( "Configuration Files (*.cfg);;" "All Files (*)" )) self.configFilePicker.setDefaultDirectory(e5project.getProjectPath()) self.catalogFilePicker.setMode(E5PathPickerModes.OpenFileMode) self.catalogFilePicker.setFilters(self.tr( "Message Catalog Files (*.pot);;" "All Files (*)" )) self.catalogFilePicker.setDefaultDirectory(e5project.getProjectPath()) self.configFilePicker.setFocus(Qt.OtherFocusReason) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) if "configFile" in configuration: self.configFilePicker.setText(configuration["configFile"]) if "catalogFile" in configuration: self.catalogFilePicker.setText(configuration["catalogFile"]) if "markersList" in configuration: self.markersEdit.setText(" ".join(configuration["markersList"])) def getConfiguration(self): """ Public method to get the entered configuration data. @return pybabel configuration @rtype dict """ configuration = { "configFile": self.configFilePicker.text(), "catalogFile": self.catalogFilePicker.text(), } if self.markersEdit.text(): configuration["markersList"] = self.markersEdit.text().split() return configuration def __updateOK(self): enable = ( bool(self.configFilePicker.text()) and bool(self.catalogFilePicker.text()) ) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) @pyqtSlot(str) def on_configFilePicker_textChanged(self, txt): """ Private slot to handle a change of the configuration file name. @param txt configuration file name @type str """ self.__updateOK() @pyqtSlot(str) def on_catalogFilePicker_textChanged(self, txt): """ Private slot to handle a change of the catalog file name. @param txt configuration file name @type str """ self.__updateOK()