Exemplo n.º 1
0
 def helpEvent(self, event, view, option, index):
     if event is not None and view is not None and event.type() == QEvent.ToolTip:
         try:
             db = index.model().db
         except AttributeError:
             return False
         try:
             book_id = db.id(index.row())
         except (ValueError, IndexError, KeyError):
             return False
         db = db.new_api
         device_connected = self.parent().gui.device_connected
         on_device = device_connected is not None and db.field_for('ondevice', book_id)
         p = prepare_string_for_xml
         title = db.field_for('title', book_id)
         authors = db.field_for('authors', book_id)
         if title and authors:
             title = '<b>%s</b>' % ('<br>'.join(wrap(p(title), 120)))
             authors = '<br>'.join(wrap(p(' & '.join(authors)), 120))
             tt = '%s<br><br>%s' % (title, authors)
             series = db.field_for('series', book_id)
             if series:
                 use_roman_numbers=config['use_roman_numerals_for_series_number']
                 val = _('Book %(sidx)s of <span class="series_name">%(series)s</span>')%dict(
                     sidx=fmt_sidx(db.field_for('series_index', book_id), use_roman=use_roman_numbers),
                     series=p(series))
                 tt += '<br><br>' + val
             if on_device:
                 val = _('This book is on the device in %s') % on_device
                 tt += '<br><br>' + val
             QToolTip.showText(event.globalPos(), tt, view)
             return True
     return False
Exemplo n.º 2
0
 def helpEvent(self, event, view, option, index):
     if event is not None and view is not None and event.type() == QEvent.ToolTip:
         try:
             db = index.model().db
         except AttributeError:
             return False
         try:
             book_id = db.id(index.row())
         except (ValueError, IndexError, KeyError):
             return False
         db = db.new_api
         device_connected = self.parent().gui.device_connected
         on_device = device_connected is not None and db.field_for('ondevice', book_id)
         p = prepare_string_for_xml
         title = db.field_for('title', book_id)
         authors = db.field_for('authors', book_id)
         if title and authors:
             title = '<b>%s</b>' % ('<br>'.join(wrap(p(title), 120)))
             authors = '<br>'.join(wrap(p(' & '.join(authors)), 120))
             tt = '%s<br><br>%s' % (title, authors)
             series = db.field_for('series', book_id)
             if series:
                 use_roman_numbers=config['use_roman_numerals_for_series_number']
                 val = _('Book %(sidx)s of <span class="series_name">%(series)s</span>')%dict(
                     sidx=fmt_sidx(db.field_for('series_index', book_id), use_roman=use_roman_numbers),
                     series=p(series))
                 tt += '<br><br>' + val
             if on_device:
                 val = _('This book is on the device in %s') % on_device
                 tt += '<br><br>' + val
             QToolTip.showText(event.globalPos(), tt, view)
             return True
     return False
Exemplo n.º 3
0
    def maybeTip(self, helpEvent):
        """
        Determines if this tooltip should be displayed. The tooltip will be displayed at
        <cusorPos> if an object is highlighted and the mouse hasn't moved for 
        some period of time, called the "wake up delay" period, which is a user pref
        (not yet implemented in the Preferences dialog) currently set to 1 second.
        
        <cursorPos> is the current cursor position in the GLPane's local coordinates.
        
        maybeTip() is called by GLPane.timerEvent() whenever the cursor is not moving to 
        determine if the tooltip should be displayed.
        
        For more details about this member, see Qt documentation on QToolTip.maybeTip().
        """

        # <motionlessCursorDuration> is the amount of time the cursor (mouse) has been motionless.
        motionlessCursorDuration = time.time(
        ) - self.glpane.cursorMotionlessStartTime

        # Don't display the tooltip yet if <motionlessCursorDuration> hasn't exceeded the "wake up delay".
        # The wake up delay is currently set to 1 second in prefs_constants.py. Mark 060818.
        if motionlessCursorDuration < env.prefs[
                dynamicToolTipWakeUpDelay_prefs_key]:
            self.toolTipShown = False
            return

        selobj = self.glpane.selobj

        # If an object is not currently highlighted, don't display a tooltip.
        if not selobj:
            return

        # If the highlighted object is a singlet,
        # don't display a tooltip for it.
        if isinstance(selobj, Atom) and (selobj.element is Singlet):
            return

        if self.toolTipShown:
            # The tooltip is already displayed, so return.
            # Do not allow tip() to be called again or it will "flash".
            return

        tipText = self.getToolTipText()

        if not tipText:
            tipText = ""
            # This makes sure that dynamic tip is not displayed when
            # the highlightable object is 'unknown' to the dynamic tip class.
            # (From QToolTip.showText doc: "If text is empty the tool tip is hidden.")

        QToolTip.showText(
            helpEvent.globalPos(),
            tipText)  #@@@ ninad061107 works fine but need code review

        self.toolTipShown = True
