20 |
20 |
21 from .Ui_CompareDialog import Ui_CompareDialog |
21 from .Ui_CompareDialog import Ui_CompareDialog |
22 |
22 |
23 import Utilities |
23 import Utilities |
24 |
24 |
25 def sbsdiff(a, b, linenumberwidth = 4): |
25 |
|
26 def sbsdiff(a, b, linenumberwidth=4): |
26 """ |
27 """ |
27 Compare two sequences of lines; generate the delta for display side by side. |
28 Compare two sequences of lines; generate the delta for display side by side. |
28 |
29 |
29 @param a first sequence of lines (list of strings) |
30 @param a first sequence of lines (list of strings) |
30 @param b second sequence of lines (list of strings) |
31 @param b second sequence of lines (list of strings) |
69 linenumberformat.format(ln2), removeMarkers(l2)) |
70 linenumberformat.format(ln2), removeMarkers(l2)) |
70 continue |
71 continue |
71 yield ('r', linenumberformat.format(ln1), l1, |
72 yield ('r', linenumberformat.format(ln1), l1, |
72 linenumberformat.format(ln2), l2) |
73 linenumberformat.format(ln2), l2) |
73 |
74 |
|
75 |
74 class CompareDialog(QWidget, Ui_CompareDialog): |
76 class CompareDialog(QWidget, Ui_CompareDialog): |
75 """ |
77 """ |
76 Class implementing a dialog to compare two files and show the result side by side. |
78 Class implementing a dialog to compare two files and show the result side by side. |
77 """ |
79 """ |
78 def __init__(self, files = [], parent = None): |
80 def __init__(self, files=[], parent=None): |
79 """ |
81 """ |
80 Constructor |
82 Constructor |
81 |
83 |
82 @param files list of files to compare and their label |
84 @param files list of files to compare and their label |
83 (list of two tuples of two strings) |
85 (list of two tuples of two strings) |
84 @param parent parent widget (QWidget) |
86 @param parent parent widget (QWidget) |
85 """ |
87 """ |
86 QWidget.__init__(self,parent) |
88 QWidget.__init__(self, parent) |
87 self.setupUi(self) |
89 self.setupUi(self) |
88 |
90 |
89 self.file1Completer = E5FileCompleter(self.file1Edit) |
91 self.file1Completer = E5FileCompleter(self.file1Edit) |
90 self.file2Completer = E5FileCompleter(self.file2Edit) |
92 self.file2Completer = E5FileCompleter(self.file2Edit) |
91 |
93 |
155 QTimer.singleShot(0, self.on_diffButton_clicked) |
157 QTimer.singleShot(0, self.on_diffButton_clicked) |
156 else: |
158 else: |
157 self.file1Label.hide() |
159 self.file1Label.hide() |
158 self.file2Label.hide() |
160 self.file2Label.hide() |
159 |
161 |
160 def show(self, filename = None): |
162 def show(self, filename=None): |
161 """ |
163 """ |
162 Public slot to show the dialog. |
164 Public slot to show the dialog. |
163 |
165 |
164 @param filename name of a file to use as the first file (string) |
166 @param filename name of a file to use as the first file (string) |
165 """ |
167 """ |
166 if filename: |
168 if filename: |
167 self.file1Edit.setText(filename) |
169 self.file1Edit.setText(filename) |
168 QWidget.show(self) |
170 QWidget.show(self) |
169 |
171 |
170 def __appendText(self, pane, linenumber, line, format, interLine = False): |
172 def __appendText(self, pane, linenumber, line, format, interLine=False): |
171 """ |
173 """ |
172 Private method to append text to the end of the contents pane. |
174 Private method to append text to the end of the contents pane. |
173 |
175 |
174 @param pane text edit widget to append text to (QTextedit) |
176 @param pane text edit widget to append text to (QTextedit) |
175 @param linenumber number of line to insert (string) |
177 @param linenumber number of line to insert (string) |
214 """ |
216 """ |
215 Private slot to handle the Compare button press. |
217 Private slot to handle the Compare button press. |
216 """ |
218 """ |
217 filename1 = Utilities.toNativeSeparators(self.file1Edit.text()) |
219 filename1 = Utilities.toNativeSeparators(self.file1Edit.text()) |
218 try: |
220 try: |
219 f1 = open(filename1, "r", encoding = "utf-8") |
221 f1 = open(filename1, "r", encoding="utf-8") |
220 lines1 = f1.readlines() |
222 lines1 = f1.readlines() |
221 f1.close() |
223 f1.close() |
222 except IOError: |
224 except IOError: |
223 E5MessageBox.critical(self, |
225 E5MessageBox.critical(self, |
224 self.trUtf8("Compare Files"), |
226 self.trUtf8("Compare Files"), |
226 .format(filename1)) |
228 .format(filename1)) |
227 return |
229 return |
228 |
230 |
229 filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) |
231 filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) |
230 try: |
232 try: |
231 f2 = open(filename2, "r", encoding = "utf-8") |
233 f2 = open(filename2, "r", encoding="utf-8") |
232 lines2 = f2.readlines() |
234 lines2 = f2.readlines() |
233 f2.close() |
235 f2.close() |
234 except IOError: |
236 except IOError: |
235 E5MessageBox.critical(self, |
237 E5MessageBox.critical(self, |
236 self.trUtf8("Compare Files"), |
238 self.trUtf8("Compare Files"), |
417 self.hsb2.valueChanged.connect(self.hsb1.setValue) |
419 self.hsb2.valueChanged.connect(self.hsb1.setValue) |
418 else: |
420 else: |
419 self.hsb1.valueChanged.disconnect(self.hsb2.setValue) |
421 self.hsb1.valueChanged.disconnect(self.hsb2.setValue) |
420 self.hsb2.valueChanged.disconnect(self.hsb1.setValue) |
422 self.hsb2.valueChanged.disconnect(self.hsb1.setValue) |
421 |
423 |
|
424 |
422 class CompareWindow(QMainWindow): |
425 class CompareWindow(QMainWindow): |
423 """ |
426 """ |
424 Main window class for the standalone dialog. |
427 Main window class for the standalone dialog. |
425 """ |
428 """ |
426 def __init__(self, files = [], parent = None): |
429 def __init__(self, files=[], parent=None): |
427 """ |
430 """ |
428 Constructor |
431 Constructor |
429 |
432 |
430 @param files list of files to compare and their label |
433 @param files list of files to compare and their label |
431 (list of two tuples of two strings) |
434 (list of two tuples of two strings) |
432 @param parent reference to the parent widget (QWidget) |
435 @param parent reference to the parent widget (QWidget) |
433 """ |
436 """ |
434 QMainWindow.__init__(self, parent) |
437 QMainWindow.__init__(self, parent) |
435 self.cw = CompareDialog(files, self) |
438 self.cw = CompareDialog(files, self) |