|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to edit the PyBabel configuration. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot, Qt |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from E5Gui.E5PathPicker import E5PathPickerModes |
|
14 from E5Gui.E5Application import e5App |
|
15 |
|
16 from .Ui_PyBabelConfigDialog import Ui_PyBabelConfigDialog |
|
17 |
|
18 |
|
19 class PyBabelConfigDialog(QDialog, Ui_PyBabelConfigDialog): |
|
20 """ |
|
21 Class implementing a dialog to edit the PyBabel configuration. |
|
22 """ |
|
23 def __init__(self, configuration, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param configuration current pybabel configuration |
|
28 @type dict |
|
29 @param parent reference to the parent widget |
|
30 @type QWidget |
|
31 """ |
|
32 super(PyBabelConfigDialog, self).__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 e5project = e5App().getObject("Project") |
|
36 |
|
37 self.configFilePicker.setMode(E5PathPickerModes.OpenFileMode) |
|
38 self.configFilePicker.setFilters(self.tr( |
|
39 "Configuration Files (*.cfg);;" |
|
40 "All Files (*)" |
|
41 )) |
|
42 self.configFilePicker.setDefaultDirectory(e5project.getProjectPath()) |
|
43 |
|
44 self.catalogFilePicker.setMode(E5PathPickerModes.OpenFileMode) |
|
45 self.catalogFilePicker.setFilters(self.tr( |
|
46 "Message Catalog Files (*.pot);;" |
|
47 "All Files (*)" |
|
48 )) |
|
49 self.catalogFilePicker.setDefaultDirectory(e5project.getProjectPath()) |
|
50 |
|
51 self.configFilePicker.setFocus(Qt.OtherFocusReason) |
|
52 |
|
53 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
54 |
|
55 if "configFile" in configuration: |
|
56 self.configFilePicker.setText(configuration["configFile"]) |
|
57 if "catalogFile" in configuration: |
|
58 self.catalogFilePicker.setText(configuration["catalogFile"]) |
|
59 if "markersList" in configuration: |
|
60 self.markersEdit.setText(" ".join(configuration["markersList"])) |
|
61 |
|
62 def getConfiguration(self): |
|
63 """ |
|
64 Public method to get the entered configuration data. |
|
65 |
|
66 @return pybabel configuration |
|
67 @rtype dict |
|
68 """ |
|
69 configuration = { |
|
70 "configFile": self.configFilePicker.text(), |
|
71 "catalogFile": self.catalogFilePicker.text(), |
|
72 } |
|
73 if self.markersEdit.text(): |
|
74 configuration["markersList"] = self.markersEdit.text().split() |
|
75 |
|
76 return configuration |
|
77 |
|
78 def __updateOK(self): |
|
79 enable = ( |
|
80 bool(self.configFilePicker.text()) and |
|
81 bool(self.catalogFilePicker.text()) |
|
82 ) |
|
83 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
84 |
|
85 @pyqtSlot(str) |
|
86 def on_configFilePicker_textChanged(self, txt): |
|
87 """ |
|
88 Private slot to handle a change of the configuration file name. |
|
89 |
|
90 @param txt configuration file name |
|
91 @type str |
|
92 """ |
|
93 self.__updateOK() |
|
94 |
|
95 @pyqtSlot(str) |
|
96 def on_catalogFilePicker_textChanged(self, txt): |
|
97 """ |
|
98 Private slot to handle a change of the catalog file name. |
|
99 |
|
100 @param txt configuration file name |
|
101 @type str |
|
102 """ |
|
103 self.__updateOK() |