Skip to content

Commit c3b817b

Browse files
committed
Convert to long form enum names
Note: This change breaks support for Qt4 and older versions of Qt5. See https://github.com/mottosso/Qt.py/blob/master/CAVEATS.md#fully-qualified-enums https://stackoverflow.com/a/72658216
1 parent bf3cdf7 commit c3b817b

26 files changed

+309
-208
lines changed

preditor/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ def launch(run_workbox=False, app_id=None, name=None, standalone=False):
184184
# it regain focus.
185185
widget.activateWindow()
186186
widget.raise_()
187-
widget.setWindowState(widget.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
187+
widget.setWindowState(
188+
widget.windowState() & ~Qt.WindowState.WindowMinimized
189+
| Qt.WindowState.WindowActive
190+
)
188191
widget.console().setFocus()
189192
app.start()
190193

preditor/excepthooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PreditorExceptHook(object):
1515
This calls each callable in the `preditor.config.excepthooks` list any time
1616
`sys.excepthook` is called due to an raised exception.
1717
18-
If `config.excepthook` is empty when installing this class, it will
18+
If `config.excepthooks` is empty when installing this class, it will
1919
automatically add `default_excepthooks`. You can disable this by adding `None`
2020
to the list before this class is initialized.
2121
"""

preditor/gui/completer.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ def __init__(self, widget):
6464

6565
def setCaseSensitive(self, caseSensitive=True):
6666
"""Set case sensitivity for completions"""
67-
self._sensitivity = Qt.CaseSensitive if caseSensitive else Qt.CaseInsensitive
67+
self._sensitivity = (
68+
Qt.CaseSensitivity.CaseSensitive
69+
if caseSensitive
70+
else Qt.CaseSensitivity.CaseInsensitive
71+
)
6872
self.buildCompleter()
6973

7074
def caseSensitive(self):
7175
"""Return current case sensitivity state for completions"""
72-
caseSensitive = self._sensitivity == Qt.CaseSensitive
76+
caseSensitive = self._sensitivity == Qt.CaseSensitivity.CaseSensitive
7377
return caseSensitive
7478

7579
def setCompleterMode(self, completerMode=CompleterMode.STARTS_WITH):
@@ -90,7 +94,7 @@ def buildCompleter(self):
9094
self.filterModel.setSourceModel(model)
9195
self.filterModel.setFilterCaseSensitivity(self._sensitivity)
9296
self.setModel(self.filterModel)
93-
self.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
97+
self.setCompletionMode(QCompleter.CompletionMode.UnfilteredPopupCompletion)
9498

9599
def currentObject(self, scope=None, docMode=False):
96100
if self._enabled:
@@ -200,7 +204,7 @@ def textUnderCursor(self, useParens=False):
200204
"""pulls out the text underneath the cursor of this items widget"""
201205

202206
cursor = self.widget().textCursor()
203-
cursor.select(QTextCursor.WordUnderCursor)
207+
cursor.select(QTextCursor.SelectionType.WordUnderCursor)
204208

205209
# grab the selected word
206210
word = cursor.selectedText()

preditor/gui/console.py

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)