AGW Logo

svn SVN Revision 68343 For supertooltip

This file contains the SVN revision history for supertooltip, at revision 68343.

Available information include commit date, the name of the committer, the file size, the SVN log messages and a diff from the previous version (if available).


file_info File Information

  • Commit Date: 29-May-2009 08:06:58 UTC
  • Committer: AG
  • File Size: 44721 byte(s)

svn_log Log Messages

The following log message was entered by the committer:

  • AquaButton: added the possibility to use it as a toggle button;
  • SuperToolTip: Simple check to avoid starting many SuperToolTips at once.

svn_diff Diff To Previous Version (65377)

Version SVN diff:

--- wxPython/3rdParty/AGW/agw/supertooltip.py       2010/08/21 20:27:02     65377
+++ wxPython/3rdParty/AGW/agw/supertooltip.py       2011/07/23 19:24:24     68343
@@ -2,7 +2,7 @@
# SUPERTOOLTIP wxPython IMPLEMENTATION
#
# Andrea Gavana, @ 07 October 2008
-# Latest Revision: 02 Aug 2010, 09.00 GMT
+# Latest Revision: 22 Jul 2011, 21.00 GMT
#
#
# TODO List
@@ -27,7 +27,7 @@

"""
SuperToolTip is a class that mimics the behaviour of `wx.TipWindow` and generic tooltip
-windows, although it is a custom-drawn widget.
+windows, although it is a custom-drawn widget.


Description
@@ -77,7 +77,7 @@

SuperToolTip is distributed under the wxPython license.

-Latest Revision: Andrea Gavana @ 02 Aug 2010, 09.00 GMT
+Latest Revision: Andrea Gavana @ 22 Jul 2011, 21.00 GMT

Version 0.4

@@ -186,8 +186,8 @@
hl = line[indxStart+1:indxEnd].strip()
line = line[0:indxStart].strip()

-    return line, hl
-
+    return line, hl
+

class ToolTipWindowBase(object):
""" Base class for the different Windows and Mac implementation. """
@@ -203,11 +203,11 @@
self._spacing = 6
self._wasOnLink = False
self._hyperlinkRect, self._hyperlinkWeb = [], []
-
+
self._classParent = classParent
self._alphaTimer = wx.Timer(self, wx.ID_ANY)

-        # Bind the events
+        # Bind the events
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
@@ -216,7 +216,7 @@
self.Bind(wx.EVT_KILL_FOCUS, self.OnDestroy)
self.Bind(wx.EVT_LEFT_DOWN, self.OnDestroy)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnDestroy)
-
+

def OnPaint(self, event):
"""
@@ -227,7 +227,7 @@

# Go with double buffering...
dc = wx.BufferedPaintDC(self)
-
+
frameRect = self.GetClientRect()
x, y, width, height = frameRect
# Store the rects for the hyperlink lines
@@ -239,7 +239,7 @@
classParent.GetMiddleGradientColour(), \
classParent.GetBottomGradientColour()

-        # Get the user options for header, bitmaps etc...
+        # Get the user options for header, bitmaps etc...
drawHeader, drawFooter = classParent.GetDrawHeaderLine(), classParent.GetDrawFooterLine()
topRect = wx.Rect(frameRect.x, frameRect.y, frameRect.width, frameRect.height/2)
bottomRect = wx.Rect(frameRect.x, frameRect.y+frameRect.height/2, frameRect.width, frameRect.height/2+1)
@@ -250,7 +250,7 @@
header, headerBmp = classParent.GetHeader(), classParent.GetHeaderBitmap()
headerFont, messageFont, footerFont, hyperlinkFont = classParent.GetHeaderFont(), classParent.GetMessageFont(), \
classParent.GetFooterFont(), classParent.GetHyperlinkFont()
-
+
xPos, yPos = self._spacing, 0
bmpXPos = bmpYPos = 0
bmpHeight = textHeight = bmpWidth = 0
@@ -259,7 +259,7 @@
# We got the header bitmap
bmpHeight, bmpWidth = headerBmp.GetHeight(), headerBmp.GetWidth()
bmpXPos = self._spacing
-
+
if header:
# We got the header text
dc.SetFont(headerFont)
@@ -280,7 +280,7 @@
dc.DrawLine(self._spacing, yPos+self._spacing, width-self._spacing, yPos+self._spacing)