Exemplo n.º 4
0
 def show_tooltip(self, ev):
     c = self.cursorForPosition(ev.pos())
     fmt = self.syntax_format_for_cursor(c)
     if fmt is not None:
         tt = unicode(fmt.toolTip())
         if tt:
             QToolTip.setFont(self.tooltip_font)
             QToolTip.setPalette(self.tooltip_palette)
             QToolTip.showText(ev.globalPos(), textwrap.fill(tt))
     QToolTip.hideText()
     ev.ignore()
Exemplo n.º 5
0
 def show_tooltip(self, ev):
     c = self.cursorForPosition(ev.pos())
     fmt = self.syntax_format_for_cursor(c)
     if fmt is not None:
         tt = unicode(fmt.toolTip())
         if tt:
             QToolTip.setFont(self.tooltip_font)
             QToolTip.setPalette(self.tooltip_palette)
             QToolTip.showText(ev.globalPos(), textwrap.fill(tt))
     QToolTip.hideText()
     ev.ignore()
Exemplo n.º 6
0
   def maybeTip(self, helpEvent):
       """
       Determines if this tooltip should be displayed. The tooltip will be displayed at
       <cusorPos> if an object is highlighted and the mouse hasn't moved for 
       some period of time, called the "wake up delay" period, which is a user pref
       (not yet implemented in the Preferences dialog) currently set to 1 second.
       
       <cursorPos> is the current cursor position in the GLPane's local coordinates.
       
       maybeTip() is called by GLPane.timerEvent() whenever the cursor is not moving to 
       determine if the tooltip should be displayed.
       
       For more details about this member, see Qt documentation on QToolTip.maybeTip().
       """
       
       # <motionlessCursorDuration> is the amount of time the cursor (mouse) has been motionless.
       motionlessCursorDuration = time.time() - self.glpane.cursorMotionlessStartTime
       
       # Don't display the tooltip yet if <motionlessCursorDuration> hasn't exceeded the "wake up delay".
       # The wake up delay is currently set to 1 second in prefs_constants.py. Mark 060818.
       if motionlessCursorDuration < env.prefs[dynamicToolTipWakeUpDelay_prefs_key]:
           self.toolTipShown = False
           return
       
       selobj = self.glpane.selobj
       
       # If an object is not currently highlighted, don't display a tooltip.
       if not selobj:
           return
       
       # If the highlighted object is a singlet, 
       # don't display a tooltip for it.
       if isinstance(selobj, Atom) and (selobj.element is Singlet):
           return
           
       if self.toolTipShown:
           # The tooltip is already displayed, so return. 
           # Do not allow tip() to be called again or it will "flash".
           return
                  
 
       tipText = self.getToolTipText()
       
       if not tipText:            
           tipText = "" 
           # This makes sure that dynamic tip is not displayed when
           # the highlightable object is 'unknown' to the dynamic tip class.
           # (From QToolTip.showText doc: "If text is empty the tool tip is hidden.")
       
       
       QToolTip.showText(helpEvent.globalPos(), tipText)  #@@@ ninad061107 works fine but need code review
              
       self.toolTipShown = True
Exemplo n.º 7
0
 def helpEvent(self, event, view, option, index):
     if event is not None and view is not None and event.type() == QEvent.ToolTip:
         try:
             db = index.model().db
         except AttributeError:
             return False
         try:
             book_id = db.id(index.row())
         except (ValueError, IndexError, KeyError):
             return False
         title = db.new_api.field_for('title', book_id)
         authors = db.new_api.field_for('authors', book_id)
         if title and authors:
             title = '<b>%s</b>' % ('\n'.join(wrap(title, 100)))
             authors = '\n'.join(wrap(' & '.join(authors), 100))
             QToolTip.showText(event.globalPos(), '%s<br><br>%s' % (title, authors), view)
             return True
     return False
Exemplo n.º 8
0
 def showEmotionTips(self,index):
     if index.isValid():
         QToolTip.showText(QCursor.pos(), "Hello", None)
