2121import os
2222import unicodedata
2323
24+ from typing import Dict
25+
2426from diffuse import utils
2527from diffuse .resources import theResources
2628
27- import gi
29+ import gi # type: ignore
2830gi .require_version ('GObject' , '2.0' )
2931gi .require_version ('Gdk' , '3.0' )
3032gi .require_version ('Gtk' , '3.0' )
3133gi .require_version ('Pango' , '1.0' )
3234gi .require_version ('PangoCairo' , '1.0' )
33- from gi .repository import GObject , Gdk , Gtk , Pango , PangoCairo # noqa: E402
35+ from gi .repository import GObject , Gdk , Gtk , Pango , PangoCairo # type: ignore # noqa: E402
3436
3537
3638# mapping to column width of a character (tab will never be in this map)
37- _char_width_cache = {}
39+ _char_width_cache : Dict [ str , str ] = {}
3840
3941# the file diff viewer is always in one of these modes defining the cursor,
40- # and hotkey behaviour
42+ # and hotkey behavior
4143LINE_MODE = 0
4244CHAR_MODE = 1
4345ALIGN_MODE = 2
@@ -142,7 +144,7 @@ def redraw_region(self, x, y, w, h):
142144
143145
144146# widget used to compare and merge text files
145- class FileDiffViewer (Gtk .Grid ):
147+ class FileDiffViewerBase (Gtk .Grid ):
146148 # class describing a text pane
147149 class Pane :
148150 def __init__ (self ):
@@ -315,7 +317,7 @@ def __init__(self, n, prefs):
315317 self .hadj = Gtk .Adjustment .new (0 , 0 , 0 , 0 , 0 , 0 )
316318 self .vadj = Gtk .Adjustment .new (0 , 0 , 0 , 0 , 0 , 0 )
317319 for i in range (n ):
318- pane = FileDiffViewer .Pane ()
320+ pane = FileDiffViewerBase .Pane ()
319321 self .panes .append (pane )
320322
321323 # pane contents
@@ -712,7 +714,7 @@ def setFormat(self, f, fmt):
712714 pane = self .panes [f ]
713715 if self .undoblock is not None :
714716 # create an Undo object for the action
715- self .addUndo (FileDiffViewer .SetFormatUndo (f , fmt , pane .format ))
717+ self .addUndo (FileDiffViewerBase .SetFormatUndo (f , fmt , pane .format ))
716718 pane .format = fmt
717719 self .emit ('format_changed' , f , fmt )
718720
@@ -734,12 +736,12 @@ def redo(self, viewer):
734736 def instanceLine (self , f , i , reverse = False ):
735737 if self .undoblock is not None :
736738 # create an Undo object for the action
737- self .addUndo (FileDiffViewer .InstanceLineUndo (f , i , reverse ))
739+ self .addUndo (FileDiffViewerBase .InstanceLineUndo (f , i , reverse ))
738740 pane = self .panes [f ]
739741 if reverse :
740742 pane .lines [i ] = None
741743 else :
742- line = FileDiffViewer .Line ()
744+ line = FileDiffViewerBase .Line ()
743745 pane .lines [i ] = line
744746
745747 # Undo for changing the text for a Line object
@@ -774,7 +776,7 @@ def updateLineText(self, f, i, is_modified, text):
774776 flags = self .getMapFlags (f , i )
775777 if self .undoblock is not None :
776778 # create an Undo object for the action
777- self .addUndo (FileDiffViewer .UpdateLineTextUndo (
779+ self .addUndo (FileDiffViewerBase .UpdateLineTextUndo (
778780 f ,
779781 i ,
780782 line .is_modified ,
@@ -835,7 +837,7 @@ def redo(self, viewer):
835837 def insertNull (self , f , i , reverse ):
836838 if self .undoblock is not None :
837839 # create an Undo object for the action
838- self .addUndo (FileDiffViewer .InsertNullUndo (f , i , reverse ))
840+ self .addUndo (FileDiffViewerBase .InsertNullUndo (f , i , reverse ))
839841 pane = self .panes [f ]
840842 lines = pane .lines
841843 # update/invalidate all relevant caches
@@ -866,7 +868,7 @@ def redo(self, viewer):
866868 def invalidateLineMatching (self , i , n , new_n ):
867869 if self .undoblock is not None :
868870 # create an Undo object for the action
869- self .addUndo (FileDiffViewer .InvalidateLineMatchingUndo (i , n , new_n ))
871+ self .addUndo (FileDiffViewerBase .InvalidateLineMatchingUndo (i , n , new_n ))
870872 # update/invalidate all relevant caches and queue widgets for redraw
871873 i2 = i + n
872874 for f , pane in enumerate (self .panes ):
@@ -896,7 +898,7 @@ def redo(self, viewer):
896898 def alignmentChange (self , finished ):
897899 if self .undoblock is not None :
898900 # create an Undo object for the action
899- self .addUndo (FileDiffViewer .AlignmentChangeUndo (finished ))
901+ self .addUndo (FileDiffViewerBase .AlignmentChangeUndo (finished ))
900902 if finished :
901903 self .updateSize (False )
902904
@@ -939,7 +941,7 @@ def redo(self, viewer):
939941 def updateBlocks (self , blocks ):
940942 if self .undoblock is not None :
941943 # create an Undo object for the action
942- self .addUndo (FileDiffViewer .UpdateBlocksUndo (self .blocks , blocks ))
944+ self .addUndo (FileDiffViewerBase .UpdateBlocksUndo (self .blocks , blocks ))
943945 self .blocks = blocks
944946
945947 # insert 'n' blank lines in all panes
@@ -1031,7 +1033,8 @@ def redo(self, viewer):
10311033 def replaceLines (self , f , lines , new_lines , max_num , new_max_num ):
10321034 if self .undoblock is not None :
10331035 # create an Undo object for the action
1034- self .addUndo (FileDiffViewer .ReplaceLinesUndo (f , lines , new_lines , max_num , new_max_num ))
1036+ self .addUndo (FileDiffViewerBase .ReplaceLinesUndo (
1037+ f , lines , new_lines , max_num , new_max_num ))
10351038 pane = self .panes [f ]
10361039 pane .lines = new_lines
10371040 # update/invalidate all relevant caches and queue widgets for redraw
@@ -1198,7 +1201,7 @@ def replaceContents(self, f, ss):
11981201 if n > 0 :
11991202 blocks .append (n )
12001203 # create line objects for the text
1201- Line = FileDiffViewer .Line
1204+ Line = FileDiffViewerBase .Line
12021205 mid = [[Line (j + 1 , ss [j ]) for j in range (n )]]
12031206
12041207 if f > 0 :
@@ -1256,7 +1259,7 @@ def bakeEdits(self, f):
12561259 lines .append (None )
12571260 else :
12581261 line_num += 1
1259- lines .append (FileDiffViewer .Line (line_num , s ))
1262+ lines .append (FileDiffViewerBase .Line (line_num , s ))
12601263
12611264 # update loaded pane
12621265 self .replaceLines (f , pane .lines , lines , pane .max_line_number , line_num )
@@ -1490,7 +1493,7 @@ def redo(self, viewer):
14901493 # selection
14911494 def recordEditMode (self ):
14921495 if self .undoblock is not None :
1493- self .addUndo (FileDiffViewer .EditModeUndo (
1496+ self .addUndo (FileDiffViewerBase .EditModeUndo (
14941497 self .mode ,
14951498 self .current_pane ,
14961499 self .current_line ,
@@ -3243,7 +3246,7 @@ def redo(self, viewer):
32433246 # swap the contents of two panes
32443247 def swapPanes (self , f_dst , f_src ):
32453248 if self .undoblock is not None :
3246- self .addUndo (FileDiffViewer .SwapPanesUndo (f_dst , f_src ))
3249+ self .addUndo (FileDiffViewerBase .SwapPanesUndo (f_dst , f_src ))
32473250 self .current_pane = f_dst
32483251 f0 = self .panes [f_dst ]
32493252 f1 = self .panes [f_src ]
@@ -4128,10 +4131,10 @@ def _pixels(size):
41284131 return int (size / Pango .SCALE + 0.5 )
41294132
41304133
4131- # create 'title_changed' signal for FileDiffViewer
4132- GObject .signal_new ('swapped-panes' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , int )) # noqa: E501
4133- GObject .signal_new ('num-edits-changed' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , )) # noqa: E501
4134- GObject .signal_new ('mode-changed' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , ()) # noqa: E501
4135- GObject .signal_new ('cursor-changed' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , ()) # noqa: E501
4136- GObject .signal_new ('syntax-changed' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (str , )) # noqa: E501
4137- GObject .signal_new ('format-changed' , FileDiffViewer , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , int )) # noqa: E501
4134+ # create 'title_changed' signal for FileDiffViewerBase
4135+ GObject .signal_new ('swapped-panes' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , int )) # noqa: E501
4136+ GObject .signal_new ('num-edits-changed' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , )) # noqa: E501
4137+ GObject .signal_new ('mode-changed' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , ()) # noqa: E501
4138+ GObject .signal_new ('cursor-changed' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , ()) # noqa: E501
4139+ GObject .signal_new ('syntax-changed' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (str , )) # noqa: E501
4140+ GObject .signal_new ('format-changed' , FileDiffViewerBase , GObject .SignalFlags .RUN_LAST , GObject .TYPE_NONE , (int , int )) # noqa: E501
0 commit comments