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