Restart new window if there is an error fetching the project
offlate/ui/manager.py
161 | 161 | worker.signals.finished.connect(self.openProject) | |
162 | 162 | worker.signals.finished.connect(self.finishReport) | |
163 | 163 | worker.signals.progress.connect(self.reportProgress) | |
164 | - | worker.signals.error.connect(self.reportError) | |
164 | + | worker.signals.restart_required.connect(self.restartNew) | |
165 | + | self.threadpool.start(worker) | |
166 | + | ||
167 | + | def restartNew(self, name, lang, system, info, error): | |
168 | + | self.reportError(name, error) | |
169 | + | w = NewWindow(self.manager, self, name, lang, system, info) | |
170 | + | w.exec_() | |
171 | + | if not w.wantNew(): | |
172 | + | return | |
173 | + | worker = NewRunnable(self, w.getProjectName(), w.getProjectLang(), | |
174 | + | w.getProjectSystem(), w.getProjectInfo()) | |
175 | + | worker.signals.finished.connect(self.openProject) | |
176 | + | worker.signals.finished.connect(self.finishReport) | |
177 | + | worker.signals.progress.connect(self.reportProgress) | |
178 | + | worker.signals.restart_required.connect(self.restartNew) | |
165 | 179 | self.threadpool.start(worker) | |
166 | 180 | ||
167 | 181 | def reportError(self, name, msg): | |
… | |||
241 | 255 | finished = pyqtSignal(str) | |
242 | 256 | progress = pyqtSignal(str, int) | |
243 | 257 | error = pyqtSignal(str, str) | |
258 | + | restart_required = pyqtSignal(str, str, int, dict, str) | |
244 | 259 | ||
245 | 260 | class NewRunnable(QRunnable): | |
246 | 261 | def __init__(self, parent, name, lang, system, info): | |
… | |||
252 | 267 | self.parent = parent | |
253 | 268 | self.signals = NewRunnableSignals() | |
254 | 269 | self.oldamount = -1 | |
270 | + | self.error = None | |
255 | 271 | ||
256 | 272 | def run(self): | |
257 | 273 | res = self.parent.manager.createProject(self.name, self.lang, self.system, | |
258 | 274 | self.info, self) | |
259 | 275 | if res: | |
260 | 276 | self.signals.finished.emit(self.name) | |
277 | + | else: | |
278 | + | self.signals.restart_required.emit(self.name, self.lang, self.system, | |
279 | + | self.info, self.error) | |
261 | 280 | self.parent.filter() | |
262 | 281 | ||
263 | 282 | def progress(self, amount): | |
… | |||
266 | 285 | self.signals.progress.emit(self.name, amount) | |
267 | 286 | ||
268 | 287 | def project_exists(self): | |
269 | - | self.signals.error.emit(self.name, self.parent.tr('A project with the \ | |
270 | - | same name already exists. The new project was not created. You should first \ | |
271 | - | remove the same-named project.')) | |
288 | + | self.error = self.parent.tr('A project with the same name already exists. \ | |
289 | + | The new project was not created. You should first remove the same-named project.') | |
272 | 290 | ||
273 | 291 | def project_present(self, directory): | |
274 | - | self.signals.error.emit(self.name, self.parent.tr('Your filesystem \ | |
275 | - | contains a same-named directory for your new project. The new project was not \ | |
276 | - | created. You should first remove the same-named directory: {}.'.format(directory))) | |
292 | + | self.error = self.parent.tr('Your filesystem contains a same-named \ | |
293 | + | directory for your new project. The new project was not created. You should \ | |
294 | + | first remove the same-named directory: "{}".'.format(directory)) | |
277 | 295 | ||
278 | 296 | def project_error(self, error): | |
279 | 297 | if isinstance(error, UnsupportedFormatException): | |
280 | - | self.signals.error.emit(self.name, self.parent.tr('The project you \ | |
281 | - | added uses the {} format, but it is not supported yet by Offlate. You can try to \ | |
282 | - | update the application, or if you are on the latest version already, report \ | |
283 | - | it as a bug!'.format(error.unsupportedFormat))) | |
298 | + | self.error = self.parent.tr('The project you added uses the {} format, \ | |
299 | + | but it is not supported yet by Offlate. You can try to update the application, \ | |
300 | + | or if you are on the latest version already, report it as a bug.'.format(error.unsupportedFormat)) | |
284 | 301 | else: | |
285 | - | self.signals.error.emit(self.name, self.parent.tr('An unexpected \ | |
286 | - | error occured while fetching the project: {}. You should report this as a \ | |
287 | - | bug.'.format(str(error)))) | |
302 | + | self.error = self.parent.tr('An unexpected error occured while \ | |
303 | + | fetching the project: {}. You should report this as a bug.'.format(str(error))) | |
288 | 304 | ||
289 | 305 | class EditRunnable(QRunnable): | |
290 | 306 | def __init__(self, parent, name, lang, system, info): |