# Get the big body image (if any)
-        embeddedImage = classParent.GetBodyImage()
+        embeddedImage = classParent.GetBodyImage()
bmpWidth = bmpHeight = -1
if embeddedImage and embeddedImage.IsOk():
bmpWidth, bmpHeight = embeddedImage.GetWidth(), embeddedImage.GetHeight()
@@ -292,7 +292,7 @@
yText = yPos
normalText = wx.SystemSettings_GetColour(wx.SYS_COLOUR_MENUTEXT)
hyperLinkText = wx.BLUE
-
+
for indx, line in enumerate(lines):
# Loop over all the lines in the message
isLink = False
@@ -318,7 +318,7 @@

xText = (bmpWidth > 0 and [bmpWidth+2*self._spacing] or [self._spacing])[0]
yText += textHeight/2+self._spacing
-
+
dc.DrawText(line, xText, yText)
if isLink:
# Store the hyperlink rectangle and link
@@ -334,21 +334,21 @@
toAdd = self._spacing
else:
yPos += messageHeight + 2*self._spacing
-
+
yText = max(messageHeight, bmpHeight+2*self._spacing)
if embeddedImage and embeddedImage.IsOk():
# Draw the main body image
dc.DrawBitmap(embeddedImage, self._spacing, messagePos, True)
-
+
footer, footerBmp = classParent.GetFooter(), classParent.GetFooterBitmap()
bmpHeight = bmpWidth = textHeight = textWidth = 0
bmpXPos = bmpYPos = 0
-
+
if footerBmp and footerBmp.IsOk():
# Got the footer bitmap
bmpHeight, bmpWidth = footerBmp.GetHeight(), footerBmp.GetWidth()
bmpXPos = self._spacing
-
+
if footer:
# Got the footer text
dc.SetFont(footerFont)
@@ -376,10 +376,10 @@

:param `event`: a `wx.EraseEvent` event to be processed.

-        :note: This method is intentionally empty to reduce flicker.
+        :note: This method is intentionally empty to reduce flicker.
"""

-        # This is intentionally empty to reduce flicker
+        # This is intentionally empty to reduce flicker
pass


@@ -428,7 +428,7 @@
# We haven't clicked a link
self.Destroy()
return
-
+
x, y = event.GetPosition()
for indx, rect in enumerate(self._hyperlinkRect):
if rect.Contains((x, y)):
@@ -456,12 +456,12 @@
if self._alphaTimer.IsRunning():
return

-        # Calculate starting alpha value and its step
+        # Calculate starting alpha value and its step
self.amount = (isShow and [0] or [255])[0]
self.delta = (isShow and [5] or [-5])[0]
# Start the timer
self._alphaTimer.Start(30)
-
+

def SetFont(self, font):
"""
@@ -474,14 +474,14 @@
self._classParent.InitFont()
self.Invalidate()

-
+
def Invalidate(self):
""" Invalidate L{SuperToolTip} size and repaint it. """

if not self._classParent.GetMessage():
# No message yet...
return
-
+
self.CalculateBestSize()
self.Refresh()

@@ -499,7 +499,7 @@
if not _libimported:
# No Mark Hammond's win32all extension
return
-
+
if wx.Platform != "__WXMSW__":
# This works only on Windows XP
return
@@ -512,12 +512,12 @@
if hasattr(win32gui, "CreateRoundRectRgn"):
rgn = win32gui.CreateRoundRectRgn(0, 0, size.x, size.y, 9, 9)
win32gui.SetWindowRgn(hwnd, rgn, True)
-
+
CS_DROPSHADOW = 0x00020000
# Load the user32 library
if not hasattr(self, "_winlib"):
self._winlib = win32api.LoadLibrary("user32")
-
+
csstyle = win32api.GetWindowLong(hwnd, win32con.GCL_STYLE)
if drop:
if csstyle & CS_DROPSHADOW:
@@ -527,7 +527,7 @@
else:
csstyle &= ~CS_DROPSHADOW

-        # Drop the shadow underneath the window
+        # Drop the shadow underneath the window
GCL_STYLE= -26
cstyle= win32gui.GetClassLong(hwnd, GCL_STYLE)
if drop:
@@ -546,7 +546,7 @@

# Increase (or decrease) the alpha channel
self.amount += self.delta
-
+
if self.amount > 255 or self.amount < 0:
# We're done, stop the timer
self._alphaTimer.Stop()
@@ -555,7 +555,7 @@
self.Destroy()
return