Exemplo n.º 9
0
 def collapse_menu_hovered(self, action):
     tip = action.toolTip()
     if tip == '*':
         tip = ''
     QToolTip.showText(QCursor.pos(), tip)
Exemplo n.º 10
0
 def show_tooltip(self, arg):
     widget, pos = arg
     QToolTip.showText(pos, self.get_tooltip())
Exemplo n.º 11
0
 def collapse_menu_hovered(self, action):
     tip = action.toolTip()
     if tip == '*':
         tip = ''
     QToolTip.showText(QCursor.pos(), tip)
Exemplo n.º 12
0
Arquivo: jobs.py Projeto: sss/calibre
 def show_tooltip(self, arg):
     widget, pos = arg
     QToolTip.showText(pos, self.get_tooltip())
Exemplo n.º 13
0
    def maybeTip(self, helpEvent):
        """
        Determines if this tooltip should be displayed. The tooltip will be displayed at
        helpEvent.globalPos() if an object is highlighted and the mouse hasn't moved for
        some period of time, called the "wake up delay" period, which is a user pref
        (not yet implemented in the Preferences dialog) currently set to 1 second.

        maybeTip() is called by GLPane.timerEvent() whenever the cursor is not moving to
        determine if the tooltip should be displayed.

        @param helpEvent: a QHelpEvent constructed by the caller
        @type helpEvent: QHelpEvent
        """
        # docstring used to also say:
        ## For more details about this member, see Qt documentation on QToolTip.maybeTip().
        # but this is unclear to me (since this class does not inherit from
        # QToolTip), so I removed it. [bruce 081208]

        debug = debug_pref("GLPane: graphics debug tooltip?",
                           Choice_boolean_False,
                           prefs_key = True )

        glpane = self.glpane
        selobj = glpane.selobj

        if debug:
            # russ 080715: Graphics debug tooltip.
            # bruce 081208/081211: revised, moved out of _getToolTipText,
            # made debug_pref.
            # note: we don't use glpane.MousePos since it's not reliable --
            # only some graphicsModes store it, and only in mouse press events.

            # Note: double buffering applies only to the color buffer,
            # not the stencil or depth buffers, which have only one copy.
            # The setting of GL_READ_BUFFER should have no effect on
            # glReadPixelsf from those buffers.
            # [bruce 081211 comment, based on Russ report of OpenGL doc]

            pos = helpEvent.pos()
            wX = pos.x()
            wY = glpane.height - pos.y() #review: off by 1??
            wZ = glReadPixelsf(wX, wY, 1, 1, GL_DEPTH_COMPONENT)[0][0]
            stencil = glReadPixelsi(wX, wY, 1, 1, GL_STENCIL_INDEX)[0][0]
            savebuff = glGetInteger(GL_READ_BUFFER)
            whichbuff = {GL_FRONT:"front", GL_BACK:"back"}.get(savebuff, "unknown")
            redraw_counter = env.redraw_counter
            # Pixel data is sign-wrapped, in spite of specifying unsigned_byte.
            def us(b):
                if b < 0:
                    return 256 + b
                else:
                    return b
            def pixvals(buff):
                glReadBuffer(buff)
                gl_format, gl_type = GL_RGBA, GL_UNSIGNED_BYTE
                rgba = glReadPixels( wX, wY, 1, 1, gl_format, gl_type )[0][0]
                return (
                    "rgba %u, %u, %u, %u" %
                    (us(rgba[0]), us(rgba[1]), us(rgba[2]), us(rgba[3]))
                 )
            def redifnot(v1, v2, text):
                if v1 != v2:
                    return redmsg(text)
                else:
                    return text
            front_pixvals = pixvals(GL_FRONT)
            back_pixvals = pixvals(GL_BACK)
            glReadBuffer(savebuff)      # restore the saved value
            tipText = (
                "env.redraw = %d; selobj = %s<br>" % (redraw_counter, quote_html(str(selobj)),) +
                    # note: sometimes selobj is an instance of _UNKNOWN_SELOBJ_class... relates to testmode bug from renderText
                    # (confirmed that renderText zaps stencil and that that alone causes no bug in other graphicsmodes)
                    # TODO: I suspect this can be printed even during rendering... need to print glpane variables
                    # which indicate whether we're doing rendering now, e.g. current_glselect, drawing_phase;
                    # also modkeys (sp?), glselect_wanted
                "mouse position (xy): %d, %d<br>" % (wX, wY,) +
                "depth %f, stencil %d<br>" % (wZ, stencil) +
                redifnot(whichbuff, "back",
                         "current read buffer: %s<br>" % whichbuff ) +
                redifnot(glpane.glselect_wanted, 0,
                         "glselect_wanted: %s<br>" % (glpane.glselect_wanted,) ) +
                redifnot(glpane.current_glselect, False,
                         "current_glselect: %s<br>" % (glpane.current_glselect,) ) +
                redifnot(glpane.drawing_phase, "?",
                         "drawing_phase: %s<br>" % (glpane.drawing_phase,) ) +
                "front: " + front_pixvals + "<br>" +
                redifnot(back_pixvals, front_pixvals,
                         "back:  " + back_pixvals )
             )
            global _last_tipText
            if tipText != _last_tipText:
                print
                print tipText
                _last_tipText = tipText
            pass # use tipText below

        else:

            # <motionlessCursorDuration> is the amount of time the cursor (mouse) has been motionless.
            motionlessCursorDuration = time.time() - glpane.cursorMotionlessStartTime

            # Don't display the tooltip yet if <motionlessCursorDuration> hasn't exceeded the "wake up delay".
            # The wake up delay is currently set to 1 second in prefs_constants.py. Mark 060818.
            if motionlessCursorDuration < env.prefs[dynamicToolTipWakeUpDelay_prefs_key]:
                self.toolTipShown = False
                return

            # If an object is not currently highlighted, don't display a tooltip.
            if not selobj:
                return

            # If the highlighted object is a singlet,
            # don't display a tooltip for it.
            if isinstance(selobj, Atom) and (selobj.element is Singlet):
                return

            if self.toolTipShown:
                # The tooltip is already displayed, so return.
                # Do not allow tip() to be called again or it will "flash".
                return

            tipText = self._getToolTipText()

            pass

        # show the tipText

        if not tipText:
            tipText = ""
            # This makes sure that dynamic tip is not displayed when
            # the highlightable object is 'unknown' to the dynamic tip class.
            # (From QToolTip.showText doc: "If text is empty the tool tip is hidden.")

        showpos = helpEvent.globalPos()

        if debug:
            # show it a little lower to avoid the cursor obscuring the tooltip.
            # (might be useful even when not debugging, depending on the cursor)
            # [bruce 081208]
            showpos = showpos + QPoint(0, 10)

        QToolTip.showText(showpos, tipText)  #@@@ ninad061107 works fine but need code review

        self.toolTipShown = True
