ProjectFlask/FlaskBabelExtension/PyBabelConfigDialog.py

branch
eric7
changeset 70
22e1d0f69668
parent 66
0d3168d0e310
child 72
4557829a4acf
equal deleted inserted replaced
69:c31a4f756a04 70:22e1d0f69668
20 20
21 class PyBabelConfigDialog(QDialog, Ui_PyBabelConfigDialog): 21 class PyBabelConfigDialog(QDialog, Ui_PyBabelConfigDialog):
22 """ 22 """
23 Class implementing a dialog to edit the flask-babel configuration. 23 Class implementing a dialog to edit the flask-babel configuration.
24 """ 24 """
25
25 def __init__(self, configuration, parent=None): 26 def __init__(self, configuration, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param configuration current pybabel configuration 30 @param configuration current pybabel configuration
30 @type dict 31 @type dict
31 @param parent reference to the parent widget 32 @param parent reference to the parent widget
32 @type QWidget 33 @type QWidget
33 """ 34 """
34 super().__init__(parent) 35 super().__init__(parent)
35 self.setupUi(self) 36 self.setupUi(self)
36 37
37 self.__ericProject = ericApp().getObject("Project") 38 self.__ericProject = ericApp().getObject("Project")
38 39
39 self.configFilePicker.setMode( 40 self.configFilePicker.setMode(
40 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE) 41 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE
41 self.configFilePicker.setFilters(self.tr( 42 )
42 "Configuration Files (*.cfg);;" 43 self.configFilePicker.setFilters(
43 "All Files (*)" 44 self.tr("Configuration Files (*.cfg);;" "All Files (*)")
44 )) 45 )
45 self.configFilePicker.setDefaultDirectory( 46 self.configFilePicker.setDefaultDirectory(self.__ericProject.getProjectPath())
46 self.__ericProject.getProjectPath()) 47
47 48 self.translationsDirectoryPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
48 self.translationsDirectoryPicker.setMode(
49 EricPathPickerModes.DIRECTORY_MODE)
50 self.translationsDirectoryPicker.setDefaultDirectory( 49 self.translationsDirectoryPicker.setDefaultDirectory(
51 self.__ericProject.getProjectPath()) 50 self.__ericProject.getProjectPath()
52 51 )
52
53 self.catalogFilePicker.setMode( 53 self.catalogFilePicker.setMode(
54 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE) 54 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE
55 self.catalogFilePicker.setFilters(self.tr( 55 )
56 "Message Catalog Files (*.pot);;" 56 self.catalogFilePicker.setFilters(
57 "All Files (*)" 57 self.tr("Message Catalog Files (*.pot);;" "All Files (*)")
58 )) 58 )
59 self.catalogFilePicker.setDefaultDirectory( 59 self.catalogFilePicker.setDefaultDirectory(self.__ericProject.getProjectPath())
60 self.__ericProject.getProjectPath()) 60
61
62 self.configFilePicker.setFocus(Qt.FocusReason.OtherFocusReason) 61 self.configFilePicker.setFocus(Qt.FocusReason.OtherFocusReason)
63 62
64 self.buttonBox.button( 63 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
65 QDialogButtonBox.StandardButton.Ok).setEnabled(False) 64
66
67 if "configFile" in configuration: 65 if "configFile" in configuration:
68 self.configFilePicker.setText( 66 self.configFilePicker.setText(
69 self.__ericProject.getAbsoluteUniversalPath( 67 self.__ericProject.getAbsoluteUniversalPath(configuration["configFile"])
70 configuration["configFile"])) 68 )
71 if "translationsDirectory" in configuration: 69 if "translationsDirectory" in configuration:
72 self.translationsDirectoryPicker.setText( 70 self.translationsDirectoryPicker.setText(
73 self.__ericProject.getAbsoluteUniversalPath( 71 self.__ericProject.getAbsoluteUniversalPath(
74 configuration["translationsDirectory"])) 72 configuration["translationsDirectory"]
73 )
74 )
75 if "domain" in configuration: 75 if "domain" in configuration:
76 self.domainEdit.setText(configuration["domain"]) 76 self.domainEdit.setText(configuration["domain"])
77 if "catalogFile" in configuration: 77 if "catalogFile" in configuration:
78 self.catalogFilePicker.setText( 78 self.catalogFilePicker.setText(
79 self.__ericProject.getAbsoluteUniversalPath( 79 self.__ericProject.getAbsoluteUniversalPath(
80 configuration["catalogFile"])) 80 configuration["catalogFile"]
81 )
82 )
81 if "markersList" in configuration: 83 if "markersList" in configuration:
82 self.markersEdit.setText(" ".join(configuration["markersList"])) 84 self.markersEdit.setText(" ".join(configuration["markersList"]))
83 85
84 msh = self.minimumSizeHint() 86 msh = self.minimumSizeHint()
85 self.resize(max(self.width(), msh.width()), msh.height()) 87 self.resize(max(self.width(), msh.width()), msh.height())
86 88
87 def getConfiguration(self): 89 def getConfiguration(self):
88 """ 90 """
89 Public method to get the entered configuration data. 91 Public method to get the entered configuration data.
90 92
91 @return pybabel configuration 93 @return pybabel configuration
92 @rtype dict 94 @rtype dict
93 """ 95 """
94 configuration = { 96 configuration = {
95 "configFile": 97 "configFile": self.__ericProject.getRelativeUniversalPath(
96 self.__ericProject.getRelativeUniversalPath( 98 self.configFilePicker.text()
97 self.configFilePicker.text()), 99 ),
98 "translationsDirectory": 100 "translationsDirectory": self.__ericProject.getRelativeUniversalPath(
99 self.__ericProject.getRelativeUniversalPath( 101 self.translationsDirectoryPicker.text()
100 self.translationsDirectoryPicker.text()), 102 ),
101 } 103 }
102 104
103 domain = self.domainEdit.text() 105 domain = self.domainEdit.text()
104 if domain: 106 if domain:
105 configuration["domain"] = domain 107 configuration["domain"] = domain
106 else: 108 else:
107 configuration["domain"] = "messages" 109 configuration["domain"] = "messages"
108 110
109 catalogFile = self.catalogFilePicker.text() 111 catalogFile = self.catalogFilePicker.text()
110 if not catalogFile: 112 if not catalogFile:
111 # use a default name made of translations dir and domain 113 # use a default name made of translations dir and domain
112 catalogFile = os.path.join( 114 catalogFile = os.path.join(
113 configuration["translationsDirectory"], 115 configuration["translationsDirectory"],
114 "{0}.pot".format(configuration["domain"])) 116 "{0}.pot".format(configuration["domain"]),
115 configuration["catalogFile"] = ( 117 )
116 self.__ericProject.getRelativeUniversalPath(catalogFile) 118 configuration["catalogFile"] = self.__ericProject.getRelativeUniversalPath(
119 catalogFile
117 ) 120 )
118 121
119 if self.markersEdit.text(): 122 if self.markersEdit.text():
120 configuration["markersList"] = self.markersEdit.text().split() 123 configuration["markersList"] = self.markersEdit.text().split()
121 124
122 return configuration 125 return configuration
123 126
124 def __updateOK(self): 127 def __updateOK(self):
125 """ 128 """
126 Private method to update the status of the OK button. 129 Private method to update the status of the OK button.
127 """ 130 """
128 enable = ( 131 enable = bool(self.configFilePicker.text()) and bool(
129 bool(self.configFilePicker.text()) and 132 self.translationsDirectoryPicker.text()
130 bool(self.translationsDirectoryPicker.text())
131 ) 133 )
132 self.buttonBox.button( 134 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
133 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) 135
134
135 def __updateCatalogPicker(self): 136 def __updateCatalogPicker(self):
136 """ 137 """
137 Private method to update the contents of the catalog picker. 138 Private method to update the contents of the catalog picker.
138 """ 139 """
139 translationsDirectory = self.translationsDirectoryPicker.text() 140 translationsDirectory = self.translationsDirectoryPicker.text()
140 domain = self.domainEdit.text() 141 domain = self.domainEdit.text()
141 self.catalogFilePicker.setText(os.path.join( 142 self.catalogFilePicker.setText(
142 translationsDirectory, "{0}.pot".format(domain))) 143 os.path.join(translationsDirectory, "{0}.pot".format(domain))
143 144 )
145
144 @pyqtSlot(str) 146 @pyqtSlot(str)
145 def on_configFilePicker_textChanged(self, txt): 147 def on_configFilePicker_textChanged(self, txt):
146 """ 148 """
147 Private slot to handle a change of the configuration file name. 149 Private slot to handle a change of the configuration file name.
148 150
149 @param txt configuration file name 151 @param txt configuration file name
150 @type str 152 @type str
151 """ 153 """
152 self.__updateOK() 154 self.__updateOK()
153 155
154 @pyqtSlot(str) 156 @pyqtSlot(str)
155 def on_translationsDirectoryPicker_textChanged(self, txt): 157 def on_translationsDirectoryPicker_textChanged(self, txt):
156 """ 158 """
157 Private slot to handle a change of the catalog file name. 159 Private slot to handle a change of the catalog file name.
158 160
159 @param txt configuration file name 161 @param txt configuration file name
160 @type str 162 @type str
161 """ 163 """
162 self.__updateOK() 164 self.__updateOK()
163 self.__updateCatalogPicker() 165 self.__updateCatalogPicker()
164 166
165 @pyqtSlot(str) 167 @pyqtSlot(str)
166 def on_domainEdit_textChanged(self, txt): 168 def on_domainEdit_textChanged(self, txt):
167 """ 169 """
168 Private slot to handle a change of the translations domain. 170 Private slot to handle a change of the translations domain.
169 171
170 @param txt entered translations domain 172 @param txt entered translations domain
171 @type str 173 @type str
172 """ 174 """
173 self.__updateCatalogPicker() 175 self.__updateCatalogPicker()

eric ide

mercurial