-        # Make the SuperToolTip more or less transparent
+        # Make the SuperToolTip more or less transparent
self.MakeWindowTransparent(self.amount)
if not self.IsShown():
self.Show()
@@ -574,30 +574,30 @@
if not _libimported:
# No way, only Windows XP with Mark Hammond's win32all
return
-
+
# this API call is not in all SDKs, only the newer ones, so
# we will runtime bind this
if wx.Platform != "__WXMSW__":
return
-
+
hwnd = self.GetHandle()

-        if not hasattr(self, "_winlib"):
+        if not hasattr(self, "_winlib"):
self._winlib = win32api.LoadLibrary("user32")
-
+
pSetLayeredWindowAttributes = win32api.GetProcAddress(self._winlib,
"SetLayeredWindowAttributes")
-
+
if pSetLayeredWindowAttributes == None:
return
-
+
exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
if 0 == (exstyle & 0x80000):
-            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000)
-
+            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000)
+
winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
-
-
+
+
def CalculateBestSize(self):
""" Calculates the L{SuperToolTip} window best size. """

@@ -635,7 +635,7 @@
messageHeight = 0
textSpacing = (bmpWidth and [3*self._spacing] or [2*self._spacing])[0]
lines = classParent.GetMessage().split("\n")
-
+
for line in lines:
if line.startswith("</b>"):      # is a bold line
font = MakeBold(messageFont)
@@ -667,7 +667,7 @@
footer, footerBmp = classParent.GetFooter(), classParent.GetFooterBitmap()
textHeight, bmpHeight = 0, 0

-        # See the OnPaint method for explanations...
+        # See the OnPaint method for explanations...
if footer:
dc.SetFont(footerFont)
textWidth, textHeight = dc.GetTextExtent(footer)
@@ -690,7 +690,7 @@
# Handle Mac and Windows/GTK differences...

if wx.Platform == "__WXMAC__":
-
+
class ToolTipWindow(wx.Frame, ToolTipWindowBase):
""" Popup window that works on wxMac. """

@@ -701,7 +701,7 @@
:param `parent`: the L{SuperToolTip} parent widget;
:param `classParent`: the L{SuperToolTip} class object.
"""
-
+
wx.Frame.__init__(self, parent, style=wx.NO_BORDER|wx.FRAME_FLOAT_ON_PARENT|wx.FRAME_NO_TASKBAR|wx.POPUP_WINDOW)
# Call the base class
ToolTipWindowBase.__init__(self, parent, classParent)
@@ -713,7 +713,7 @@
A simple `wx.PopupWindow` that holds fancy tooltips.
Not available on Mac as `wx.PopupWindow` is not implemented there.
"""
-
+
def __init__(self, parent, classParent):
"""
Default class constructor.
@@ -726,7 +726,7 @@
# Call the base class
ToolTipWindowBase.__init__(self, parent, classParent)

-
+
class SuperToolTip(object):
"""
The main class for L{SuperToolTip}, which holds all the methods
@@ -745,10 +745,10 @@
:param `footer`: the footer text;
:param `footerBmp`: the footer bitmap.
"""
-
+
self._superToolTip = None

-        # Set all the initial options
+        # Set all the initial options
self.SetMessage(message)
self.SetBodyImage(bodyImage)
self.SetHeader(header)
@@ -762,15 +762,15 @@
self._bottomLine = False

self.InitFont()
-
-        # Get the running applications
+
+        # Get the running applications
self._runningApp = wx.GetApp()
self._runningApp.__superToolTip = True

# Build a couple of timers...
self._startTimer = wx.PyTimer(self.OnStartTimer)
self._endTimer = wx.PyTimer(self.OnEndTimer)
-
+
self.SetStartDelay()
self.SetEndDelay()
self.ApplyStyle("XP Blue")
@@ -780,23 +780,23 @@
"""
Sets the target window for L{SuperToolTip}.

-        :param `widget`: the widget to which L{SuperToolTip} is associated.
+        :param `widget`: the widget to which L{SuperToolTip} is associated.
"""

self._widget = widget
-
+
self._widget.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
self._widget.Bind(wx.EVT_LEAVE_WINDOW, self.OnWidgetLeave)
-
+

def GetTarget(self):
""" Returns the target window for L{SuperToolTip}. """
-
+
if not hasattr(self, "_widget"):
raise Exception("\nError: the widget target for L{SuperToolTip} has not been set.")

return self._widget
-
+

def SetStartDelay(self, delay=1):
"""
@@ -804,15 +804,15 @@

