--- a/eric7/QScintilla/QsciScintillaCompat.py Wed Jul 28 17:01:12 2021 +0200 +++ b/eric7/QScintilla/QsciScintillaCompat.py Wed Jul 28 17:02:19 2021 +0200 @@ -10,8 +10,8 @@ import contextlib from PyQt6.QtCore import pyqtSignal, Qt, QPoint -from PyQt6.QtGui import QPalette, QColor, QFontMetrics -from PyQt6.QtWidgets import QApplication, QListWidget +from PyQt6.QtGui import QPalette, QColor +from PyQt6.QtWidgets import QApplication from PyQt6.Qsci import ( QsciScintillaBase, QsciScintilla, QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION @@ -84,11 +84,7 @@ self.userListActivated.connect(self.__completionListSelected) self.modificationChanged.connect(self.__modificationChanged) - self.maxLines = 5 - self.maxChars = 40 - # Adjust the min. size of the autocomplete list box for short strings. - # Otherwise the width of the list box is at least the standard width. - self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXWIDTH, 5) + self.setAutoCompletionWidgetSize(40, 5) def __modificationChanged(self, m): """ @@ -386,6 +382,18 @@ ## methods below are missing from QScintilla ########################################################################### + def setAutoCompletionWidgetSize(self, chars, lines): + """ + Public method to set the size of completion and user lists. + + @param chars max. number of chars to show + @type int + @param lines max. number of lines to show + @type int + """ + self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXWIDTH, chars) + self.SendScintilla(QsciScintilla.SCI_AUTOCSETMAXHEIGHT, lines) + def zoomIn(self, zoom=1): """ Public method used to increase the zoom factor. @@ -1502,122 +1510,6 @@ ## 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] - geom = userListWidget.geometry() - - baseHeight = geom.height() - - # Workaround for getting all items instead of - # userListWidget.items() call with unknown mime types. - all_items = userListWidget.findItems( - '', Qt.MatchFlag.MatchStartsWith) - if not all_items: - return - - width = 0 - maxItemHeight = 0 - for item in all_items: - visualRect = userListWidget.visualItemRect(item) - itemWidth = visualRect.width() - if itemWidth > width: - width = itemWidth - itemHeight = visualRect.height() - if itemHeight > maxItemHeight: - maxItemHeight = itemHeight - - height = min(self.maxLines, len(all_items)) * maxItemHeight - # Just a fiddling factor: 2 for better readability, - # e.g. underscores at the end of the list. - height += 2 - - # Borders - borders = geom.size() - userListWidget.contentsRect().size() - width += borders.width() - height += borders.height() - - font = userListWidget.font() - fm = QFontMetrics(font) - averageCharWidth = fm.averageCharWidth() - maxWidth = averageCharWidth * self.maxChars - if width > maxWidth: - width = maxWidth - height += ( - userListWidget.horizontalScrollBar().sizeHint().height() - ) - # List box doesn't honor limited size to show scroll bars. - # So just force it. - userListWidget.setHorizontalScrollBarPolicy( - Qt.ScrollBarPolicy.ScrollBarAlwaysOn) - - if len(all_items) > self.maxLines: - width += userListWidget.verticalScrollBar().sizeHint().width() - - # Special case, where the space below current line where to less - yPos = geom.y() - charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) - currentYPos = self.SendScintilla( - QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos) - - # X position doesn't matter: set to 0 - globalPos = self.mapToGlobal(QPoint(0, currentYPos)) - if yPos < globalPos.y(): - deltaHeight = baseHeight - height - geom.setY(yPos + deltaHeight - 4) - - geom.setWidth(width) - geom.setHeight(height) - userListWidget.setGeometry(geom) - def __completionListSelected(self, listId, txt): """ Private slot to handle the selection from the completion list.