9 |
9 |
10 import contextlib |
10 import contextlib |
11 |
11 |
12 from PyQt5.QtCore import pyqtSignal, Qt, QPoint |
12 from PyQt5.QtCore import pyqtSignal, Qt, QPoint |
13 from PyQt5.QtGui import QPalette, QColor |
13 from PyQt5.QtGui import QPalette, QColor |
14 from PyQt5.QtWidgets import QApplication |
14 from PyQt5.QtWidgets import QApplication, QListWidget |
15 from PyQt5.Qsci import ( |
15 from PyQt5.Qsci import ( |
16 QsciScintillaBase, QsciScintilla, |
16 QsciScintillaBase, QsciScintilla, |
17 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION |
17 QSCINTILLA_VERSION as QSCIQSCINTILLA_VERSION |
18 ) |
18 ) |
19 |
19 |
1498 |
1498 |
1499 ########################################################################### |
1499 ########################################################################### |
1500 ## replacements for buggy methods |
1500 ## replacements for buggy methods |
1501 ########################################################################### |
1501 ########################################################################### |
1502 |
1502 |
|
1503 def showUserList(self, listId, lst): |
|
1504 """ |
|
1505 Public method to show a user supplied list. |
|
1506 |
|
1507 @param listId id of the list (integer) |
|
1508 @param lst list to be show (list of strings) |
|
1509 """ |
|
1510 if listId <= 0: |
|
1511 return |
|
1512 |
|
1513 # Setup seperator for user lists |
|
1514 self.SendScintilla( |
|
1515 QsciScintilla.SCI_AUTOCSETSEPARATOR, ord(self.UserSeparator)) |
|
1516 self.SendScintilla( |
|
1517 QsciScintilla.SCI_USERLISTSHOW, listId, |
|
1518 self._encodeString(self.UserSeparator.join(lst))) |
|
1519 |
|
1520 self.updateUserListSize() |
|
1521 |
|
1522 def autoCompleteFromDocument(self): |
|
1523 """ |
|
1524 Public method to resize list box after creation. |
|
1525 """ |
|
1526 super().autoCompleteFromDocument() |
|
1527 self.updateUserListSize() |
|
1528 |
|
1529 def autoCompleteFromAPIs(self): |
|
1530 """ |
|
1531 Public method to resize list box after creation. |
|
1532 """ |
|
1533 super().autoCompleteFromAPIs() |
|
1534 self.updateUserListSize() |
|
1535 |
|
1536 def autoCompleteFromAll(self): |
|
1537 """ |
|
1538 Public method to resize list box after creation. |
|
1539 """ |
|
1540 super().autoCompleteFromAll() |
|
1541 self.updateUserListSize() |
|
1542 |
|
1543 ########################################################################### |
|
1544 ## work-around for buggy behavior |
|
1545 ########################################################################### |
|
1546 |
|
1547 def updateUserListSize(self): |
|
1548 """ |
|
1549 Public method to resize the completion list to fit with contents. |
|
1550 """ |
|
1551 children = self.findChildren(QListWidget) |
|
1552 if children: |
|
1553 userListWidget = children[-1] |
|
1554 hScrollbar = userListWidget.horizontalScrollBar() |
|
1555 if hScrollbar.isVisible(): |
|
1556 hScrollbarHeight = hScrollbar.sizeHint().height() |
|
1557 |
|
1558 geom = userListWidget.geometry() |
|
1559 geom.setHeight(geom.height() + hScrollbarHeight) |
|
1560 |
|
1561 charPos = self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS) |
|
1562 currentYPos = self.SendScintilla( |
|
1563 QsciScintilla.SCI_POINTYFROMPOSITION, 0, charPos) |
|
1564 if geom.y() < currentYPos: |
|
1565 geom.setY(geom.y() - hScrollbarHeight) |
|
1566 moveY = True |
|
1567 else: |
|
1568 moveY = False |
|
1569 |
|
1570 userListWidget.setGeometry(geom) |
|
1571 if moveY: |
|
1572 userListWidget.move(geom.x(), geom.y() - hScrollbarHeight) |
|
1573 |
1503 def __completionListSelected(self, listId, txt): |
1574 def __completionListSelected(self, listId, txt): |
1504 """ |
1575 """ |
1505 Private slot to handle the selection from the completion list. |
1576 Private slot to handle the selection from the completion list. |
1506 |
1577 |
1507 Note: This works around an issue of some window managers taking |
1578 Note: This works around an issue of some window managers taking |