Factorize copyright settings UI
offlate/ui/config/settings.py
14 | 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | 15 | #### | |
16 | 16 | ||
17 | + | import datetime | |
17 | 18 | import os | |
18 | 19 | import re | |
19 | 20 | import sys | |
… | |||
121 | 122 | def data(self): | |
122 | 123 | return self.widget.data | |
123 | 124 | ||
124 | - | class SettingsWidget(QWidget): | |
125 | - | def __init__(self, parent=None, manager=None): | |
125 | + | class CopyrightSettingsWidget(QWidget): | |
126 | + | def __init__(self, name="", email="", parent=None): | |
126 | 127 | super().__init__(parent) | |
127 | - | self.parent = parent | |
128 | - | self.manager = manager | |
128 | + | self.name = name | |
129 | + | self.email = email | |
129 | 130 | self.initUI() | |
130 | 131 | ||
131 | 132 | def initUI(self): | |
132 | - | vbox = QVBoxLayout() | |
133 | + | layout = QVBoxLayout() | |
133 | 134 | ||
134 | - | formExplain = QLabel(self) | |
135 | - | formExplain.setText(self.tr("First, we need to know your name and email \ | |
136 | - | address, so we can use this information to give you copyright credit on your \ | |
137 | - | work, when this is posible. The copyright line will look like ???Copyright ?? \ | |
138 | - | YEAR NAME <EMAIL>???")) | |
139 | - | formExplain.setWordWrap(True) | |
140 | - | vbox.addWidget(formExplain) | |
135 | + | explainText = QLabel(self) | |
136 | + | explainText.setText(self.tr("In some cases, we need to add a copyright \ | |
137 | + | line for you in the translation files we send upstream. Here, you can configure \ | |
138 | + | how you want the copyright line to look like. This information will most likely \ | |
139 | + | become public after your first contribution.")) | |
140 | + | explainText.setWordWrap(True) | |
141 | + | layout.addWidget(explainText) | |
141 | 142 | ||
142 | 143 | form = QFormLayout() | |
143 | 144 | self.nameWidget = QLineEdit() | |
145 | + | self.nameWidget.setText(self.name) | |
144 | 146 | self.nameWidget.setPlaceholderText(self.tr("John Doe")) | |
145 | - | self.nameWidget.setText(self.manager.getConf(['Generic', 'name'])) | |
146 | 147 | self.emailWidget = QLineEdit() | |
147 | - | self.emailWidget.setPlaceholderText(self.tr("john@doe.me")) | |
148 | - | self.emailWidget.setText(self.manager.getConf(['Generic', 'email'])) | |
149 | - | form.addRow(QLabel(self.tr("Your name:")), self.nameWidget) | |
150 | - | form.addRow(QLabel(self.tr("Your email address:")), self.emailWidget) | |
151 | - | vbox.addLayout(form) | |
148 | + | self.emailWidget.setText(self.email) | |
149 | + | self.nameWidget.setPlaceholderText(self.tr("john@doe.me")) | |
150 | + | form.addRow(QLabel("Name:"), self.nameWidget) | |
151 | + | form.addRow(QLabel("Email:"), self.emailWidget) | |
152 | + | layout.addLayout(form) | |
153 | + | ||
154 | + | layout.addSpacing(15) | |
155 | + | ||
156 | + | previewLabel = QLabel() | |
157 | + | previewLabel.setText(self.tr("Here is how your copyright line will look like:")) | |
158 | + | layout.addWidget(previewLabel) | |
159 | + | ||
160 | + | layout.addSpacing(9) | |
161 | + | ||
162 | + | self.previewLine = QLabel() | |
163 | + | self.previewLine.setTextFormat(Qt.RichText) | |
164 | + | self.previewLine.setWordWrap(True) | |
165 | + | self.previewLine.setAlignment(Qt.AlignCenter) | |
166 | + | pal = QPalette() | |
167 | + | pal.setColor(QPalette.Window, Qt.white) | |
168 | + | self.previewLine.setAutoFillBackground(True) | |
169 | + | self.previewLine.setMargin(9) | |
170 | + | self.previewLine.setPalette(pal) | |
171 | + | layout.addWidget(self.previewLine) | |
172 | + | self.updatePreview() | |
173 | + | self.nameWidget.textChanged.connect(self.updatePreview) | |
174 | + | self.emailWidget.textChanged.connect(self.updatePreview) | |
175 | + | ||
176 | + | self.setLayout(layout) | |
177 | + | ||
178 | + | def updatePreview(self, _ignore=None): | |
179 | + | currentDateTime = datetime.datetime.now() | |
180 | + | date = currentDateTime.date() | |
181 | + | year = date.strftime("%Y") | |
182 | + | name = self.nameWidget.text() | |
183 | + | nameHolder = "<i>{}</i>".format(self.tr("John Doe")) | |
184 | + | email = self.emailWidget.text() | |
185 | + | emailHolder = "<i>{}</i>".format(self.tr("john@doe.me")) | |
186 | + | self.previewLine.setText(self.tr("Copyright © {} {} <{}>").format(year, | |
187 | + | name if name != "" else nameHolder, email if email != "" else emailHolder)) | |
188 | + | ||
189 | + | class SettingsWidget(QWidget): | |
190 | + | def __init__(self, parent=None, manager=None): | |
191 | + | super().__init__(parent) | |
192 | + | self.parent = parent | |
193 | + | self.manager = manager | |
194 | + | self.initUI() | |
195 | + | ||
196 | + | def initUI(self): | |
197 | + | vbox = QVBoxLayout() | |
198 | + | ||
199 | + | self.copyright = CopyrightSettingsWidget(self.manager.getConf(['Generic', 'name']), | |
200 | + | self.manager.getConf(['Generic', 'email'])) | |
201 | + | vbox.addWidget(self.copyright) | |
152 | 202 | ||
153 | 203 | systemsbox = QGridLayout() | |
154 | 204 | x = 0 | |
… | |||
197 | 247 | self.setLayout(vbox) | |
198 | 248 | ||
199 | 249 | def done(self): | |
200 | - | name = self.nameWidget.text() | |
201 | - | email = self.emailWidget.text() | |
250 | + | name = self.copyright.nameWidget.text() | |
251 | + | email = self.copyright.emailWidget.text() | |
202 | 252 | if name == None or name == "": | |
203 | 253 | return | |
204 | 254 | if email == None or email == "": |
offlate/ui/welcome.py
18 | 18 | from PyQt5.QtGui import * | |
19 | 19 | from PyQt5.QtCore import * | |
20 | 20 | ||
21 | - | import datetime | |
22 | 21 | import sys | |
23 | 22 | import os | |
24 | 23 | ||
… | |||
99 | 98 | self.setTitle(self.tr("Copyright Settings")) | |
100 | 99 | self.setSubTitle(self.tr("Configuring how your copyright is added to files")) | |
101 | 100 | ||
102 | - | explainText = QLabel(self) | |
103 | - | explainText.setText(self.tr("In some cases, we need to add a copyright \ | |
104 | - | line for you in the translation files we send upstream. Here, you can configure \ | |
105 | - | how you want the copyright line to look like. This information will most likely \ | |
106 | - | become public after your first contribution.")) | |
107 | - | explainText.setWordWrap(True) | |
108 | - | layout.addWidget(explainText) | |
109 | - | ||
110 | - | form = QFormLayout() | |
111 | - | self.nameEdit = QLineEdit() | |
112 | - | self.emailEdit = QLineEdit() | |
113 | - | form.addRow(QLabel("Name:"), self.nameEdit) | |
114 | - | form.addRow(QLabel("Email:"), self.emailEdit) | |
115 | - | layout.addLayout(form) | |
116 | - | ||
117 | - | layout.addSpacing(15) | |
118 | - | ||
119 | - | previewLabel = QLabel() | |
120 | - | previewLabel.setText(self.tr("Here is how your copyright line will look like:")) | |
121 | - | layout.addWidget(previewLabel) | |
122 | - | ||
123 | - | layout.addSpacing(9) | |
124 | - | ||
125 | - | self.previewLine = QLabel() | |
126 | - | self.previewLine.setTextFormat(Qt.RichText) | |
127 | - | self.previewLine.setWordWrap(True) | |
128 | - | self.previewLine.setAlignment(Qt.AlignCenter) | |
129 | - | pal = QPalette() | |
130 | - | pal.setColor(QPalette.Window, Qt.white) | |
131 | - | self.previewLine.setAutoFillBackground(True) | |
132 | - | self.previewLine.setMargin(9) | |
133 | - | self.previewLine.setPalette(pal) | |
134 | - | layout.addWidget(self.previewLine) | |
135 | - | self.updatePreview() | |
136 | - | self.nameEdit.textChanged.connect(self.updatePreview) | |
137 | - | self.emailEdit.textChanged.connect(self.updatePreview) | |
101 | + | self.copyright = CopyrightSettingsWidget() | |
102 | + | layout.addWidget(self.copyright) | |
138 | 103 | ||
139 | 104 | self.setLayout(layout) | |
140 | 105 | ||
141 | - | self.registerField("name*", self.nameEdit) | |
142 | - | self.registerField("email*", self.emailEdit) | |
143 | - | ||
144 | - | def updatePreview(self, _ignore=None): | |
145 | - | currentDateTime = datetime.datetime.now() | |
146 | - | date = currentDateTime.date() | |
147 | - | year = date.strftime("%Y") | |
148 | - | name = self.nameEdit.text() | |
149 | - | nameHolder = "<i>{}</i>".format(self.tr("Your Name")) | |
150 | - | email = self.emailEdit.text() | |
151 | - | emailHolder = "<i>{}</i>".format(self.tr("your@email")) | |
152 | - | self.previewLine.setText(self.tr("Copyright © {} {} <{}>").format(year, | |
153 | - | name if name != "" else nameHolder, email if email != "" else emailHolder)) | |
106 | + | self.registerField("name*", self.copyright.nameWidget) | |
107 | + | self.registerField("email*", self.copyright.emailWidget) | |
154 | 108 | ||
155 | 109 | class PageLang(QWizardPage): | |
156 | 110 | def __init__(self, parent): |