Exemplo n.º 14
0
    def maybeTip(self, helpEvent):
        """
        Determines if this tooltip should be displayed. The tooltip will be displayed at
        helpEvent.globalPos() if an object is highlighted and the mouse hasn't moved for 
        some period of time, called the "wake up delay" period, which is a user pref
        (not yet implemented in the Preferences dialog) currently set to 1 second.
        
        maybeTip() is called by GLPane.timerEvent() whenever the cursor is not moving to 
        determine if the tooltip should be displayed.

        @param helpEvent: a QHelpEvent constructed by the caller
        @type helpEvent: QHelpEvent
        """
        # docstring used to also say:
        ## For more details about this member, see Qt documentation on QToolTip.maybeTip().
        # but this is unclear to me (since this class does not inherit from
        # QToolTip), so I removed it. [bruce 081208]

        debug = debug_pref("GLPane: graphics debug tooltip?",
                           Choice_boolean_False,
                           prefs_key = True )

        glpane = self.glpane
        selobj = glpane.selobj

        if debug:
            # russ 080715: Graphics debug tooltip.
            # bruce 081208/081211: revised, moved out of _getToolTipText,
            # made debug_pref.
            # note: we don't use glpane.MousePos since it's not reliable --
            # only some graphicsModes store it, and only in mouse press events.

            # Note: double buffering applies only to the color buffer,
            # not the stencil or depth buffers, which have only one copy.
            # The setting of GL_READ_BUFFER should have no effect on
            # glReadPixelsf from those buffers.
            # [bruce 081211 comment, based on Russ report of OpenGL doc]
            
            pos = helpEvent.pos()
            wX = pos.x()
            wY = glpane.height - pos.y() #review: off by 1??
            wZ = glReadPixelsf(wX, wY, 1, 1, GL_DEPTH_COMPONENT)[0][0]
            stencil = glReadPixelsi(wX, wY, 1, 1, GL_STENCIL_INDEX)[0][0]
            savebuff = glGetInteger(GL_READ_BUFFER)
            whichbuff = {GL_FRONT:"front", GL_BACK:"back"}.get(savebuff, "unknown")
            redraw_counter = env.redraw_counter
            # Pixel data is sign-wrapped, in spite of specifying unsigned_byte.
            def us(b):
                if b < 0:
                    return 256 + b
                else:
                    return b
            def pixvals(buff):
                glReadBuffer(buff)
                gl_format, gl_type = GL_RGBA, GL_UNSIGNED_BYTE
                rgba = glReadPixels( wX, wY, 1, 1, gl_format, gl_type )[0][0]
                return (
                    "rgba %u, %u, %u, %u" %
                    (us(rgba[0]), us(rgba[1]), us(rgba[2]), us(rgba[3]))
                 )
            def redifnot(v1, v2, text):
                if v1 != v2:
                    return redmsg(text)
                else:
                    return text
            front_pixvals = pixvals(GL_FRONT)
            back_pixvals = pixvals(GL_BACK)
            glReadBuffer(savebuff)      # restore the saved value
            tipText = (
                "env.redraw = %d; selobj = %s<br>" % (redraw_counter, quote_html(str(selobj)),) +
                    # note: sometimes selobj is an instance of _UNKNOWN_SELOBJ_class... relates to testmode bug from renderText
                    # (confirmed that renderText zaps stencil and that that alone causes no bug in other graphicsmodes)
                    # TODO: I suspect this can be printed even during rendering... need to print glpane variables
                    # which indicate whether we're doing rendering now, e.g. current_glselect, drawing_phase;
                    # also modkeys (sp?), glselect_wanted
                "mouse position (xy): %d, %d<br>" % (wX, wY,) +
                "depth %f, stencil %d<br>" % (wZ, stencil) +
                redifnot(whichbuff, "back",
                         "current read buffer: %s<br>" % whichbuff ) +
                redifnot(glpane.glselect_wanted, 0,
                         "glselect_wanted: %s<br>" % (glpane.glselect_wanted,) ) + 
                redifnot(glpane.current_glselect, False,
                         "current_glselect: %s<br>" % (glpane.current_glselect,) ) + 
                redifnot(glpane.drawing_phase, "?",
                         "drawing_phase: %s<br>" % (glpane.drawing_phase,) ) +
                "front: " + front_pixvals + "<br>" +
                redifnot(back_pixvals, front_pixvals,
                         "back:  " + back_pixvals )
             )
            global _last_tipText
            if tipText != _last_tipText:
                print
                print tipText
                _last_tipText = tipText
            pass # use tipText below

        else:
            
            # <motionlessCursorDuration> is the amount of time the cursor (mouse) has been motionless.
            motionlessCursorDuration = time.time() - glpane.cursorMotionlessStartTime
            
            # Don't display the tooltip yet if <motionlessCursorDuration> hasn't exceeded the "wake up delay".
            # The wake up delay is currently set to 1 second in prefs_constants.py. Mark 060818.
            if motionlessCursorDuration < env.prefs[dynamicToolTipWakeUpDelay_prefs_key]:
                self.toolTipShown = False
                return
            
            # If an object is not currently highlighted, don't display a tooltip.
            if not selobj:
                return
            
            # If the highlighted object is a singlet, 
            # don't display a tooltip for it.
            if isinstance(selobj, Atom) and (selobj.element is Singlet):
                return
                
            if self.toolTipShown:
                # The tooltip is already displayed, so return. 
                # Do not allow tip() to be called again or it will "flash".
                return
        
            tipText = self._getToolTipText()

            pass

        # show the tipText
        
        if not tipText:            
            tipText = "" 
            # This makes sure that dynamic tip is not displayed when
            # the highlightable object is 'unknown' to the dynamic tip class.
            # (From QToolTip.showText doc: "If text is empty the tool tip is hidden.")

        showpos = helpEvent.globalPos()

        if debug:
            # show it a little lower to avoid the cursor obscuring the tooltip.
            # (might be useful even when not debugging, depending on the cursor)
            # [bruce 081208]
            showpos = showpos + QPoint(0, 10)
        
        QToolTip.showText(showpos, tipText)  #@@@ ninad061107 works fine but need code review
               
        self.toolTipShown = True