# eric6.UI.CompareDialog

Module implementing a dialog to compare two files and show the result side by side.

### Global Attributes

None

### Classes

CompareDialog | Class implementing a dialog to compare two files and show the result side by side.
CompareWindow | Main window class for the standalone dialog.

### Functions

removeMarkers | Internal function to remove all diff markers.
sbsdiff | Compare two sequences of lines; generate the delta for display side by side.

## CompareDialog

Class implementing a dialog to compare two files and show the result side by side.

### Derived from

QWidget, Ui_CompareDialog

### Class Attributes

None

### Class Methods

None

### Methods

CompareDialog | Constructor
__appendText | Private method to append text to the end of the contents pane.
__compare | Private method to compare two lists of text.
__fileChanged | Private slot to enable/disable the Compare button.
__moveTextToCurrentDiffPos | Private slot to move the text display to the current diff position.
__scrollBarMoved | Private slot to enable the buttons and set the current diff position depending on scrollbar position.
__selectFile | Private slot to display a file selection dialog.
compare | Public method to compare two lists of text.
on_buttonBox_clicked | Private slot called by a button of the button box clicked.
on_diffButton_clicked | Private slot to handle the Compare button press.
on_downButton_clicked | Private slot to go to the next difference.
on_file1Button_clicked | Private slot to handle the file 1 file selection button press.
on_file2Button_clicked | Private slot to handle the file 2 file selection button press.
on_firstButton_clicked | Private slot to go to the first difference.
on_lastButton_clicked | Private slot to go to the last difference.
on_synchronizeCheckBox_toggled | Private slot to connect or disconnect the scrollbars of the displays.
on_upButton_clicked | Private slot to go to the previous difference.
show | Public slot to show the dialog.

### Static Methods

None

#### CompareDialog (Constructor)

CompareDialog(files=[], parent=None)

Constructor

files
  list of files to compare and their label (list of two tuples of two strings)
parent
  parent widget (QWidget)

#### CompareDialog.__appendText

__appendText(pane, linenumber, line, format, interLine=False)

Private method to append text to the end of the contents pane.

pane
  text edit widget to append text to (QTextedit)
linenumber
  number of line to insert (string)
line
  text to insert (string)
format
  text format to be used (QTextCharFormat)
interLine
  flag indicating interline changes (boolean)

#### CompareDialog.__compare

__compare(lines1, lines2)

Private method to compare two lists of text.

lines1
  text to compare against (list of strings)
lines2
  text to compare (list of strings)

#### CompareDialog.__fileChanged

__fileChanged()

Private slot to enable/disable the Compare button.

#### CompareDialog.__moveTextToCurrentDiffPos

__moveTextToCurrentDiffPos()

Private slot to move the text display to the current diff position.

#### CompareDialog.__scrollBarMoved

__scrollBarMoved(value)

Private slot to enable the buttons and set the current diff position depending on scrollbar position.

value
  scrollbar position (integer)

#### CompareDialog.__selectFile

__selectFile(lineEdit)

Private slot to display a file selection dialog.

lineEdit
  field for the display of the selected filename (QLineEdit)

#### CompareDialog.compare

compare(lines1, lines2, name1="", name2="")

Public method to compare two lists of text.

lines1
  text to compare against (string or list of strings)
lines2
  text to compare (string or list of strings)
name1=
  name to be shown for the first text (string)
name2=
  name to be shown for the second text (string)

#### CompareDialog.on_buttonBox_clicked

on_buttonBox_clicked(button)

Private slot called by a button of the button box clicked.

button
  button that was clicked (QAbstractButton)

#### CompareDialog.on_diffButton_clicked

on_diffButton_clicked()

Private slot to handle the Compare button press.

#### CompareDialog.on_downButton_clicked

on_downButton_clicked()

Private slot to go to the next difference.

#### CompareDialog.on_file1Button_clicked

on_file1Button_clicked()

Private slot to handle the file 1 file selection button press.

#### CompareDialog.on_file2Button_clicked

on_file2Button_clicked()

Private slot to handle the file 2 file selection button press.

#### CompareDialog.on_firstButton_clicked

on_firstButton_clicked()

Private slot to go to the first difference.

#### CompareDialog.on_lastButton_clicked

on_lastButton_clicked()

Private slot to go to the last difference.

#### CompareDialog.on_synchronizeCheckBox_toggled

on_synchronizeCheckBox_toggled(sync)

Private slot to connect or disconnect the scrollbars of the displays.

sync
  flag indicating synchronisation status (boolean)

#### CompareDialog.on_upButton_clicked

on_upButton_clicked()

Private slot to go to the previous difference.

#### CompareDialog.show

show(filename=None)

Public slot to show the dialog.

filename
  name of a file to use as the first file (string)

Up

## CompareWindow

Main window class for the standalone dialog.

### Derived from

E5MainWindow

### Class Attributes

None

### Class Methods

None

### Methods

CompareWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### CompareWindow (Constructor)

CompareWindow(files=[], parent=None)

Constructor

files
  list of files to compare and their label (list of two tuples of two strings)
parent
  reference to the parent widget (QWidget)

#### CompareWindow.eventFilter

eventFilter(obj, event)

Public method to filter events.

obj
  reference to the object the event is meant for (QObject)
event
  reference to the event object (QEvent)

Returns:
  flag indicating, whether the event was handled (boolean)

Up

## removeMarkers

removeMarkers(line)

Internal function to remove all diff markers.

line
  line to work on (string)

Returns:
  line without diff markers (string)

Up

## sbsdiff

sbsdiff(a, b, linenumberwidth=4)

Compare two sequences of lines; generate the delta for display side by side.

a
  first sequence of lines (list of strings)
b
  second sequence of lines (list of strings)
linenumberwidth
  width (in characters) of the linenumbers (integer)

Returns:
  a generator yielding tuples of differences. The tuple is composed of strings as follows.
  - opcode -- one of e, d, i, r for equal, delete, insert, replace
  - lineno a -- linenumber of sequence a
  - line a -- line of sequence a
  - lineno b -- linenumber of sequence b
  - line b -- line of sequence b

Up