|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
|
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> |
|
4 <html><head> |
|
5 <title>eric4.UI.DiffDialog</title> |
|
6 <style> |
|
7 body { |
|
8 background:white; |
|
9 margin: 0em 1em 10em 1em; |
|
10 color: black; |
|
11 } |
|
12 |
|
13 h1 { color: white; background: #4FA4FF; } |
|
14 h2 { color: white; background: #4FA4FF; } |
|
15 h3 { color: white; background: #00557F; } |
|
16 h4 { color: white; background: #00557F; } |
|
17 |
|
18 a { color: #AA5500; } |
|
19 |
|
20 </style> |
|
21 </head> |
|
22 <body><a NAME="top" ID="top"></a> |
|
23 <h1>eric4.UI.DiffDialog</h1> |
|
24 <p> |
|
25 Module implementing a dialog to compare two files. |
|
26 </p> |
|
27 <h3>Global Attributes</h3> |
|
28 <table> |
|
29 <tr><td>None</td></tr> |
|
30 </table> |
|
31 <h3>Classes</h3> |
|
32 <table> |
|
33 <tr> |
|
34 <td><a href="#DiffDialog">DiffDialog</a></td> |
|
35 <td>Class implementing a dialog to compare two files.</td> |
|
36 </tr><tr> |
|
37 <td><a href="#DiffWindow">DiffWindow</a></td> |
|
38 <td>Main window class for the standalone dialog.</td> |
|
39 </tr> |
|
40 </table> |
|
41 <h3>Functions</h3> |
|
42 <table> |
|
43 <tr> |
|
44 <td><a href="#context_diff">context_diff</a></td> |
|
45 <td>Compare two sequences of lines; generate the delta as a context diff.</td> |
|
46 </tr><tr> |
|
47 <td><a href="#unified_diff">unified_diff</a></td> |
|
48 <td>Compare two sequences of lines; generate the delta as a unified diff.</td> |
|
49 </tr> |
|
50 </table> |
|
51 <hr /><hr /> |
|
52 <a NAME="DiffDialog" ID="DiffDialog"></a> |
|
53 <h2>DiffDialog</h2> |
|
54 <p> |
|
55 Class implementing a dialog to compare two files. |
|
56 </p> |
|
57 <h3>Derived from</h3> |
|
58 QWidget, Ui_DiffDialog |
|
59 <h3>Class Attributes</h3> |
|
60 <table> |
|
61 <tr><td>None</td></tr> |
|
62 </table> |
|
63 <h3>Methods</h3> |
|
64 <table> |
|
65 <tr> |
|
66 <td><a href="#DiffDialog.__init__">DiffDialog</a></td> |
|
67 <td>Constructor</td> |
|
68 </tr><tr> |
|
69 <td><a href="#DiffDialog.__appendText">__appendText</a></td> |
|
70 <td>Private method to append text to the end of the contents pane.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#DiffDialog.__fileChanged">__fileChanged</a></td> |
|
73 <td>Private slot to enable/disable the Compare button.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#DiffDialog.__generateContextDiff">__generateContextDiff</a></td> |
|
76 <td>Private slot to generate a context diff output.</td> |
|
77 </tr><tr> |
|
78 <td><a href="#DiffDialog.__generateUnifiedDiff">__generateUnifiedDiff</a></td> |
|
79 <td>Private slot to generate a unified diff output.</td> |
|
80 </tr><tr> |
|
81 <td><a href="#DiffDialog.__selectFile">__selectFile</a></td> |
|
82 <td>Private slot to display a file selection dialog.</td> |
|
83 </tr><tr> |
|
84 <td><a href="#DiffDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> |
|
85 <td>Private slot called by a button of the button box clicked.</td> |
|
86 </tr><tr> |
|
87 <td><a href="#DiffDialog.on_diffButton_clicked">on_diffButton_clicked</a></td> |
|
88 <td>Private slot to handle the Compare button press.</td> |
|
89 </tr><tr> |
|
90 <td><a href="#DiffDialog.on_file1Button_clicked">on_file1Button_clicked</a></td> |
|
91 <td>Private slot to handle the file 1 file selection button press.</td> |
|
92 </tr><tr> |
|
93 <td><a href="#DiffDialog.on_file2Button_clicked">on_file2Button_clicked</a></td> |
|
94 <td>Private slot to handle the file 2 file selection button press.</td> |
|
95 </tr><tr> |
|
96 <td><a href="#DiffDialog.on_saveButton_clicked">on_saveButton_clicked</a></td> |
|
97 <td>Private slot to handle the Save button press.</td> |
|
98 </tr><tr> |
|
99 <td><a href="#DiffDialog.show">show</a></td> |
|
100 <td>Public slot to show the dialog.</td> |
|
101 </tr> |
|
102 </table> |
|
103 <a NAME="DiffDialog.__init__" ID="DiffDialog.__init__"></a> |
|
104 <h4>DiffDialog (Constructor)</h4> |
|
105 <b>DiffDialog</b>(<i>parent = None</i>) |
|
106 <p> |
|
107 Constructor |
|
108 </p><a NAME="DiffDialog.__appendText" ID="DiffDialog.__appendText"></a> |
|
109 <h4>DiffDialog.__appendText</h4> |
|
110 <b>__appendText</b>(<i>txt, format</i>) |
|
111 <p> |
|
112 Private method to append text to the end of the contents pane. |
|
113 </p><dl> |
|
114 <dt><i>txt</i></dt> |
|
115 <dd> |
|
116 text to insert (string) |
|
117 </dd><dt><i>format</i></dt> |
|
118 <dd> |
|
119 text format to be used (QTextCharFormat) |
|
120 </dd> |
|
121 </dl><a NAME="DiffDialog.__fileChanged" ID="DiffDialog.__fileChanged"></a> |
|
122 <h4>DiffDialog.__fileChanged</h4> |
|
123 <b>__fileChanged</b>(<i></i>) |
|
124 <p> |
|
125 Private slot to enable/disable the Compare button. |
|
126 </p><a NAME="DiffDialog.__generateContextDiff" ID="DiffDialog.__generateContextDiff"></a> |
|
127 <h4>DiffDialog.__generateContextDiff</h4> |
|
128 <b>__generateContextDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
|
129 <p> |
|
130 Private slot to generate a context diff output. |
|
131 </p><dl> |
|
132 <dt><i>a</i></dt> |
|
133 <dd> |
|
134 first sequence of lines (list of strings) |
|
135 </dd><dt><i>b</i></dt> |
|
136 <dd> |
|
137 second sequence of lines (list of strings) |
|
138 </dd><dt><i>fromfile</i></dt> |
|
139 <dd> |
|
140 filename of the first file (string) |
|
141 </dd><dt><i>tofile</i></dt> |
|
142 <dd> |
|
143 filename of the second file (string) |
|
144 </dd><dt><i>fromfiledate</i></dt> |
|
145 <dd> |
|
146 modification time of the first file (string) |
|
147 </dd><dt><i>tofiledate</i></dt> |
|
148 <dd> |
|
149 modification time of the second file (string) |
|
150 </dd> |
|
151 </dl><a NAME="DiffDialog.__generateUnifiedDiff" ID="DiffDialog.__generateUnifiedDiff"></a> |
|
152 <h4>DiffDialog.__generateUnifiedDiff</h4> |
|
153 <b>__generateUnifiedDiff</b>(<i>a, b, fromfile, tofile, fromfiledate, tofiledate</i>) |
|
154 <p> |
|
155 Private slot to generate a unified diff output. |
|
156 </p><dl> |
|
157 <dt><i>a</i></dt> |
|
158 <dd> |
|
159 first sequence of lines (list of strings) |
|
160 </dd><dt><i>b</i></dt> |
|
161 <dd> |
|
162 second sequence of lines (list of strings) |
|
163 </dd><dt><i>fromfile</i></dt> |
|
164 <dd> |
|
165 filename of the first file (string) |
|
166 </dd><dt><i>tofile</i></dt> |
|
167 <dd> |
|
168 filename of the second file (string) |
|
169 </dd><dt><i>fromfiledate</i></dt> |
|
170 <dd> |
|
171 modification time of the first file (string) |
|
172 </dd><dt><i>tofiledate</i></dt> |
|
173 <dd> |
|
174 modification time of the second file (string) |
|
175 </dd> |
|
176 </dl><a NAME="DiffDialog.__selectFile" ID="DiffDialog.__selectFile"></a> |
|
177 <h4>DiffDialog.__selectFile</h4> |
|
178 <b>__selectFile</b>(<i>lineEdit</i>) |
|
179 <p> |
|
180 Private slot to display a file selection dialog. |
|
181 </p><dl> |
|
182 <dt><i>lineEdit</i></dt> |
|
183 <dd> |
|
184 field for the display of the selected filename |
|
185 (QLineEdit) |
|
186 </dd> |
|
187 </dl><a NAME="DiffDialog.on_buttonBox_clicked" ID="DiffDialog.on_buttonBox_clicked"></a> |
|
188 <h4>DiffDialog.on_buttonBox_clicked</h4> |
|
189 <b>on_buttonBox_clicked</b>(<i>button</i>) |
|
190 <p> |
|
191 Private slot called by a button of the button box clicked. |
|
192 </p><dl> |
|
193 <dt><i>button</i></dt> |
|
194 <dd> |
|
195 button that was clicked (QAbstractButton) |
|
196 </dd> |
|
197 </dl><a NAME="DiffDialog.on_diffButton_clicked" ID="DiffDialog.on_diffButton_clicked"></a> |
|
198 <h4>DiffDialog.on_diffButton_clicked</h4> |
|
199 <b>on_diffButton_clicked</b>(<i></i>) |
|
200 <p> |
|
201 Private slot to handle the Compare button press. |
|
202 </p><a NAME="DiffDialog.on_file1Button_clicked" ID="DiffDialog.on_file1Button_clicked"></a> |
|
203 <h4>DiffDialog.on_file1Button_clicked</h4> |
|
204 <b>on_file1Button_clicked</b>(<i></i>) |
|
205 <p> |
|
206 Private slot to handle the file 1 file selection button press. |
|
207 </p><a NAME="DiffDialog.on_file2Button_clicked" ID="DiffDialog.on_file2Button_clicked"></a> |
|
208 <h4>DiffDialog.on_file2Button_clicked</h4> |
|
209 <b>on_file2Button_clicked</b>(<i></i>) |
|
210 <p> |
|
211 Private slot to handle the file 2 file selection button press. |
|
212 </p><a NAME="DiffDialog.on_saveButton_clicked" ID="DiffDialog.on_saveButton_clicked"></a> |
|
213 <h4>DiffDialog.on_saveButton_clicked</h4> |
|
214 <b>on_saveButton_clicked</b>(<i></i>) |
|
215 <p> |
|
216 Private slot to handle the Save button press. |
|
217 </p><p> |
|
218 It saves the diff shown in the dialog to a file in the local |
|
219 filesystem. |
|
220 </p><a NAME="DiffDialog.show" ID="DiffDialog.show"></a> |
|
221 <h4>DiffDialog.show</h4> |
|
222 <b>show</b>(<i>filename = None</i>) |
|
223 <p> |
|
224 Public slot to show the dialog. |
|
225 </p><dl> |
|
226 <dt><i>filename</i></dt> |
|
227 <dd> |
|
228 name of a file to use as the first file (string) |
|
229 </dd> |
|
230 </dl> |
|
231 <div align="right"><a href="#top">Up</a></div> |
|
232 <hr /><hr /> |
|
233 <a NAME="DiffWindow" ID="DiffWindow"></a> |
|
234 <h2>DiffWindow</h2> |
|
235 <p> |
|
236 Main window class for the standalone dialog. |
|
237 </p> |
|
238 <h3>Derived from</h3> |
|
239 QMainWindow |
|
240 <h3>Class Attributes</h3> |
|
241 <table> |
|
242 <tr><td>None</td></tr> |
|
243 </table> |
|
244 <h3>Methods</h3> |
|
245 <table> |
|
246 <tr> |
|
247 <td><a href="#DiffWindow.__init__">DiffWindow</a></td> |
|
248 <td>Constructor</td> |
|
249 </tr><tr> |
|
250 <td><a href="#DiffWindow.eventFilter">eventFilter</a></td> |
|
251 <td>Public method to filter events.</td> |
|
252 </tr> |
|
253 </table> |
|
254 <a NAME="DiffWindow.__init__" ID="DiffWindow.__init__"></a> |
|
255 <h4>DiffWindow (Constructor)</h4> |
|
256 <b>DiffWindow</b>(<i>parent = None</i>) |
|
257 <p> |
|
258 Constructor |
|
259 </p><dl> |
|
260 <dt><i>parent</i></dt> |
|
261 <dd> |
|
262 reference to the parent widget (QWidget) |
|
263 </dd> |
|
264 </dl><a NAME="DiffWindow.eventFilter" ID="DiffWindow.eventFilter"></a> |
|
265 <h4>DiffWindow.eventFilter</h4> |
|
266 <b>eventFilter</b>(<i>obj, event</i>) |
|
267 <p> |
|
268 Public method to filter events. |
|
269 </p><dl> |
|
270 <dt><i>obj</i></dt> |
|
271 <dd> |
|
272 reference to the object the event is meant for (QObject) |
|
273 </dd><dt><i>event</i></dt> |
|
274 <dd> |
|
275 reference to the event object (QEvent) |
|
276 </dd> |
|
277 </dl><dl> |
|
278 <dt>Returns:</dt> |
|
279 <dd> |
|
280 flag indicating, whether the event was handled (boolean) |
|
281 </dd> |
|
282 </dl> |
|
283 <div align="right"><a href="#top">Up</a></div> |
|
284 <hr /><hr /> |
|
285 <a NAME="context_diff" ID="context_diff"></a> |
|
286 <h2>context_diff</h2> |
|
287 <b>context_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
|
288 <p> |
|
289 Compare two sequences of lines; generate the delta as a context diff. |
|
290 </p><p> |
|
291 Context diffs are a compact way of showing line changes and a few |
|
292 lines of context. The number of context lines is set by 'n' which |
|
293 defaults to three. |
|
294 </p><p> |
|
295 By default, the diff control lines (those with *** or ---) are |
|
296 created with a trailing newline. This is helpful so that inputs |
|
297 created from file.readlines() result in diffs that are suitable for |
|
298 file.writelines() since both the inputs and outputs have trailing |
|
299 newlines. |
|
300 </p><p> |
|
301 For inputs that do not have trailing newlines, set the lineterm |
|
302 argument to "" so that the output will be uniformly newline free. |
|
303 </p><p> |
|
304 The context diff format normally has a header for filenames and |
|
305 modification times. Any or all of these may be specified using |
|
306 strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. |
|
307 The modification times are normally expressed in the format returned |
|
308 by time.ctime(). If not specified, the strings default to blanks. |
|
309 </p><p> |
|
310 Example: |
|
311 </p><p> |
|
312 <pre> |
|
313 >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), |
|
314 ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', |
|
315 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), |
|
316 *** Original Sat Jan 26 23:30:50 1991 |
|
317 --- Current Fri Jun 06 10:22:46 2003 |
|
318 *************** |
|
319 *** 1,4 **** |
|
320 one |
|
321 ! two |
|
322 ! three |
|
323 four |
|
324 --- 1,4 ---- |
|
325 + zero |
|
326 one |
|
327 ! tree |
|
328 four |
|
329 </pre> |
|
330 </p><dl> |
|
331 <dt><i>a</i></dt> |
|
332 <dd> |
|
333 first sequence of lines (list of strings) |
|
334 </dd><dt><i>b</i></dt> |
|
335 <dd> |
|
336 second sequence of lines (list of strings) |
|
337 </dd><dt><i>fromfile</i></dt> |
|
338 <dd> |
|
339 filename of the first file (string) |
|
340 </dd><dt><i>tofile</i></dt> |
|
341 <dd> |
|
342 filename of the second file (string) |
|
343 </dd><dt><i>fromfiledate</i></dt> |
|
344 <dd> |
|
345 modification time of the first file (string) |
|
346 </dd><dt><i>tofiledate</i></dt> |
|
347 <dd> |
|
348 modification time of the second file (string) |
|
349 </dd><dt><i>n</i></dt> |
|
350 <dd> |
|
351 number of lines of context (integer) |
|
352 </dd><dt><i>lineterm</i></dt> |
|
353 <dd> |
|
354 line termination string (string) |
|
355 </dd> |
|
356 </dl><dl> |
|
357 <dt>Returns:</dt> |
|
358 <dd> |
|
359 a generator yielding lines of differences |
|
360 </dd> |
|
361 </dl> |
|
362 <div align="right"><a href="#top">Up</a></div> |
|
363 <hr /><hr /> |
|
364 <a NAME="unified_diff" ID="unified_diff"></a> |
|
365 <h2>unified_diff</h2> |
|
366 <b>unified_diff</b>(<i>a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'</i>) |
|
367 <p> |
|
368 Compare two sequences of lines; generate the delta as a unified diff. |
|
369 </p><p> |
|
370 Unified diffs are a compact way of showing line changes and a few |
|
371 lines of context. The number of context lines is set by 'n' which |
|
372 defaults to three. |
|
373 </p><p> |
|
374 By default, the diff control lines (those with ---, +++, or @@) are |
|
375 created with a trailing newline. This is helpful so that inputs |
|
376 created from file.readlines() result in diffs that are suitable for |
|
377 file.writelines() since both the inputs and outputs have trailing |
|
378 newlines. |
|
379 </p><p> |
|
380 For inputs that do not have trailing newlines, set the lineterm |
|
381 argument to "" so that the output will be uniformly newline free. |
|
382 </p><p> |
|
383 The unidiff format normally has a header for filenames and modification |
|
384 times. Any or all of these may be specified using strings for |
|
385 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification |
|
386 times are normally expressed in the format returned by time.ctime(). |
|
387 </p><p> |
|
388 Example: |
|
389 </p><p> |
|
390 <pre> |
|
391 >>> for line in unified_diff('one two three four'.split(), |
|
392 ... 'zero one tree four'.split(), 'Original', 'Current', |
|
393 ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003', |
|
394 ... lineterm=''): |
|
395 ... print line |
|
396 --- Original Sat Jan 26 23:30:50 1991 |
|
397 +++ Current Fri Jun 06 10:20:52 2003 |
|
398 @ -1,4 +1,4 @@ |
|
399 +zero |
|
400 one |
|
401 -two |
|
402 -three |
|
403 +tree |
|
404 four |
|
405 </pre> |
|
406 </p><dl> |
|
407 <dt><i>a</i></dt> |
|
408 <dd> |
|
409 first sequence of lines (list of strings) |
|
410 </dd><dt><i>b</i></dt> |
|
411 <dd> |
|
412 second sequence of lines (list of strings) |
|
413 </dd><dt><i>fromfile</i></dt> |
|
414 <dd> |
|
415 filename of the first file (string) |
|
416 </dd><dt><i>tofile</i></dt> |
|
417 <dd> |
|
418 filename of the second file (string) |
|
419 </dd><dt><i>fromfiledate</i></dt> |
|
420 <dd> |
|
421 modification time of the first file (string) |
|
422 </dd><dt><i>tofiledate</i></dt> |
|
423 <dd> |
|
424 modification time of the second file (string) |
|
425 </dd><dt><i>n</i></dt> |
|
426 <dd> |
|
427 number of lines of context (integer) |
|
428 </dd><dt><i>lineterm</i></dt> |
|
429 <dd> |
|
430 line termination string (string) |
|
431 </dd> |
|
432 </dl><dl> |
|
433 <dt>Returns:</dt> |
|
434 <dd> |
|
435 a generator yielding lines of differences |
|
436 </dd> |
|
437 </dl> |
|
438 <div align="right"><a href="#top">Up</a></div> |
|
439 <hr /> |
|
440 </body></html> |