@@ -39,7 +39,7 @@ class ConsolePrEdit(QTextEdit):
3939
4040 # These Qt Properties can be customized using style sheets.
4141 commentColor = QtPropertyInit ('_commentColor' , QColor (0 , 206 , 52 ))
42- errorMessageColor = QtPropertyInit ('_errorMessageColor' , QColor (Qt .red ))
42+ errorMessageColor = QtPropertyInit ('_errorMessageColor' , QColor (Qt .GlobalColor . red ))
4343 keywordColor = QtPropertyInit ('_keywordColor' , QColor (17 , 154 , 255 ))
4444 resultColor = QtPropertyInit ('_resultColor' , QColor (128 , 128 , 128 ))
4545 stdoutColor = QtPropertyInit ('_stdoutColor' , QColor (17 , 154 , 255 ))
@@ -179,15 +179,15 @@ def mousePressEvent(self, event):
179179 self .clickPos = event .pos ()
180180 self .anchor = self .anchorAt (event .pos ())
181181 if self .anchor :
182- QApplication .setOverrideCursor (Qt .PointingHandCursor )
182+ QApplication .setOverrideCursor (Qt .CursorShape . PointingHandCursor )
183183 return super (ConsolePrEdit , self ).mousePressEvent (event )
184184
185185 def mouseReleaseEvent (self , event ):
186186 """Overload of mouseReleaseEvent to capture if user has left clicked... Check if
187187 click position is the same as release position, if so, call errorHyperlink.
188188 """
189189 samePos = event .pos () == self .clickPos
190- left = event .button () == Qt .LeftButton
190+ left = event .button () == Qt .MouseButton . LeftButton
191191 if samePos and left and self .anchor :
192192 self .errorHyperlink ()
193193
@@ -201,7 +201,7 @@ def wheelEvent(self, event):
201201 # scrolling. If used in LoggerWindow, use that wheel event
202202 # May not want to import LoggerWindow, so perhaps
203203 # check by str(type())
204- ctrlPressed = event .modifiers () == Qt .ControlModifier
204+ ctrlPressed = event .modifiers () == Qt .KeyboardModifier . ControlModifier
205205 if ctrlPressed and "LoggerWindow" in str (type (self .window ())):
206206 self .window ().wheelEvent (event )
207207 else :
@@ -211,7 +211,7 @@ def keyReleaseEvent(self, event):
211211 """Override of keyReleaseEvent to determine when to end navigation of
212212 previous commands
213213 """
214- if event .key () == Qt .Key_Alt :
214+ if event .key () == Qt .Key . Key_Alt :
215215 self ._prevCommandIndex = 0
216216 else :
217217 event .ignore ()
@@ -328,7 +328,7 @@ def setCommand(self):
328328 prevCommand = self ._prevCommands [self ._prevCommandIndex ]
329329
330330 cursor = self .textCursor ()
331- cursor .select (QTextCursor .LineUnderCursor )
331+ cursor .select (QTextCursor .SelectionType . LineUnderCursor )
332332 if cursor .selectedText ().startswith (self ._consolePrompt ):
333333 prevCommand = "{}{}" .format (self ._consolePrompt , prevCommand )
334334 cursor .insertText (prevCommand )
@@ -344,20 +344,22 @@ def clearToLastPrompt(self):
344344 currentCursor = self .textCursor ()
345345 # move to the end of the document so we can search backwards
346346 cursor = self .textCursor ()
347- cursor .movePosition (cursor .End )
347+ cursor .movePosition (QTextCursor . MoveOperation .End )
348348 self .setTextCursor (cursor )
349349 # Check if the last line is a empty prompt. If so, then preform two finds so we
350350 # find the prompt we are looking for instead of this empty prompt
351351 findCount = (
352352 2 if self .toPlainText ()[- len (self .prompt ()) :] == self .prompt () else 1
353353 )
354354 for _ in range (findCount ):
355- self .find (self .prompt (), QTextDocument .FindBackward )
355+ self .find (self .prompt (), QTextDocument .FindFlag . FindBackward )
356356 # move to the end of the found line, select the rest of the text and remove it
357357 # preserving history if there is anything to remove.
358358 cursor = self .textCursor ()
359- cursor .movePosition (cursor .EndOfLine )
360- cursor .movePosition (cursor .End , cursor .KeepAnchor )
359+ cursor .movePosition (QTextCursor .MoveOperation .EndOfLine )
360+ cursor .movePosition (
361+ QTextCursor .MoveOperation .End , QTextCursor .MoveMode .KeepAnchor
362+ )
361363 txt = cursor .selectedText ()
362364 if txt :
363365 self .setTextCursor (cursor )
@@ -373,7 +375,7 @@ def executeString(self, commandText, filename='<ConsolePrEdit>', extraPrint=True
373375 if self .clearExecutionTime is not None :
374376 self .clearExecutionTime ()
375377 cursor = self .textCursor ()
376- cursor .select (QTextCursor .BlockUnderCursor )
378+ cursor .select (QTextCursor .SelectionType . BlockUnderCursor )
377379 line = cursor .selectedText ()
378380 if line and line [0 ] not in string .printable :
379381 line = line [1 :]
@@ -481,7 +483,7 @@ def insertCompletion(self, completion):
481483 """inserts the completion text into the editor"""
482484 if self .completer ().widget () == self :
483485 cursor = self .textCursor ()
484- cursor .select (QTextCursor .WordUnderCursor )
486+ cursor .select (QTextCursor .SelectionType . WordUnderCursor )
485487 cursor .insertText (completion )
486488 self .setTextCursor (cursor )
487489
@@ -544,33 +546,33 @@ def keyPressEvent(self, event):
544546 # character, or remove it if backspace or delete has just been pressed.
545547 key = event .text ()
546548 _ , prefix = completer .currentObject (scope = __main__ .__dict__ )
547- isBackspaceOrDel = event .key () in (Qt .Key_Backspace , Qt .Key_Delete )
549+ isBackspaceOrDel = event .key () in (Qt .Key . Key_Backspace , Qt . Key .Key_Delete )
548550 if key .isalnum () or key in ("-" , "_" ):
549551 prefix += str (key )
550552 elif isBackspaceOrDel and prefix :
551553 prefix = prefix [:- 1 ]
552554
553555 if completer and event .key () in (
554- Qt .Key_Backspace ,
555- Qt .Key_Delete ,
556- Qt .Key_Escape ,
556+ Qt .Key . Key_Backspace ,
557+ Qt .Key . Key_Delete ,
558+ Qt .Key . Key_Escape ,
557559 ):
558560 completer .hideDocumentation ()
559561
560562 # enter || return keys will execute the command
561- if event .key () in (Qt .Key_Return , Qt .Key_Enter ):
563+ if event .key () in (Qt .Key . Key_Return , Qt . Key .Key_Enter ):
562564 if completer .popup ().isVisible ():
563565 completer .clear ()
564566 event .ignore ()
565567 else :
566568 self .executeCommand ()
567569
568570 # home key will move the cursor to home
569- elif event .key () == Qt .Key_Home :
571+ elif event .key () == Qt .Key . Key_Home :
570572 self .moveToHome ()
571573
572574 # otherwise, ignore the event for completion events
573- elif event .key () in (Qt .Key_Tab , Qt .Key_Backtab ):
575+ elif event .key () in (Qt .Key . Key_Tab , Qt . Key .Key_Backtab ):
574576 if not completer .popup ().isVisible ():
575577 # The completer does not get updated if its not visible while typing.
576578 # We are about to complete the text using it so ensure its updated.
@@ -580,19 +582,28 @@ def keyPressEvent(self, event):
580582 )
581583 # Insert the correct text and clear the completion model
582584 index = completer .popup ().currentIndex ()
583- self .insertCompletion (index .data (Qt .DisplayRole ))
585+ self .insertCompletion (index .data (Qt .ItemDataRole . DisplayRole ))
584586 completer .clear ()
585587
586- elif event .key () == Qt .Key_Escape and completer .popup ().isVisible ():
588+ elif event .key () == Qt .Key . Key_Escape and completer .popup ().isVisible ():
587589 completer .clear ()
588590
589591 # other wise handle the keypress
590592 else :
591593 # define special key sequences
592594 modifiers = QApplication .instance ().keyboardModifiers ()
593- ctrlSpace = event .key () == Qt .Key_Space and modifiers == Qt .ControlModifier
594- ctrlM = event .key () == Qt .Key_M and modifiers == Qt .ControlModifier
595- ctrlI = event .key () == Qt .Key_I and modifiers == Qt .ControlModifier
595+ ctrlSpace = (
596+ event .key () == Qt .Key .Key_Space
597+ and modifiers == Qt .KeyboardModifier .ControlModifier
598+ )
599+ ctrlM = (
600+ event .key () == Qt .Key .Key_M
601+ and modifiers == Qt .KeyboardModifier .ControlModifier
602+ )
603+ ctrlI = (
604+ event .key () == Qt .Key .Key_I
605+ and modifiers == Qt .KeyboardModifier .ControlModifier
606+ )
596607
597608 # Process all events we do not want to override
598609 if not (ctrlSpace or ctrlM or ctrlI ):
@@ -611,20 +622,20 @@ def keyPressEvent(self, event):
611622 # check for particular events for the completion
612623 if completer :
613624 # look for documentation popups
614- if event .key () == Qt .Key_ParenLeft :
625+ if event .key () == Qt .Key . Key_ParenLeft :
615626 rect = self .cursorRect ()
616627 point = self .mapToGlobal (QPoint (rect .x (), rect .y ()))
617628 completer .showDocumentation (pos = point , scope = __main__ .__dict__ )
618629
619630 # hide documentation popups
620- elif event .key () == Qt .Key_ParenRight :
631+ elif event .key () == Qt .Key . Key_ParenRight :
621632 completer .hideDocumentation ()
622633
623634 # determine if we need to show the popup or if it already is visible, we
624635 # need to update it
625636 elif (
626- event .key () == Qt .Key_Period
627- or event .key () == Qt .Key_Escape
637+ event .key () == Qt .Key . Key_Period
638+ or event .key () == Qt .Key . Key_Escape
628639 or completer .popup ().isVisible ()
629640 or ctrlSpace
630641 or ctrlI
@@ -655,7 +666,9 @@ def keyPressEvent(self, event):
655666 completer .setCurrentRow (index .row ())
656667
657668 # Make sure that current selection is visible, ie scroll to it
658- completer .popup ().scrollTo (index , QAbstractItemView .EnsureVisible )
669+ completer .popup ().scrollTo (
670+ index , QAbstractItemView .ScrollHint .EnsureVisible
671+ )
659672
660673 # show the completer for the rect
661674 rect = self .cursorRect ()
@@ -672,28 +685,34 @@ def keyPressEvent(self, event):
672685 if completer .wasCompleting and not completer .popup ().isVisible ():
673686 wasCompletingCounterMax = completer .wasCompletingCounterMax
674687 if completer .wasCompletingCounter <= wasCompletingCounterMax :
675- if event .key () not in (Qt .Key_Backspace , Qt .Key_Left ):
688+ if event .key () not in (Qt .Key . Key_Backspace , Qt . Key .Key_Left ):
676689 completer .wasCompletingCounter += 1
677690 else :
678691 completer .wasCompletingCounter = 0
679692 completer .wasCompleting = False
680693
681694 def moveToHome (self ):
682695 """moves the cursor to the home location"""
683- mode = QTextCursor .MoveAnchor
696+ mode = QTextCursor .MoveMode . MoveAnchor
684697 # select the home
685- if QApplication .instance ().keyboardModifiers () == Qt .ShiftModifier :
686- mode = QTextCursor .KeepAnchor
698+ if (
699+ QApplication .instance ().keyboardModifiers ()
700+ == Qt .KeyboardModifier .ShiftModifier
701+ ):
702+ mode = QTextCursor .MoveMode .KeepAnchor
687703 # grab the cursor
688704 cursor = self .textCursor ()
689- if QApplication .instance ().keyboardModifiers () == Qt .ControlModifier :
705+ if (
706+ QApplication .instance ().keyboardModifiers ()
707+ == Qt .KeyboardModifier .ControlModifier
708+ ):
690709 # move to the top of the document if control is pressed
691- cursor .movePosition (QTextCursor .Start )
710+ cursor .movePosition (QTextCursor .MoveOperation . Start )
692711 else :
693712 # Otherwise just move it to the start of the line
694- cursor .movePosition (QTextCursor .StartOfBlock , mode )
713+ cursor .movePosition (QTextCursor .MoveOperation . StartOfBlock , mode )
695714 # move the cursor to the end of the prompt.
696- cursor .movePosition (QTextCursor .Right , mode , len (self .prompt ()))
715+ cursor .movePosition (QTextCursor .MoveOperation . Right , mode , len (self .prompt ()))
697716 self .setTextCursor (cursor )
698717
699718 def outputPrompt (self ):
@@ -730,7 +749,7 @@ def startPrompt(self, prompt):
730749 prompt(str): The prompt to start the line with. If this prompt
731750 is already the only text on the last line this function does nothing.
732751 """
733- self .moveCursor (QTextCursor .End )
752+ self .moveCursor (QTextCursor .MoveOperation . End )
734753
735754 # if this is not already a new line
736755 if self .textCursor ().block ().text () != prompt :
@@ -753,9 +772,11 @@ def startOutputLine(self):
753772 self .startPrompt (self ._outputPrompt )
754773
755774 def removeCurrentLine (self ):
756- self .moveCursor (QTextCursor .End , QTextCursor .MoveAnchor )
757- self .moveCursor (QTextCursor .StartOfLine , QTextCursor .MoveAnchor )
758- self .moveCursor (QTextCursor .End , QTextCursor .KeepAnchor )
775+ self .moveCursor (QTextCursor .MoveOperation .End , QTextCursor .MoveMode .MoveAnchor )
776+ self .moveCursor (
777+ QTextCursor .MoveOperation .StartOfLine , QTextCursor .MoveMode .MoveAnchor
778+ )
779+ self .moveCursor (QTextCursor .MoveOperation .End , QTextCursor .MoveMode .KeepAnchor )
759780 self .textCursor ().removeSelectedText ()
760781 self .textCursor ().deletePreviousChar ()
761782 self .insertPlainText ("\n " )
@@ -796,7 +817,7 @@ def write(self, msg, error=False):
796817 hasattr (window , 'uiErrorHyperlinksACT' )
797818 and window .uiErrorHyperlinksACT .isChecked ()
798819 )
799- self .moveCursor (QTextCursor .End )
820+ self .moveCursor (QTextCursor .MoveOperation . End )
800821
801822 charFormat = QTextCharFormat ()
802823 if not error :
@@ -815,7 +836,7 @@ def write(self, msg, error=False):
815836 info = None
816837
817838 if doHyperlink and msg == '\n ' :
818- cursor .select (QTextCursor .BlockUnderCursor )
839+ cursor .select (QTextCursor .SelectionType . BlockUnderCursor )
819840 line = cursor .selectedText ()
820841
821842 # Remove possible leading unicode paragraph separator, which really
0 commit comments