Exemple #1
0
 def show_calltip(self, title, text, color='#2D62FF',
                  at_line=None, at_position=None):
     """Show calltip"""
     if text is None or len(text) == 0:
         return
     # Saving cursor position:
     if at_position is None:
         at_position = self.get_position('cursor')
     self.calltip_position = at_position
     # Preparing text:
     weight = 'bold' if self.calltip_font.bold() else 'normal'
     size = self.calltip_font.pointSize()
     family = self.calltip_font.family()
     format1 = '<div style=\'font-size: %spt; color: %s\'>' % (size, color)
     format2 = '<hr><div style=\'font-family: "%s"; font-size: %spt; font-weight: %s\'>' % (family, size, weight)
     if isinstance(text, list):
         text = "\n    ".join(text)
     text = text.replace('\n', '<br>')
     if len(text) > self.calltip_size:
         text = text[:self.calltip_size] + " ..."
     tiptext = format1 + ('<b>%s</b></div>' % title) \
               + format2 + text + "</div>"
     # Showing tooltip at cursor position:
     cx, cy = self.get_coordinates('cursor')
     if at_line is not None:
         cx = 5
         cursor = QTextCursor(self.document().findBlockByNumber(at_line-1))
         cy = self.cursorRect(cursor).top()
     point = self.mapToGlobal(QPoint(cx, cy))
     point.setX(point.x()+self.get_linenumberarea_width())
     QToolTip.showText(point, tiptext)
Exemple #2
0
 def hide_tooltip_if_necessary(self, key):
     """Hide calltip when necessary"""
     try:
         calltip_char = self.get_character(self.calltip_position)
         before = self.is_cursor_before(self.calltip_position,
                                        char_offset=1)
         other = key in (Qt.Key_ParenRight, Qt.Key_Period, Qt.Key_Tab)
         if calltip_char not in ('?','(') or before or other:
             QToolTip.hideText()
     except (IndexError, TypeError):
         QToolTip.hideText()
Exemple #3
0
 def hide_tooltip_if_necessary(self, key):
     """Hide calltip when necessary"""
     try:
         calltip_char = self.get_character(self.calltip_position)
         before = self.is_cursor_before(self.calltip_position,
                                        char_offset=1)
         other = key in (Qt.Key_ParenRight, Qt.Key_Period, Qt.Key_Tab)
         if calltip_char not in ('?', '(') or before or other:
             QToolTip.hideText()
     except (IndexError, TypeError):
         QToolTip.hideText()
Exemple #4
0
 def show_calltip(self,
                  title,
                  text,
                  color='#2D62FF',
                  at_line=None,
                  at_position=None):
     """Show calltip"""
     if text is None or len(text) == 0:
         return
     # Saving cursor position:
     if at_position is None:
         at_position = self.get_position('cursor')
     self.calltip_position = at_position
     # Preparing text:
     weight = 'bold' if self.calltip_font.bold() else 'normal'
     size = self.calltip_font.pointSize()
     family = self.calltip_font.family()
     format1 = '<div style=\'font-size: %spt; color: %s\'>' % (size, color)
     format2 = '<hr><div style=\'font-family: "%s"; font-size: %spt; font-weight: %s\'>' % (
         family, size, weight)
     if isinstance(text, list):
         text = "\n    ".join(text)
     text = text.replace('\n', '<br>')
     if len(text) > self.calltip_size:
         text = text[:self.calltip_size] + " ..."
     tiptext = format1 + ('<b>%s</b></div>' % title) \
               + format2 + text + "</div>"
     # Showing tooltip at cursor position:
     cx, cy = self.get_coordinates('cursor')
     if at_line is not None:
         cx = 5
         cursor = QTextCursor(self.document().findBlockByNumber(at_line -
                                                                1))
         cy = self.cursorRect(cursor).top()
     point = self.mapToGlobal(QPoint(cx, cy))
     point.setX(point.x() + self.get_linenumberarea_width())
     QToolTip.showText(point, tiptext)