:param `delay`: the delay in seconds.
"""
-
-        self._startDelayTime = float(delay)
-
+
+        self._startDelayTime = float(delay)
+

def GetStartDelay(self):
""" Returns the tim delay (in seconds) after which the L{SuperToolTip} is created."""

return self._startDelayTime
-
+

def SetEndDelay(self, delay=1e6):
"""
@@ -820,15 +820,15 @@

:param `delay`: the delay in seconds.
"""
-
+
self._endDelayTime = float(delay)
-
+

def GetEndDelay(self):
""" Returns the delay time (in seconds) after which the L{SuperToolTip} is destroyed."""
-
+
return self._endDelayTime
-
+

def OnWidgetEnter(self, event):
"""
@@ -836,7 +836,7 @@

:param `event`: a `wx.MouseEvent` event to be processed.
"""
-
+
if self._superToolTip:
# Not yet created
return
@@ -853,7 +853,7 @@
self._startTimer.Start(self._startDelayTime*1000)
event.Skip()

-
+
def OnWidgetLeave(self, event):
"""
Handles the ``wx.EVT_LEAVE_WINDOW`` event for the target widgets.
@@ -864,7 +864,7 @@
pos = wx.GetMousePosition()
realPos = self._widget.ScreenToClient(pos)
rect = self._widget.GetClientRect()
-
+
if rect.Contains(realPos):
# We get fake leave events...
event.Skip()
@@ -879,18 +879,23 @@

self._startTimer.Stop()
self._endTimer.Stop()
-
+
event.Skip()

def GetTipWindow(self):
""" Return the TipWindow, will return None if not yet created """
-
+
return self._superToolTip
-
+

def OnStartTimer(self):
""" The creation time has expired, create the L{SuperToolTip}. """

+        # target widget might already be destroyed
+        if not self._widget:
+            self._startTimer.Stop()
+            return
+
tip = ToolTipWindow(self._widget, self)
self._superToolTip = tip
self._superToolTip.CalculateBestSize()
@@ -901,10 +906,10 @@
self._superToolTip.StartAlpha(True)
else:
self._superToolTip.Show()
-
+
self._startTimer.Stop()
self._endTimer.Start(self._endDelayTime*1000)
-
+

def OnEndTimer(self):
""" The show time for L{SuperToolTip} has expired, destroy the L{SuperToolTip}. """
@@ -914,15 +919,15 @@
self._superToolTip.StartAlpha(False)
else:
self._superToolTip.Destroy()
-
+
self._endTimer.Stop()
-
+

def DoShowNow(self):
""" Create the L{SuperToolTip} immediately. """

if self._superToolTip:
-            # need to destroy it if already exists,
+            # need to destroy it if already exists,
# otherwise we might end up with many of them
self._superToolTip.Destroy()

@@ -931,15 +936,15 @@
self._superToolTip.CalculateBestSize()
self._superToolTip.SetPosition(wx.GetMousePosition())
self._superToolTip.DropShadow(self.GetDropShadow())
-
+
# need to stop this, otherwise we get into trouble when leaving the window
self._startTimer.Stop()
-
+
if self.GetUseFade():
self._superToolTip.StartAlpha(True)
else:
self._superToolTip.Show()
-
+
self._endTimer.Start(self._endDelayTime*1000)


@@ -950,11 +955,11 @@
# Unbind the events!
self._widget.Unbind(wx.EVT_LEAVE_WINDOW)
self._widget.Unbind(wx.EVT_ENTER_WINDOW)
-
+
self._superToolTip.Destroy()
del self._superToolTip
self._superToolTip = None
-
+

def SetHeaderBitmap(self, bmp):
"""
@@ -972,7 +977,7 @@
""" Returns the header bitmap. """

return self._headerBmp
-
+

def SetHeader(self, header):
"""
@@ -981,7 +986,7 @@
:param `header`: the header text to display.
"""

-        self._header = header
+        self._header = header
if self._superToolTip:
self._superToolTip.Invalidate()

@@ -990,7 +995,7 @@
""" Returns the header text. """

return self._header
-
+

def SetDrawHeaderLine(self, draw):
"""
@@ -1009,7 +1014,7 @@
""" Returns whether the separator line after the header is drawn or not. """

