tooltip.py :  » GUI » Kodos » kodos-2.4.9 » modules » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Kodos 
Kodos » kodos 2.4.9 » modules » tooltip.py
#  tooltip.py: -*- Python -*-  DESCRIPTIVE TEXT.

from qt import *
from util import *

class Tooltip(QLabel):
    def __init__(self, text, bgcolor="#ffd700",fgcolor="#000000",delay=1000):
        self.delay = delay
        QLabel.__init__(self, None, "tooltip", Qt.WStyle_StaysOnTop
                        | Qt.WStyle_Customize
                        | Qt.WStyle_NoBorder
                        | Qt.WStyle_Tool)
        self.setMargin(1)
        self.setIndent(0)
        self.setAutoMask(FALSE)
        self.setFrameStyle(QFrame.Plain | QFrame.Box)
        self.setLineWidth(1)
        self.polish()
        self.setText(text)
        self.adjustSize()

        # set the pallete...
        pal = QPalette()
        cg = QColorGroup()
        cg.setColor(QColorGroup.Background, QColor(bgcolor))
        cg.setColor(QColorGroup.Foreground, QColor(fgcolor))
        pal.setActive(cg)
        pal.setInactive(cg)
        self.setPalette(pal)

        self.enter_timer_id = None
        self.leave_timer_id = None


    def set_tooltip(self, text):
        self.text = text
        self.setText(text)


    def clear_tooltip(self):
        self.text = ''
        self.setText('')
                

    def addWidget(self, widget):
        #print "adding widget", widget
        widget.installEventFilter(self)


    def removeWidget(self, widget):
        #print "removing widget", widget
        widget.removeEventFilter(self)


    def killCustomTimers( self ):
        if self.enter_timer_id:
            self.killTimer( self.enter_timer_id )
            self.enter_timer_id = None
        if self.leave_timer_id:
            self.killTimer( self.leave_timer_id )
            self.leave_timer_id = None


    def timerEvent( self, ev ):
        if ev.timerId() == self.enter_timer_id:
            self.tooltip_open()
        elif ev.timerId() == self.leave_timer_id:
            self.tooltip_close()
        self.killCustomTimers()


    def eventFilter(self, obj, ev):
        type = ev.type()
        #print obj, type
        if type == QEvent.Enter:
            self.killCustomTimers()
            self.enter_timer_id = self.startTimer(self.delay)
            #print "tip!"
            self.event_widget = obj
        elif type == QEvent.Leave:
            self.killCustomTimers()
            self.leave_timer_id = self.startTimer(self.delay)
            #print "remove tip!"
            self.event_widget = None
        return FALSE ## Always return unhandled for this kind of filter!!!


    def tooltip_open(self):
        if not self.text:
            return
        
        try:
            pos = self.event_widget.mapToGlobal(
                QPoint(0, self.event_widget.height()))
            self.move(pos.x(), pos.y())
            self.show()
            self.setFixedSize( self.sizeHint() )
        except:
            pass


    def tooltip_close(self):
        self.hide()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.