30 def show(self, timeout=0, above=False):
31 self.cursor_start_col = self.textedit.textCursor().columnNumber()
32 desktop = QApplication.instance().desktop()
33 screen = desktop.screen(desktop.screenNumber(self))
34 screen_width = screen.width()
35 screen_height = screen.height()
36 win_width = self.width()
37 win_height = self.height()
38 cursorRect = self.textedit.cursorRect()
39 if above:
40 pos = self.textedit.mapToGlobal(cursorRect.topLeft())
41 pos.setY(pos.y() - win_height)
42 else:
43 pos = self.textedit.mapToGlobal(cursorRect.bottomLeft())
44 if pos.y() < 0:
45 pos = self.textedit.mapToGlobal(cursorRect.bottomLeft())
46 if pos.y() + win_height > screen_height:
47 pos = self.textedit.mapToGlobal(cursorRect.topLeft())
48 pos.setY(pos.y() - win_height)
49 if pos.x() + win_width > screen_width:
50 pos.setX(screen_width - win_width)
51
52 self.move(pos)
53 QWidget.show(self)
54 self.active = True
55 if timeout:
56 QTimer.singleShot(timeout * 1000, self.hide)
57