return self._topLine
-
+

def SetBodyImage(self, bmp):
"""
@@ -1022,11 +1027,11 @@
if self._superToolTip:
self._superToolTip.Invalidate()

-
+
def GetBodyImage(self):
""" Returns the main body bitmap used in L{SuperToolTip}. """

-        return self._embeddedImage
+        return self._embeddedImage


def SetDrawFooterLine(self, draw):
@@ -1046,7 +1051,7 @@
""" Returns whether the separator line before the footer is drawn or not. """

return self._bottomLine
-
+

def SetFooterBitmap(self, bmp):
"""
@@ -1063,7 +1068,7 @@
def GetFooterBitmap(self):
""" Returns the footer bitmap. """

-        return self._footerBmp
+        return self._footerBmp


def SetFooter(self, footer):
@@ -1073,17 +1078,17 @@
:param `footer`: the footer text to display.
"""

-        self._footer = footer
+        self._footer = footer
if self._superToolTip:
self._superToolTip.Invalidate()

-
+
def GetFooter(self):
""" Returns the footer text. """

return self._footer

-
+
def SetMessage(self, message):
"""
Sets the main body message for L{SuperToolTip}.
@@ -1125,7 +1130,7 @@
if self._superToolTip:
self._superToolTip.Refresh()

-
+
def SetBottomGradientColour(self, colour):
"""
Sets the bottom gradient colour for L{SuperToolTip}.
@@ -1148,7 +1153,7 @@
self._textColour = colour
if self._superToolTip:
self._superToolTip.Refresh()
-
+

def GetTopGradientColour(self):
""" Returns the top gradient colour. """
@@ -1161,18 +1166,18 @@

return self._middleColour

-
+
def GetBottomGradientColour(self):
""" Returns the bottom gradient colour. """

return self._bottomColour
-
+

def GetTextColour(self):
""" Returns the text colour. """

return self._textColour
-
+

SetTopGradientColor = SetTopGradientColour
SetMiddleGradientColor = SetMiddleGradientColour
@@ -1182,7 +1187,7 @@
GetBottomGradientColor = GetBottomGradientColour
SetTextColor = SetTextColour
GetTextColor = GetTextColour
-
+

def InitFont(self):
""" Initalizes the fonts for L{SuperToolTip}. """
@@ -1234,7 +1239,7 @@
self._footerFont = font
if self._superToolTip:
self._superToolTip.Invalidate()
-
+

def SetHyperlinkFont(self, font):
"""
@@ -1247,7 +1252,7 @@
self._hyperlinkFont = font
if self._superToolTip:
self._superToolTip.Invalidate()
-
+

def GetMessageFont(self):
""" Returns the font used in the main body message. """
@@ -1264,21 +1269,21 @@
def GetFooterFont(self):
""" Returns the font used for the footer text. """

-        return self._footerFont
+        return self._footerFont


def GetHyperlinkFont(self):
""" Returns the font used for the hyperlink text. """

-        return self._hyperlinkFont
-
+        return self._hyperlinkFont
+

def SetDropShadow(self, drop):
"""
Whether to draw a shadow below L{SuperToolTip} or not.

:param `drop`: ``True`` to drop a shadow below the control, ``False`` otherwise.
-
+
:note: This method is available only on Windows and requires Mark Hammond's
pywin32 package.
"""
@@ -1297,20 +1302,20 @@
"""

return self._dropShadow
-
+

def SetUseFade(self, fade):
"""
Whether to use a fade in/fade out effect or not.

:param `fade`: ``True`` to use a fade in/fade out effect, ``False`` otherwise.
-
+
:note: This method is available only on Windows and requires Mark Hammond's
pywin32 package.
"""
-
+
self._useFade = fade
-
+

def GetUseFade(self):
"""
@@ -1322,7 +1327,7 @@

return self._useFade

-
+
def ApplyStyle(self, style):
"""
Applies none of the predefined styles.
@@ -1343,7 +1348,7 @@
if self._superToolTip:
self._superToolTip.Refresh()

-
+
def EnableTip(self, enable=True):
"""
Globally (application-wide) enables/disables L{SuperToolTip}.
Tree

Table Of Contents

Previous topic

supertooltip functions

Next topic

SVN Revision 68881 For supertooltip