Thu, 19 Nov 2020 20:19:55 +0100
Continued 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) self.__e5project = e5App().getObject("Project") self.configFilePicker.setMode( E5PathPickerModes.SaveFileEnsureExtensionMode) self.configFilePicker.setFilters(self.tr( "Configuration Files (*.cfg);;" "All Files (*)" )) self.configFilePicker.setDefaultDirectory( self.__e5project.getProjectPath()) self.catalogFilePicker.setMode( E5PathPickerModes.SaveFileEnsureExtensionMode) self.catalogFilePicker.setFilters(self.tr( "Message Catalog Files (*.pot);;" "All Files (*)" )) self.catalogFilePicker.setDefaultDirectory( self.__e5project.getProjectPath()) self.configFilePicker.setFocus(Qt.OtherFocusReason) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) if "configFile" in configuration: self.configFilePicker.setText( self.__e5project.getAbsoluteUniversalPath( configuration["configFile"])) if "catalogFile" in configuration: self.catalogFilePicker.setText( self.__e5project.getAbsoluteUniversalPath( configuration["catalogFile"])) if "markersList" in configuration: self.markersEdit.setText(" ".join(configuration["markersList"])) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) def getConfiguration(self): """ Public method to get the entered configuration data. @return pybabel configuration @rtype dict """ configuration = { "configFile": self.__e5project.getRelativeUniversalPath( self.configFilePicker.text()), "catalogFile": self.__e5project.getRelativeUniversalPath( 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()