| 3 | import binaryninjaui |
| 4 | |
| 5 | class TooltipPopup(QWidget): |
| 6 | def __init__(self, parent=None): |
| 7 | super().__init__(parent, Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) |
| 8 | self.setFocusPolicy(Qt.StrongFocus) |
| 9 | self.setWindowTitle("Tooltip Popup") |
| 10 | |
| 11 | layout = QVBoxLayout() |
| 12 | label = QLabel("This is a tooltip-style popup. Press ESC to close.") |
| 13 | layout.addWidget(label) |
| 14 | |
| 15 | self.setLayout(layout) |
| 16 | self.adjustSize() |
| 17 | |
| 18 | def keyPressEvent(self, event): |
| 19 | # This causes the fake tooltip to be closed when you hit Esc |
| 20 | if event.key() == Qt.Key_Escape: |
| 21 | print("Escape key pressed") |
| 22 | self.close() |
| 23 | event.accept() |
| 24 | else: |
| 25 | super().keyPressEvent(event) |
| 26 | |
| 27 | def showEvent(self, event): |
| 28 | # This forces the fake tooltip to be focused |
| 29 | super().showEvent(event) |
| 30 | self.raise_() |
| 31 | self.activateWindow() |
| 32 | self.setFocus() |
| 33 | |
| 34 | def focusOutEvent(self, event): |
| 35 | # This closes the fake tooltip when the user clicks into another UI element |
| 36 | print("Lost focus") |
| 37 | self.close() |
| 38 | super().focusOutEvent(event) |
| 39 | |
| 40 | def show_tooltip_popup(parent, pos): |
| 41 | tooltip_popup = TooltipPopup(parent) |
no outgoing calls
no test coverage detected