44 QApplication , QMainWindow , QWidget , QVBoxLayout , QHBoxLayout ,
55 QLabel , QPlainTextEdit , QTextEdit , QPushButton
66)
7- from PySide6 .QtGui import QColor , QTextCursor , QTextFormat
7+ from PySide6 .QtGui import QColor , QColorConstants , QTextCursor , QTextFormat
88from PySide6 .QtCore import Qt , QRect , QSize
99from jinja2 import Environment , TemplateSyntaxError
1010
@@ -56,12 +56,13 @@ def update_line_number_area(self, rect, dy):
5656 def resizeEvent (self , event ):
5757 super ().resizeEvent (event )
5858 cr = self .contentsRect ()
59- self .line_number_area .setGeometry (QRect (cr .left (), cr .top (), self .line_number_area_width (), cr .height ()))
59+ self .line_number_area .setGeometry (QRect (cr .left (), cr .top (),
60+ self .line_number_area_width (), cr .height ()))
6061
6162 def line_number_area_paint_event (self , event ):
6263 from PySide6 .QtGui import QPainter
6364 painter = QPainter (self .line_number_area )
64- painter .fillRect (event .rect (), Qt . lightGray )
65+ painter .fillRect (event .rect (), QColorConstants . LightGray )
6566
6667 block = self .firstVisibleBlock ()
6768 block_number = block .blockNumber ()
@@ -71,10 +72,10 @@ def line_number_area_paint_event(self, event):
7172 while block .isValid () and top <= event .rect ().bottom ():
7273 if block .isVisible () and bottom >= event .rect ().top ():
7374 number = str (block_number + 1 )
74- painter .setPen (Qt . black )
75+ painter .setPen (QColorConstants . Black )
7576 painter .drawText (0 , top , self .line_number_area .width () - 2 ,
7677 self .fontMetrics ().height (),
77- Qt .AlignRight , number )
78+ Qt .AlignmentFlag . AlignRight , number )
7879 block = block .next ()
7980 top = bottom
8081 bottom = top + int (self .blockBoundingRect (block ).height ())
@@ -84,11 +85,11 @@ def highlight_current_line(self):
8485 extra_selections = []
8586 if not self .isReadOnly ():
8687 selection = QTextEdit .ExtraSelection ()
87- line_color = QColor ( Qt . yellow ) .lighter (160 )
88- selection .format .setBackground (line_color )
89- selection .format .setProperty (QTextFormat .FullWidthSelection , True )
90- selection .cursor = self .textCursor ()
91- selection .cursor .clearSelection ()
88+ line_color = QColorConstants . Yellow .lighter (160 )
89+ selection .format .setBackground (line_color ) # type: ignore
90+ selection .format .setProperty (QTextFormat .Property . FullWidthSelection , True ) # type: ignore
91+ selection .cursor = self .textCursor () # type: ignore
92+ selection .cursor .clearSelection () # type: ignore
9293 extra_selections .append (selection )
9394 self .setExtraSelections (extra_selections )
9495
@@ -100,23 +101,24 @@ def highlight_position(self, lineno: int, col: int, color: QColor):
100101 start = block .position () + max (0 , col - 1 )
101102 cursor .setPosition (start )
102103 if col <= len (text ):
103- cursor .movePosition (QTextCursor .NextCharacter , QTextCursor .KeepAnchor )
104+ cursor .movePosition (QTextCursor .MoveOperation .NextCharacter ,
105+ QTextCursor .MoveMode .KeepAnchor )
104106
105107 extra = QTextEdit .ExtraSelection ()
106- extra .format .setBackground (color .lighter (160 ))
107- extra .cursor = cursor
108+ extra .format .setBackground (color .lighter (160 )) # type: ignore
109+ extra .cursor = cursor # type: ignore
108110
109111 self .setExtraSelections (self .extraSelections () + [extra ])
110112
111113 def highlight_line (self , lineno : int , color : QColor ):
112114 block = self .document ().findBlockByLineNumber (lineno - 1 )
113115 if block .isValid ():
114116 cursor = QTextCursor (block )
115- cursor .select (QTextCursor .LineUnderCursor )
117+ cursor .select (QTextCursor .SelectionType . LineUnderCursor )
116118
117119 extra = QTextEdit .ExtraSelection ()
118- extra .format .setBackground (color .lighter (160 ))
119- extra .cursor = cursor
120+ extra .format .setBackground (color .lighter (160 )) # type: ignore
121+ extra .cursor = cursor # type: ignore
120122
121123 self .setExtraSelections (self .extraSelections () + [extra ])
122124
0 commit comments