eric7/QScintilla/QsciScintillaCompat.py

branch
eric7
changeset 8489
45af30c5561d
parent 8481
02865597d820
child 8581
a6c893c8b7af
diff -r b9168b90f830 -r 45af30c5561d eric7/QScintilla/QsciScintillaCompat.py
--- a/eric7/QScintilla/QsciScintillaCompat.py	Wed Jul 28 19:46:57 2021 +0200
+++ b/eric7/QScintilla/QsciScintillaCompat.py	Thu Jul 29 19:39:19 2021 +0200
@@ -11,7 +11,7 @@
 
 from PyQt6.QtCore import pyqtSignal, Qt, QPoint
 from PyQt6.QtGui import QPalette, QColor
-from PyQt6.QtWidgets import QApplication
+from PyQt6.QtWidgets import QApplication, QListWidget
 from PyQt6.Qsci import (
     QsciScintillaBase, QsciScintilla,
     QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION
@@ -1510,6 +1510,77 @@
     ## replacements for buggy methods
     ###########################################################################
     
+    def showUserList(self, listId, lst):
+        """
+        Public method to show a user supplied list.
+        
+        @param listId id of the list (integer)
+        @param lst list to be show (list of strings)
+        """
+        if listId <= 0:
+            return
+        
+        # Setup seperator for user lists
+        self.SendScintilla(
+            QsciScintilla.SCI_AUTOCSETSEPARATOR, ord(self.UserSeparator))
+        self.SendScintilla(
+            QsciScintilla.SCI_USERLISTSHOW, listId,
+            self._encodeString(self.UserSeparator.join(lst)))
+        
+        self.updateUserListSize()
+    
+    def autoCompleteFromDocument(self):
+        """
+        Public method to resize list box after creation.
+        """
+        super().autoCompleteFromDocument()
+        self.updateUserListSize()
+    
+    def autoCompleteFromAPIs(self):
+        """
+        Public method to resize list box after creation.
+        """
+        super().autoCompleteFromAPIs()
+        self.updateUserListSize()
+    
+    def autoCompleteFromAll(self):
+        """
+        Public method to resize list box after creation.
+        """
+        super().autoCompleteFromAll()
+        self.updateUserListSize()
+    
+    ###########################################################################
+    ## work-around for buggy behavior
+    ###########################################################################
+    
+    def updateUserListSize(self):
+        """
+        Public method to resize the completion list to fit with contents.
+        """
+        children = self.findChildren(QListWidget)
+        if children:
+            userListWidget = children[-1]
+            hScrollbar = userListWidget.horizontalScrollBar()
+            if hScrollbar.isVisible():
+                hScrollbarHeight = hScrollbar.sizeHint().height()
+                
+                geom = userListWidget.geometry()
+                geom.setHeight(geom.height() + hScrollbarHeight)
+                
+                charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
+                currentYPos = self.SendScintilla(
+                    QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos)
+                if geom.y() < currentYPos:
+                    geom.setY(geom.y() - hScrollbarHeight)
+                    moveY = True
+                else:
+                    moveY = False
+                
+                userListWidget.setGeometry(geom)
+                if moveY:
+                    userListWidget.move(geom.x(), geom.y() - hScrollbarHeight)
+    
     def __completionListSelected(self, listId, txt):
         """
         Private slot to handle the selection from the completion list.

eric ide

mercurial