src/eric7/EricWidgets/EricSpellCheckedTextEdit.py

branch
eric7
changeset 9643
10839ab864e0
parent 9600
367d1b4fcca8
child 9653
e67609152c5e
equal deleted inserted replaced
9642:a0f7800fbfcb 9643:10839ab864e0
19 19
20 ENCHANT_AVAILABLE = True 20 ENCHANT_AVAILABLE = True
21 except ImportError: 21 except ImportError:
22 ENCHANT_AVAILABLE = False 22 ENCHANT_AVAILABLE = False
23 23
24 from PyQt6.QtCore import QCoreApplication, Qt, pyqtSlot 24 from PyQt6.QtCore import QCoreApplication, QPoint, Qt, pyqtSlot
25 from PyQt6.QtGui import ( 25 from PyQt6.QtGui import (
26 QAction, 26 QAction,
27 QActionGroup, 27 QActionGroup,
28 QSyntaxHighlighter, 28 QSyntaxHighlighter,
29 QTextBlockUserData, 29 QTextBlockUserData,
76 # checking. 76 # checking.
77 spellDict = None 77 spellDict = None
78 78
79 self.__highlighter.setDict(spellDict) 79 self.__highlighter.setDict(spellDict)
80 80
81 def contextMenuEvent(self, evt): 81 @pyqtSlot(QPoint)
82 """ 82 def _showContextMenu(self, pos):
83 Protected method to handle context menu events to add a spelling 83 """
84 suggestions submenu. 84 Protected slot to show a context menu.
85 85
86 @param evt reference to the context menu event 86 @param pos position for the context menu
87 @type QContextMenuEvent 87 @type QPoint
88 """ 88 """
89 menu = self.__createSpellcheckContextMenu(evt.pos()) 89 menu = self.__createSpellcheckContextMenu(pos)
90 menu.exec(evt.globalPos()) 90 menu.exec(self.mapToGlobal(pos))
91 91
92 def __createSpellcheckContextMenu(self, pos): 92 def __createSpellcheckContextMenu(self, pos):
93 """ 93 """
94 Private method to create the spell-check context menu. 94 Private method to create the spell-check context menu.
95 95
574 """ 574 """
575 Constructor 575 Constructor
576 """ 576 """
577 pass 577 pass
578 578
579 @pyqtSlot(QPoint)
580 def _showContextMenu(self, pos):
581 """
582 Protected slot to show a context menu.
583
584 @param pos position for the context menu
585 @type QPoint
586 """
587 pass
588
579 def setFormat(self, formatName): 589 def setFormat(self, formatName):
580 """ 590 """
581 Public method to set the document format. 591 Public method to set the document format.
582 592
583 @param formatName name of the document format 593 @param formatName name of the document format
656 @type list 666 @type list
657 """ 667 """
658 QPlainTextEdit.__init__(self, *args) 668 QPlainTextEdit.__init__(self, *args)
659 SpellCheckMixin.__init__(self) 669 SpellCheckMixin.__init__(self)
660 670
671 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
672 self.customContextMenuRequested.connect(self._showContextMenu)
673
661 674
662 class EricSpellCheckedTextEdit(QTextEdit, SpellCheckMixin): 675 class EricSpellCheckedTextEdit(QTextEdit, SpellCheckMixin):
663 """ 676 """
664 Class implementing a QTextEdit with built-in spell checker. 677 Class implementing a QTextEdit with built-in spell checker.
665 """ 678 """
673 """ 686 """
674 QTextEdit.__init__(self, *args) 687 QTextEdit.__init__(self, *args)
675 SpellCheckMixin.__init__(self) 688 SpellCheckMixin.__init__(self)
676 689
677 self.setFormat("html") 690 self.setFormat("html")
691
692 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
693 self.customContextMenuRequested.connect(self._showContextMenu)
678 694
679 def setAcceptRichText(self, accept): 695 def setAcceptRichText(self, accept):
680 """ 696 """
681 Public method to set the text edit mode. 697 Public method to set the text edit mode.
682 698

eric ide

mercurial