Fixes for the callback system
offlate/core/manager.py
71 | 71 | f.write(json.dumps([])) | |
72 | 72 | ||
73 | 73 | def createProject(self, name, lang, system, data, callback): | |
74 | - | callback.progress(0) | |
74 | + | callback.reportProgress(0) | |
75 | 75 | ||
76 | 76 | projectpath = self.basedir + '/' + name | |
77 | 77 | path = Path(projectpath) | |
… | |||
97 | 97 | rmdir(projectpath) | |
98 | 98 | return False | |
99 | 99 | ||
100 | - | callback.progress(100) | |
100 | + | callback.reportProgress(100) | |
101 | 101 | ||
102 | 102 | self.writeProjects() | |
103 | 103 | return True |
offlate/systems/callback.py
20 | 20 | """ | |
21 | 21 | The base class for callbacks used in the different systems. | |
22 | 22 | """ | |
23 | - | def reportProgress(progress): | |
23 | + | def reportProgress(self, progress): | |
24 | 24 | """ | |
25 | 25 | Report progress in some operation. This method is called during download, | |
26 | 26 | update and upload of translation projects. | |
27 | 27 | """ | |
28 | 28 | raise Exception("Unimplemented method in concrete class: reportProgress") | |
29 | 29 | ||
30 | + | def askPassword(self): | |
31 | + | """ | |
32 | + | Get a password (interactively or not) and return it to the caller. | |
33 | + | """ | |
34 | + | raise Exception("Unimplemented method in concrete class: askPassword") | |
35 | + | ||
30 | 36 | def githubBranchError(branch): | |
31 | 37 | """ | |
32 | 38 | Report an error while accessing a branch |
offlate/systems/git.py
46 | 46 | ||
47 | 47 | def transfer_progress(self, stats): | |
48 | 48 | if self.callback is not None: | |
49 | - | self.callback.progress((100.0 * stats.received_objects) / \ | |
49 | + | self.callback.reportProgress((100.0 * stats.received_objects) / \ | |
50 | 50 | stats.total_objects) | |
51 | 51 | ||
52 | 52 | class GitProject(Project): |
offlate/ui/editor.py
21 | 21 | from .spellcheckedit import SpellCheckEdit | |
22 | 22 | from .tagclickedit import TagClickEdit | |
23 | 23 | from .parallel import RunnableCallback, RunnableSignals | |
24 | + | from ..systems.callback import SystemCallback | |
24 | 25 | ||
25 | 26 | import math | |
26 | 27 | import platform | |
… | |||
35 | 36 | def __init__(self, parent = None): | |
36 | 37 | super(ProjectTab, self).__init__(parent) | |
37 | 38 | ||
38 | - | class Interface: | |
39 | + | class Interface(SystemCallback): | |
39 | 40 | def __init__(self): | |
40 | 41 | self.value = None | |
41 | 42 | ||
42 | 43 | def ok(self): | |
43 | 44 | self.value = self.qd.textValue() | |
44 | 45 | ||
46 | + | def mergeConflict(self, base, oldTranslation, newTranslation): | |
47 | + | # TODO: Actually do something more intelligent | |
48 | + | return newTranslation | |
49 | + | ||
45 | 50 | def askPassword(self): | |
46 | 51 | self.qd = QInputDialog() | |
47 | 52 | self.qd.setLabelText(self.qd.tr("Please enter your password:")) | |
… | |||
50 | 55 | self.qd.exec_() | |
51 | 56 | return self.value | |
52 | 57 | ||
53 | - | def gitlabTokenNotFound(self, server): | |
58 | + | def gitlabTokenNotFoundError(self, server): | |
54 | 59 | self.qd = QErrorMessage() | |
55 | 60 | self.qd.showMessage(self.qd.tr("Token for {} not found. Have you added this server to your settings?.").format(server)) | |
56 | 61 | self.qd.exec_() | |
57 | 62 | ||
58 | - | def gitlabTokenBranchError(self, branch): | |
63 | + | def gitlabBranchError(self, branch): | |
59 | 64 | self.qd = QErrorMessage() | |
60 | 65 | self.qd.showMessage(self.qd.tr("Error while creating branch {}.").format(branch)) | |
61 | 66 | self.qd.exec_() | |
… | |||
366 | 371 | self.project.save() | |
367 | 372 | self.project.send(Interface()) | |
368 | 373 | ||
369 | - | def askmerge(self, msgid, oldstr, newstr): | |
370 | - | # TODO: Actually do something more intelligent | |
371 | - | return newstr | |
372 | - | ||
373 | - | def update(self, callback=None): | |
374 | + | def update(self, callback=Interface()): | |
374 | 375 | self.project.save() | |
375 | - | self.project.update(self.askmerge, callback) | |
376 | + | self.project.update(callback) | |
376 | 377 | self.content = self.project.content() | |
377 | 378 | self.updateContent() | |
378 | 379 | ||
… | |||
399 | 400 | l = self.manager.listProjects() | |
400 | 401 | for p in l: | |
401 | 402 | name = p['name'] | |
402 | - | act = QAction(name, self) | |
403 | + | act = QAction(name, self) | |
403 | 404 | act.triggered.connect((lambda name: (lambda : self.open(name)))(name)) | |
404 | 405 | menu.addAction(act) | |
405 | 406 | ||
… | |||
621 | 622 | self.oldamount = -1 | |
622 | 623 | self.error = None | |
623 | 624 | self.name = self.widget.project.name | |
624 | - | ||
625 | + | ||
625 | 626 | def run(self): | |
626 | 627 | self.widget.send() | |
627 | 628 | self.signals.finished.emit(self.name) | |
… | |||
634 | 635 | self.oldamount = -1 | |
635 | 636 | self.error = None | |
636 | 637 | self.name = self.widget.project.name | |
637 | - | ||
638 | + | ||
638 | 639 | def run(self): | |
639 | - | self.widget.update(self) | |
640 | + | self.widget.update(Interface()) | |
640 | 641 | self.signals.finished.emit(self.name) | |
641 | 642 | ||
642 | 643 | class ExternalRunnable(QRunnable, RunnableCallback): | |
… | |||
647 | 648 | self.oldamount = -1 | |
648 | 649 | self.error = None | |
649 | 650 | self.name = "" | |
650 | - | ||
651 | + | ||
651 | 652 | def run(self): | |
652 | 653 | # Try to open file with the default application | |
653 | 654 | try: | |
… | |||
687 | 688 | files.extend(f) | |
688 | 689 | for f in files: | |
689 | 690 | self.observer.schedule(event_handler, str(Path(f).parent), recursive=True) | |
690 | - | ||
691 | + | ||
691 | 692 | def run(self): | |
692 | 693 | self.observer.start() | |
693 | 694 | while self.size > 0: |
offlate/ui/parallel.py
17 | 17 | from PyQt5.QtCore import * | |
18 | 18 | from ..formats.exception import UnsupportedFormatException | |
19 | 19 | from ..systems.exception import ProjectNotFoundSystemException | |
20 | + | from ..systems.callback import SystemCallback | |
20 | 21 | ||
21 | - | class RunnableCallback: | |
22 | - | def progress(self, amount): | |
22 | + | class RunnableCallback(SystemCallback): | |
23 | + | def reportProgress(self, amount): | |
23 | 24 | if int(round(amount)) > self.oldamount: | |
24 | 25 | self.oldamount = int(round(amount)) | |
25 | 26 | self.signals.progress.emit(self.name, amount) |