A call-tip widget for tkinter text widgets.
| 17 | |
| 18 | |
| 19 | class CalltipWindow(TooltipBase): |
| 20 | """A call-tip widget for tkinter text widgets.""" |
| 21 | |
| 22 | def __init__(self, text_widget): |
| 23 | """Create a call-tip; shown by showtip(). |
| 24 | |
| 25 | text_widget: a Text widget with code for which call-tips are desired |
| 26 | """ |
| 27 | # Note: The Text widget will be accessible as self.anchor_widget |
| 28 | super().__init__(text_widget) |
| 29 | |
| 30 | self.label = self.text = None |
| 31 | self.parenline = self.parencol = self.lastline = None |
| 32 | self.hideid = self.checkhideid = None |
| 33 | self.checkhide_after_id = None |
| 34 | |
| 35 | def get_position(self): |
| 36 | """Choose the position of the call-tip.""" |
| 37 | curline = int(self.anchor_widget.index("insert").split('.')[0]) |
| 38 | if curline == self.parenline: |
| 39 | anchor_index = (self.parenline, self.parencol) |
| 40 | else: |
| 41 | anchor_index = (curline, 0) |
| 42 | box = self.anchor_widget.bbox("%d.%d" % anchor_index) |
| 43 | if not box: |
| 44 | box = list(self.anchor_widget.bbox("insert")) |
| 45 | # align to left of window |
| 46 | box[0] = 0 |
| 47 | box[2] = 0 |
| 48 | return box[0] + 2, box[1] + box[3] |
| 49 | |
| 50 | def position_window(self): |
| 51 | "Reposition the window if needed." |
| 52 | curline = int(self.anchor_widget.index("insert").split('.')[0]) |
| 53 | if curline == self.lastline: |
| 54 | return |
| 55 | self.lastline = curline |
| 56 | self.anchor_widget.see("insert") |
| 57 | super().position_window() |
| 58 | |
| 59 | def showtip(self, text, parenleft, parenright): |
| 60 | """Show the call-tip, bind events which will close it and reposition it. |
| 61 | |
| 62 | text: the text to display in the call-tip |
| 63 | parenleft: index of the opening parenthesis in the text widget |
| 64 | parenright: index of the closing parenthesis in the text widget, |
| 65 | or the end of the line if there is no closing parenthesis |
| 66 | """ |
| 67 | # Only called in calltip.Calltip, where lines are truncated |
| 68 | self.text = text |
| 69 | if self.tipwindow or not self.text: |
| 70 | return |
| 71 | |
| 72 | self.anchor_widget.mark_set(MARK_RIGHT, parenright) |
| 73 | self.parenline, self.parencol = map( |
| 74 | int, self.anchor_widget.index(parenleft).split(".")) |
| 75 | |
| 76 | super().showtip() |
no outgoing calls
no test coverage detected
searching dependent graphs…