Fix editing projects
CHANGELOG
21 | 21 | * Unsupported formats raises a specific exception that can be caught by the UI | |
22 | 22 | * Stop crashing when an error occurs during project fetching | |
23 | 23 | * Properly load empty translations in ts format | |
24 | + | * Fix crash when editing a project | |
24 | 25 | ||
25 | 26 | Changes since 0.2 | |
26 | 27 | ----------------- |
offlate/manager.py
159 | 159 | self.projects = [x for x in self.projects if x['name'] != name] | |
160 | 160 | self.writeProjects() | |
161 | 161 | ||
162 | - | def updateProject(self, name, lang, system, info): | |
163 | - | rmdir(self.basedir + '/' + name) | |
162 | + | def updateProject(self, name, lang, system, info, callback): | |
163 | + | try: | |
164 | + | rmdir(self.basedir + '/' + name) | |
165 | + | except: | |
166 | + | pass | |
164 | 167 | self.projects = [x for x in self.projects if x['name'] != name] | |
165 | - | self.createProject(name, lang, system, info) | |
168 | + | return self.createProject(name, lang, system, info, callback) |
offlate/ui/manager.py
249 | 249 | return | |
250 | 250 | worker = EditRunnable(self, w.getProjectName(), w.getProjectLang(), | |
251 | 251 | w.getProjectSystem(), w.getProjectInfo()) | |
252 | + | worker.signals.progress.connect(self.reportProgress) | |
253 | + | worker.signals.restart_required.connect(self.restartNew) | |
254 | + | worker.signals.finished.connect(self.finishReport) | |
252 | 255 | self.threadpool.start(worker) | |
253 | 256 | ||
254 | 257 | class NewRunnableSignals(QObject): | |
… | |||
257 | 260 | error = pyqtSignal(str, str) | |
258 | 261 | restart_required = pyqtSignal(str, str, int, dict, str) | |
259 | 262 | ||
260 | - | class NewRunnable(QRunnable): | |
261 | - | def __init__(self, parent, name, lang, system, info): | |
262 | - | super().__init__() | |
263 | - | self.name = name | |
264 | - | self.lang = lang | |
265 | - | self.system = system | |
266 | - | self.info = info | |
267 | - | self.parent = parent | |
268 | - | self.signals = NewRunnableSignals() | |
269 | - | self.oldamount = -1 | |
270 | - | self.error = None | |
271 | - | ||
272 | - | def run(self): | |
273 | - | res = self.parent.manager.createProject(self.name, self.lang, self.system, | |
274 | - | self.info, self) | |
275 | - | if res: | |
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) | |
280 | - | self.parent.filter() | |
281 | - | ||
263 | + | class RunnableCallback: | |
282 | 264 | def progress(self, amount): | |
283 | 265 | if int(round(amount)) > self.oldamount: | |
284 | 266 | self.oldamount = int(round(amount)) | |
… | |||
302 | 284 | self.error = self.parent.tr('An unexpected error occured while \ | |
303 | 285 | fetching the project: {}. You should report this as a bug.'.format(str(error))) | |
304 | 286 | ||
305 | - | class EditRunnable(QRunnable): | |
287 | + | class NewRunnable(QRunnable, RunnableCallback): | |
288 | + | def __init__(self, parent, name, lang, system, info): | |
289 | + | super().__init__() | |
290 | + | self.name = name | |
291 | + | self.lang = lang | |
292 | + | self.system = system | |
293 | + | self.info = info | |
294 | + | self.parent = parent | |
295 | + | self.signals = NewRunnableSignals() | |
296 | + | self.oldamount = -1 | |
297 | + | self.error = None | |
298 | + | ||
299 | + | def run(self): | |
300 | + | res = self.parent.manager.createProject(self.name, self.lang, self.system, | |
301 | + | self.info, self) | |
302 | + | if res: | |
303 | + | self.signals.finished.emit(self.name) | |
304 | + | else: | |
305 | + | self.signals.restart_required.emit(self.name, self.lang, self.system, | |
306 | + | self.info, self.error) | |
307 | + | self.parent.filter() | |
308 | + | ||
309 | + | class EditRunnable(QRunnable, RunnableCallback): | |
306 | 310 | def __init__(self, parent, name, lang, system, info): | |
307 | 311 | super().__init__() | |
308 | 312 | self.name = name | |
… | |||
310 | 314 | self.system = system | |
311 | 315 | self.info = info | |
312 | 316 | self.parent = parent | |
317 | + | self.signals = NewRunnableSignals() | |
318 | + | self.oldamount = -1 | |
319 | + | self.error = None | |
313 | 320 | ||
314 | 321 | def run(self): | |
315 | - | self.parent.manager.updateProject(self.name, self.lang, self.system, | |
316 | - | self.info) | |
322 | + | res = self.parent.manager.updateProject(self.name, self.lang, self.system, | |
323 | + | self.info, self) | |
324 | + | if res: | |
325 | + | self.signals.finished.emit(self.name) | |
326 | + | else: | |
327 | + | self.signals.restart_required.emit(self.name, self.lang, self.system, | |
328 | + | self.info, self.error) | |
317 | 329 | self.parent.filter() |