# eric7.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.
__generateFormats | Private method to generate the various text formats.
__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.
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_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=None, 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, charFormat, 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)
charFormat
  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.__generateFormats

__generateFormats()

Private method to generate the various text formats.

#### 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.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_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

EricMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

CompareWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### CompareWindow (Constructor)

CompareWindow(files=None, 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)

Return:
  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)

Return:
  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)

Yield:
  tuples of differences. Each 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

Yield Type:
  tuple of (str, str, str, str, str)

Up