@@ -36,7 +36,7 @@ class ConsolePrEdit(QTextEdit):
3636 # Ensure the error prompt only shows up once.
3737 _errorPrompted = False
3838 # the color error messages are displayed in, can be set by stylesheets
39- _errorMessageColor = QColor (Qt .red )
39+ _errorMessageColor = QColor (Qt .GlobalColor . red )
4040
4141 def __init__ (self , parent ):
4242 super (ConsolePrEdit , self ).__init__ (parent )
@@ -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 )
@@ -391,7 +393,7 @@ def executeString(self, commandText, filename='<ConsolePrEdit>', extraPrint=True
391393 if self .clearExecutionTime is not None :
392394 self .clearExecutionTime ()
393395 cursor = self .textCursor ()
394- cursor .select (QTextCursor .BlockUnderCursor )
396+ cursor .select (QTextCursor .SelectionType . BlockUnderCursor )
395397 line = cursor .selectedText ()
396398 if line and line [0 ] not in string .printable :
397399 line = line [1 :]
@@ -499,7 +501,7 @@ def insertCompletion(self, completion):
499501 """inserts the completion text into the editor"""
500502 if self .completer ().widget () == self :
501503 cursor = self .textCursor ()
502- cursor .select (QTextCursor .WordUnderCursor )
504+ cursor .select (QTextCursor .SelectionType . WordUnderCursor )
503505 cursor .insertText (completion )
504506 self .setTextCursor (cursor )
505507
@@ -562,33 +564,33 @@ def keyPressEvent(self, event):
562564 # character, or remove it if backspace or delete has just been pressed.
563565 key = event .text ()
564566 _ , prefix = completer .currentObject (scope = __main__ .__dict__ )
565- isBackspaceOrDel = event .key () in (Qt .Key_Backspace , Qt .Key_Delete )
567+ isBackspaceOrDel = event .key () in (Qt .Key . Key_Backspace , Qt . Key .Key_Delete )
566568 if key .isalnum () or key in ("-" , "_" ):
567569 prefix += str (key )
568570 elif isBackspaceOrDel and prefix :
569571 prefix = prefix [:- 1 ]
570572
571573 if completer and event .key () in (
572- Qt .Key_Backspace ,
573- Qt .Key_Delete ,
574- Qt .Key_Escape ,
574+ Qt .Key . Key_Backspace ,
575+ Qt .Key . Key_Delete ,
576+ Qt .Key . Key_Escape ,
575577 ):
576578 completer .hideDocumentation ()
577579
578580 # enter || return keys will execute the command
579- if event .key () in (Qt .Key_Return , Qt .Key_Enter ):
581+ if event .key () in (Qt .Key . Key_Return , Qt . Key .Key_Enter ):
580582 if completer .popup ().isVisible ():
581583 completer .clear ()
582584 event .ignore ()
583585 else :
584586 self .executeCommand ()
585587
586588 # home key will move the cursor to home
587- elif event .key () == Qt .Key_Home :
589+ elif event .key () == Qt .Key . Key_Home :
588590 self .moveToHome ()
589591
590592 # otherwise, ignore the event for completion events
591- elif event .key () in (Qt .Key_Tab , Qt .Key_Backtab ):
593+ elif event .key () in (Qt .Key . Key_Tab , Qt . Key .Key_Backtab ):
592594 if not completer .popup ().isVisible ():
593595 # The completer does not get updated if its not visible while typing.
594596 # We are about to complete the text using it so ensure its updated.
@@ -598,19 +600,28 @@ def keyPressEvent(self, event):
598600 )
599601 # Insert the correct text and clear the completion model
600602 index = completer .popup ().currentIndex ()
601- self .insertCompletion (index .data (Qt .DisplayRole ))
603+ self .insertCompletion (index .data (Qt .ItemDataRole . DisplayRole ))
602604 completer .clear ()
603605
604- elif event .key () == Qt .Key_Escape and completer .popup ().isVisible ():
606+ elif event .key () == Qt .Key . Key_Escape and completer .popup ().isVisible ():
605607 completer .clear ()
606608
607609 # other wise handle the keypress
608610 else :
609611 # define special key sequences
610612 modifiers = QApplication .instance ().keyboardModifiers ()
611- ctrlSpace = event .key () == Qt .Key_Space and modifiers == Qt .ControlModifier
612- ctrlM = event .key () == Qt .Key_M and modifiers == Qt .ControlModifier
613- ctrlI = event .key () == Qt .Key_I and modifiers == Qt .ControlModifier
613+ ctrlSpace = (
614+ event .key () == Qt .Key .Key_Space
615+ and modifiers == Qt .KeyboardModifier .ControlModifier
616+ )
617+ ctrlM = (
618+ event .key () == Qt .Key .Key_M
619+ and modifiers == Qt .KeyboardModifier .ControlModifier
620+ )
621+ ctrlI = (
622+ event .key () == Qt .Key .Key_I
623+ and modifiers == Qt .KeyboardModifier .ControlModifier
624+ )
614625
615626 # Process all events we do not want to override
616627 if not (ctrlSpace or ctrlM or ctrlI ):
@@ -629,20 +640,20 @@ def keyPressEvent(self, event):
629640 # check for particular events for the completion
630641 if completer :
631642 # look for documentation popups
632- if event .key () == Qt .Key_ParenLeft :
643+ if event .key () == Qt .Key . Key_ParenLeft :
633644 rect = self .cursorRect ()
634645 point = self .mapToGlobal (QPoint (rect .x (), rect .y ()))
635646 completer .showDocumentation (pos = point , scope = __main__ .__dict__ )
636647
637648 # hide documentation popups
638- elif event .key () == Qt .Key_ParenRight :
649+ elif event .key () == Qt .Key . Key_ParenRight :
639650 completer .hideDocumentation ()
640651
641652 # determine if we need to show the popup or if it already is visible, we
642653 # need to update it
643654 elif (
644- event .key () == Qt .Key_Period
645- or event .key () == Qt .Key_Escape
655+ event .key () == Qt .Key . Key_Period
656+ or event .key () == Qt .Key . Key_Escape
646657 or completer .popup ().isVisible ()
647658 or ctrlSpace
648659 or ctrlI
@@ -673,7 +684,9 @@ def keyPressEvent(self, event):
673684 completer .setCurrentRow (index .row ())
674685
675686 # Make sure that current selection is visible, ie scroll to it
676- completer .popup ().scrollTo (index , QAbstractItemView .EnsureVisible )
687+ completer .popup ().scrollTo (
688+ index , QAbstractItemView .ScrollHint .EnsureVisible
689+ )
677690
678691 # show the completer for the rect
679692 rect = self .cursorRect ()
@@ -690,7 +703,7 @@ def keyPressEvent(self, event):
690703 if completer .wasCompleting and not completer .popup ().isVisible ():
691704 wasCompletingCounterMax = completer .wasCompletingCounterMax
692705 if completer .wasCompletingCounter <= wasCompletingCounterMax :
693- if event .key () not in (Qt .Key_Backspace , Qt .Key_Left ):
706+ if event .key () not in (Qt .Key . Key_Backspace , Qt . Key .Key_Left ):
694707 completer .wasCompletingCounter += 1
695708 else :
696709 completer .wasCompletingCounter = 0
@@ -704,20 +717,26 @@ def setKeywordColor(self, color):
704717
705718 def moveToHome (self ):
706719 """moves the cursor to the home location"""
707- mode = QTextCursor .MoveAnchor
720+ mode = QTextCursor .MoveMode . MoveAnchor
708721 # select the home
709- if QApplication .instance ().keyboardModifiers () == Qt .ShiftModifier :
710- mode = QTextCursor .KeepAnchor
722+ if (
723+ QApplication .instance ().keyboardModifiers ()
724+ == Qt .KeyboardModifier .ShiftModifier
725+ ):
726+ mode = QTextCursor .MoveMode .KeepAnchor
711727 # grab the cursor
712728 cursor = self .textCursor ()
713- if QApplication .instance ().keyboardModifiers () == Qt .ControlModifier :
729+ if (
730+ QApplication .instance ().keyboardModifiers ()
731+ == Qt .KeyboardModifier .ControlModifier
732+ ):
714733 # move to the top of the document if control is pressed
715- cursor .movePosition (QTextCursor .Start )
734+ cursor .movePosition (QTextCursor .MoveOperation . Start )
716735 else :
717736 # Otherwise just move it to the start of the line
718- cursor .movePosition (QTextCursor .StartOfBlock , mode )
737+ cursor .movePosition (QTextCursor .MoveOperation . StartOfBlock , mode )
719738 # move the cursor to the end of the prompt.
720- cursor .movePosition (QTextCursor .Right , mode , len (self .prompt ()))
739+ cursor .movePosition (QTextCursor .MoveOperation . Right , mode , len (self .prompt ()))
721740 self .setTextCursor (cursor )
722741
723742 def outputPrompt (self ):
@@ -760,7 +779,7 @@ def startPrompt(self, prompt):
760779 prompt(str): The prompt to start the line with. If this prompt
761780 is already the only text on the last line this function does nothing.
762781 """
763- self .moveCursor (QTextCursor .End )
782+ self .moveCursor (QTextCursor .MoveOperation . End )
764783
765784 # if this is not already a new line
766785 if self .textCursor ().block ().text () != prompt :
@@ -795,9 +814,11 @@ def setStringColor(self, color):
795814 self ._stringColor = color
796815
797816 def removeCurrentLine (self ):
798- self .moveCursor (QTextCursor .End , QTextCursor .MoveAnchor )
799- self .moveCursor (QTextCursor .StartOfLine , QTextCursor .MoveAnchor )
800- self .moveCursor (QTextCursor .End , QTextCursor .KeepAnchor )
817+ self .moveCursor (QTextCursor .MoveOperation .End , QTextCursor .MoveMode .MoveAnchor )
818+ self .moveCursor (
819+ QTextCursor .MoveOperation .StartOfLine , QTextCursor .MoveMode .MoveAnchor
820+ )
821+ self .moveCursor (QTextCursor .MoveOperation .End , QTextCursor .MoveMode .KeepAnchor )
801822 self .textCursor ().removeSelectedText ()
802823 self .textCursor ().deletePreviousChar ()
803824 self .insertPlainText ("\n " )
@@ -838,7 +859,7 @@ def write(self, msg, error=False):
838859 hasattr (window , 'uiErrorHyperlinksACT' )
839860 and window .uiErrorHyperlinksACT .isChecked ()
840861 )
841- self .moveCursor (QTextCursor .End )
862+ self .moveCursor (QTextCursor .MoveOperation . End )
842863
843864 charFormat = QTextCharFormat ()
844865 if not error :
@@ -857,7 +878,7 @@ def write(self, msg, error=False):
857878 info = None
858879
859880 if doHyperlink and msg == '\n ' :
860- cursor .select (QTextCursor .BlockUnderCursor )
881+ cursor .select (QTextCursor .SelectionType . BlockUnderCursor )
861882 line = cursor .selectedText ()
862883
863884 # Remove possible leading unicode paragraph separator, which really
0 commit comments