mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-29 06:32:40 -06:00
1338 lines
46 KiB
Python
1338 lines
46 KiB
Python
# --------------------------------------------------------------------------------- #
|
|
# ZoomBar wxPython IMPLEMENTATION
|
|
#
|
|
# Andrea Gavana @ 19 Dec 2012, 21.00 GMT
|
|
#
|
|
#
|
|
# For all kind of problems, requests of enhancements and bug reports, please write
|
|
# to me at:
|
|
#
|
|
# andrea.gavana@gmail.com
|
|
# andrea.gavana@maerskoil.com
|
|
#
|
|
# Or, obviously, to the wxPython mailing list!!!
|
|
#
|
|
# Tags: phoenix-port, documented, unittest, py3-port
|
|
#
|
|
# End of comments
|
|
# --------------------------------------------------------------------------------- #
|
|
|
|
"""
|
|
:class:`ZoomBar` is a class that *appoximatively* mimics the behaviour of the Mac Dock,
|
|
inside a :class:`Panel`.
|
|
|
|
|
|
Description
|
|
===========
|
|
|
|
:class:`ZoomBar` is a class that *appoximatively* mimics the behaviour of the Mac Dock,
|
|
inside a :class:`Panel`.
|
|
|
|
Once you hover mouse over the :class:`ZoomBar` correct button will bubble up, grow to
|
|
predefined size, so you can easily see the button you are about to click and
|
|
have larger area to click. Difference this makes is amazing.
|
|
|
|
The buttons are able to be zoomed from the bottom up (bottom fixed) as well
|
|
as to zoom from a central point. Also the container is able to move the
|
|
remaining buttons around the zoomed button.
|
|
|
|
|
|
Usage
|
|
=====
|
|
|
|
Usage example::
|
|
|
|
import os
|
|
import random
|
|
import glob
|
|
|
|
import wx
|
|
import wx.lib.agw.zoombar as ZB
|
|
|
|
class MyFrame(wx.Frame):
|
|
|
|
def __init__(self, parent):
|
|
|
|
wx.Frame.__init__(self, parent, -1, "ZoomBar Demo")
|
|
|
|
panel = wx.Panel(self)
|
|
|
|
bar = ZB.ZoomBar(panel, -1)
|
|
|
|
standard = glob.glob(bitmapDir + "/*96.png")
|
|
reflections = glob.glob(bitmapDir + "/*96Flip40.png")
|
|
|
|
separatorImage = bitmapDir + "/separator.gif"
|
|
separatorReflection = bitmapDir + "/separatorFlip.png"
|
|
count = 0
|
|
|
|
for std, ref in zip(standard, reflections):
|
|
if random.randint(0, 1) == 1 and count > 0:
|
|
sep1 = wx.Bitmap(separatorImage, wx.BITMAP_TYPE_GIF)
|
|
sep2 = wx.Bitmap(separatorReflection, wx.BITMAP_TYPE_PNG)
|
|
bar.AddSeparator(sep1, sep2)
|
|
|
|
bname = os.path.split(std)[1][0:-6]
|
|
bar.AddButton(wx.Bitmap(std, wx.BITMAP_TYPE_PNG), wx.Bitmap(ref, wx.BITMAP_TYPE_PNG), bname)
|
|
count += 1
|
|
|
|
bar.ResetSize()
|
|
|
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
sizer.Add(bar, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 15)
|
|
panel.SetSizer(sizer)
|
|
|
|
|
|
# our normal wxApp-derived class, as usual
|
|
|
|
app = wx.App(0)
|
|
|
|
frame = MyFrame(None)
|
|
app.SetTopWindow(frame)
|
|
frame.Show()
|
|
|
|
app.MainLoop()
|
|
|
|
|
|
Supported Platforms
|
|
===================
|
|
|
|
:class:`ZoomBar` has been tested on the following platforms:
|
|
* Windows (Windows XP).
|
|
|
|
|
|
Window Styles
|
|
=============
|
|
|
|
`No particular window styles are available for this class.`
|
|
|
|
|
|
Events Processing
|
|
=================
|
|
|
|
This class processes the following events:
|
|
|
|
============================== ==================================================
|
|
Event Name Description
|
|
============================== ==================================================
|
|
``EVT_ZOOMBAR`` Process a ``wxEVT_ZOOMBAR`` event, when a :class:`ZoomBar` button is clicked.
|
|
============================== ==================================================
|
|
|
|
|
|
License And Version
|
|
===================
|
|
|
|
:class:`ZoomBar` is distributed under the wxPython license.
|
|
|
|
Latest Revision: Andrea Gavana @ 19 Dec 2012, 21.00 GMT
|
|
|
|
Version 0.1
|
|
|
|
"""
|
|
|
|
import wx
|
|
import sys
|
|
|
|
import wx.lib.six as six
|
|
|
|
from wx.lib.embe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eXl/u/dZAfNPYMNYM2ZRsnA2sCSE60SYcANIgqiaLV6SqJRY+proNnWJEu"
|
|
"1vWeiiFDLfzQew/EWHKrCdvzG04Ws9lsD3Tk13Y5YcgP/ltH11JeJthV1x/5rMdfz9Vr89Z1"
|
|
"ZNFzSMqua9QPgRmvHb22xkeJ02pnntPplNbr9SO3rPQvduvfU8vKPTShPOIVK5U448XMbDzn"
|
|
"1x6AQXnUmkcU37I5KwN0dFyIdLP4WLInk8m1E8JIx/mrr75K9+/fp5OTE3rw4AEdHx/TxcXF"
|
|
"/ttUqBpEAS569l5nJjkySI2o9ioG4AUXz4ksvpYRj6ieM/JRW8Z5UILyAnSkd1Uva/0jnpZs"
|
|
"z3EtAGDtnf65cn7NDs0JQwIcDWJ0oZApFrIgNAMCI9/I+L/Ht0KVSjbD3xsj110nuhYb9cbz"
|
|
"nnl8W5JsZCt6vP4BQCYNciTwQXKs95b/jwCoEbDOghqr3dt7r13riA4OPD/K7mFGj4yOUZHj"
|
|
"Uc8pj9fOvvHlL3+ZHj58SP/yi5/v5svlkv7yl7/QRx99tAc4y+XykUDpLWZm0SsbkFmAStCN"
|
|
"+HgG3VLhozbU3pLELYqA0iGATva6Nf8Kn8patACXnj4ZkJMF7xLgyJMc69srzAMl4eyJiDe3"
|
|
"EUnFoyrYyYDfSM6h5yRlVJIlX4vGegBIt3uAB1HWTtGD++kTHQS6szHfSu6H3MMIwCIdDuFP"
|
|
"Uo/oA8feay2/FzzyfvfmFO/wBPXzZMo4OZlM6Otf/zo9fPiQXnzxRZr/9re/pbfeeotOT0/3"
|
|
"t6ZQgOw5ZqouRuviRcgSnSSMoh4QMFoXKW8k79ZA0xOQRgezx5HgKoTW00pk1a/k3gSxjXjJ"
|
|
"YXRw/LRQa2LLjIv8rgXY9xJK8jrRZm3007qnEd1EPDnkej5OMCmpchoeEcfP9XpNRET/Ax6j"
|
|
"kIck2UJrAAAAAElFTkSuQmCC")
|
|
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# ZoomBar events and binding for handling them
|
|
# ----------------------------------------------------------------------------
|
|
|
|
wxEVT_ZOOMBAR = wx.NewEventType()
|
|
EVT_ZOOMBAR = wx.PyEventBinder(wxEVT_ZOOMBAR, 1)
|
|
""" Process a `wxEVT_ZOOMBAR` event, when a :class:`ZoomBar` button is clicked. """
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
def MakeDisabledBitmap(original):
|
|
"""
|
|
Creates a disabled-looking bitmap starting from the input one.
|
|
|
|
:param `original`: an instance of :class:`Bitmap` to be greyed-out.
|
|
"""
|
|
|
|
img = original.ConvertToImage()
|
|
return wx.Bitmap(img.ConvertToGreyscale())
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
class ZoomBarImage(object):
|
|
"""
|
|
This simple class holds information about a :class:`ZoomBar` button, such as normal
|
|
bitmaps, disabled bitmap, button label, etc...
|
|
"""
|
|
|
|
def __init__(self, parent, bitmap, disabledBmp=wx.NullBitmap, label=""):
|
|
"""
|
|
Default class constructor.
|
|
|
|
:param `parent`: the main :class:`ZoomBar` window;
|
|
:param `bitmap`: the button bitmap, an instance of :class:`Bitmap`;
|
|
:param `disabledBmp`: the button bitmap when the button is in a disabled
|
|
state;
|
|
:param `label`: the button label.
|
|
"""
|
|
|
|
self._parent = parent
|
|
self._bitmap = bitmap
|
|
|
|
if not disabledBmp.IsOk():
|
|
disabledBmp = MakeDisabledBitmap(bitmap)
|
|
|
|
self._disabledBmp = disabledBmp
|
|
self._label = label
|
|
|
|
self._height = 36
|
|
self._width = 36
|
|
|
|
self._oldnx = 0
|
|
self._oldLeft = 0
|
|
self._oldTop = 0
|
|
self._oldWidth = 0
|
|
self._oldBottom = 0
|
|
self._oldHeight = 0
|
|
self._vCenter = 0
|
|
self._hCenter = 0
|
|
self._oldInc = -six.MAXSIZE
|
|
self._isSeparator = False
|
|
self._enabled = True
|
|
|
|
# Larger number gives a greater zoom effect
|
|
self._zoomFactor = 3
|
|
|
|
# Whether this is a reflection or not
|
|
self._isAReflection = False
|
|
|
|
self._cachedBitmaps = {}
|
|
self._cachedDisabledBitmaps = {}
|
|
|
|
|
|
def SetZoomFactor(self, zoom):
|
|
"""
|
|
Sets the zoom factor for the button. Larger number gives a greater zoom
|
|
effect.
|
|
|
|
:param `zoom`: a floating point number, greater than or equal to 1.0.
|
|
"""
|
|
|
|
self._zoomFactor = zoom
|
|
|
|
|
|
def SetCenterZoom(self, center=True):
|
|
"""
|
|
Sets to zoom from the center.
|
|
|
|
:param `center`: if ``True`` button zooms upwards.
|
|
"""
|
|
|
|
self._centerZoom = center
|
|
|
|
|
|
def ZoomImage(self, nxcoord):
|
|
"""
|
|
Zooms the button bitmap depending on the mouse x position.
|
|
|
|
:param `nxcoord`: the mouse x position relative to the button center.
|
|
"""
|
|
|
|
if nxcoord < self._vCenter:
|
|
inc = int(((nxcoord - self._oldLeft)*10.0)/(self._oldWidth/2.0)) + 1
|
|
else:
|
|
inc = int(((self._oldLeft + self._oldWidth - nxcoord)*10.0)/(self._oldWidth/2)) + 1
|
|
|
|
if self._isSeparator:
|
|
return False
|
|
|
|
if abs(inc - self._oldInc) < 2:
|
|
return False
|
|
|
|
self._oldInc = inc
|
|
|
|
if not self._isAReflection:
|
|
# original button
|
|
inc = inc*self._zoomFactor
|
|
self._width = self._oldWidth + inc
|
|
self._left = self._vCenter - self._width/2
|
|
self._height = self._oldHeight + inc
|
|
self._top = self._oldBottom - self._height
|
|
|
|
else:
|
|
# the reflection
|
|
self._height = self._oldHeight + inc
|
|
self._width = self._oldWidth + inc
|
|
self._top = self._top + self._height
|
|
|
|
self._oldnx = nxcoord
|
|
return True
|
|
|
|
|
|
def SetSize(self, width, height):
|
|
"""
|
|
Sets the button size.
|
|
|
|
:param `width`: the button width;
|
|
:param `height`: the button height.
|
|
"""
|
|
|
|
self._width = width
|
|
self._height = height
|
|
|
|
|
|
def GetPosition(self):
|
|
""" Returns the button position. """
|
|
|
|
return wx.Point(self._left, self._top)
|
|
|
|
|
|
def GetSize(self):
|
|
""" Returns the button size. """
|
|
|
|
return wx.Size(self._width, self._height)
|
|
|
|
|
|
def GetBitmap(self):
|
|
"""
|
|
Returns the button bitmap, which may be a scaled up version of the original
|
|
bitmap is the button is being zoomed.
|
|
"""
|
|
|
|
if self._isAReflection:
|
|
return self._paintBitmap
|
|
|
|
if self._enabled:
|
|
return self._cachedBitmaps[self._width]
|
|
|
|
return self._cachedDisabledBitmaps[self._width]
|
|
|
|
|
|
def SetupProps(self, buttonSize):
|
|
"""
|
|
Set up the button position and size.
|
|
|
|
:param `buttonSize`: the button original size (not zoomed), in pixels.
|
|
"""
|
|
|
|
self._width = self._oldWidth = buttonSize
|
|
self._height = self._oldHeight = buttonSize
|
|
|
|
self._oldLeft = self._left
|
|
self._oldTop = self._top
|
|
self._vCenter = self._oldLeft + int(self._oldWidth/2.0)
|
|
self._hCenter = self._oldTop + int(self._oldHeight/2.0)
|
|
self._oldBottom = self._top + self._height
|
|
|
|
if self._isAReflection:
|
|
img = self._bitmap.ConvertToImage()
|
|
img = img.Scale(self._width, self._height, wx.IMAGE_QUALITY_HIGH)
|
|
self._paintBitmap = img.ConvertToBitmap()
|
|
|
|
|
|
def GetLabel(self):
|
|
""" Returns the button label (if any). """
|
|
|
|
return self._label
|
|
|
|
|
|
def SetLabel(self, label):
|
|
"""
|
|
Sets the button label.
|
|
|
|
:param `label`: a string specifying the button label. May be an empty string
|
|
for no label.
|
|
"""
|
|
|
|
self._label = label
|
|
|
|
|
|
def IsZoomed(self):
|
|
""" Returns ``True`` if the button is zoomed, ``False`` otherwise. """
|
|
|
|
return self._width/float(self._oldWidth) >= 1.25
|
|
|
|
|
|
def LoopScales(self, size):
|
|
"""
|
|
Caches the bitmaps at various zoom levels to avoid calling every time
|
|
`image.Scale` on the button bitmap.
|
|
|
|
:param `size`: the original button size, in pixels.
|
|
"""
|
|
|
|
if self._isAReflection:
|
|
return
|
|
|
|
for scale in range(size-10*self._zoomFactor, size+15*self._zoomFactor, self._zoomFactor):
|
|
if scale in self._cachedBitmaps or scale <= 0:
|
|
continue
|
|
|
|
img = self._bitmap.ConvertToImage()
|
|
img = img.Scale(scale, scale, wx.IMAGE_QUALITY_HIGH)
|
|
bmp = img.ConvertToBitmap()
|
|
self._cachedBitmaps[scale] = bmp
|
|
|
|
img = self._disabledBmp.ConvertToImage()
|
|
img = img.Scale(scale, scale, wx.IMAGE_QUALITY_HIGH)
|
|
bmp = img.ConvertToBitmap()
|
|
self._cachedDisabledBitmaps[scale] = bmp
|
|
|
|
|
|
def Enable(self, enable=True):
|
|
"""
|
|
Enables/disables a button.
|
|
|
|
:param `enable`: ``True`` to enable a button, ``False`` to disable it.
|
|
"""
|
|
|
|
self._enabled = enable
|
|
|
|
|
|
def IsEnabled(self):
|
|
""" Returns ``True`` if the button is enabled, ``False`` otherwise. """
|
|
|
|
return self._enabled
|
|
|
|
|
|
class ImageBar(object):
|
|
""" This class holds the background button bar on which the buttons float. """
|
|
|
|
def __init__(self, bitmap=None):
|
|
"""
|
|
Default class constructor.
|
|
|
|
:param `bitmap`: if not ``None``, the bitmap to use as a background button
|
|
bar on which the buttons float. It should be an instance of :class:`Image`.
|
|
"""
|
|
|
|
if bitmap and bitmap.IsOk():
|
|
self._bitmap = bitmap
|
|
self._hasBitmap = bitmap
|
|
else:
|
|
self._bitmap = zoombackgrey.GetImage()
|
|
self._hasBitmap = None
|
|
|
|
self._left = 23
|
|
self._top = 53
|
|
self._startColour = wx.Colour(97, 97, 97)
|
|
self._endColour = wx.Colour(97, 97, 97)
|
|
|
|
|
|
def GetPosition(self):
|
|
""" Returns the position of :class:`ImageBar`, as a :class:`Point`. """
|
|
|
|
return wx.Point(self._left, self._top)
|
|
|
|
|
|
def GetSize(self):
|
|
""" Returns the size of :class:`ImageBar`, as a :class:`Size`. """
|
|
|
|
return wx.Size(self._bitmap.GetWidth(), self._bitmap.GetHeight())
|
|
|
|
|
|
def GetBitmap(self):
|
|
""" Returns the background button bar on which the buttons float. """
|
|
if isinstance(self._bitmap, wx.Image):
|
|
return wx.Bitmap(self._bitmap)
|
|
return self._bitmap
|
|
|
|
|
|
def SetPosition(self, xpos, ypos):
|
|
"""
|
|
Sets the position of :class:`ImageBar`.
|
|
|
|
:param `xpos`: the `x` position of the bar;
|
|
:param `ypos`: the `y` position of the bar.
|
|
"""
|
|
|
|
self._left = xpos
|
|
self._top = ypos
|
|
|
|
|
|
def SetSize(self, xSize, ySize):
|
|
"""
|
|
Sets the size of :class:`ImageBar`.
|
|
|
|
:param `xSize`: the width of the bar, in pixels;
|
|
:param `ySize`: the height of the bar, in pixels.
|
|
"""
|
|
|
|
self.SetBarColour(self._startColour, xSize, ySize)
|
|
|
|
|
|
def SetBarColour(self, colour, xSize=None, ySize=None):
|
|
"""
|
|
Sets the background button bar colour.
|
|
|
|
:param `colour`: an instance of :class:`Colour`;
|
|
:param `xSize`: if not ``None``, the new :class:`ImageBar` width;
|
|
:param `ySize`: if not ``None``, the new :class:`ImageBar` height.
|
|
"""
|
|
|
|
if not isinstance(colour, wx.Colour):
|
|
colour = wx.Colour(colour)
|
|
|
|
if self._hasBitmap:
|
|
bitmap = self._hasBitmap
|
|
else:
|
|
bitmap = zoombackgrey.GetImage()
|
|
|
|
if xSize is not None:
|
|
self._size = wx.Size(xSize, ySize)
|
|
|
|
bitmap.Rescale(self._size.width, self._size.height/2)
|
|
|
|
r1, g1, b1 = self._startColour.Red(), self._startColour.Green(), self._startColour.Blue()
|
|
r2, g2, b2 = colour.Red(), colour.Green(), colour.Blue()
|
|
|
|
fr = (r1 > 0 and [float(r2)/r1] or [0])[0]
|
|
fg = (g1 > 0 and [float(g2)/g1] or [0])[0]
|
|
fb = (b1 > 0 and [float(b2)/b1] or [0])[0]
|
|
|
|
bitmap = bitmap.AdjustChannels(fr, fg, fb, 1)
|
|
self._bitmap = bitmap.ConvertToBitmap()
|
|
self._endColour = colour
|
|
|
|
|
|
def GetBarColour(self):
|
|
""" Returns the background button bar colour. """
|
|
|
|
return self._endColour
|
|
|
|
|
|
class ZoomBarEvent(wx.PyCommandEvent):
|
|
""" Event sent from the :class:`ZoomBar` when a button is activated. """
|
|
|
|
def __init__(self, eventType, eventId=1):
|
|
"""
|
|
Default class constructor.
|
|
|
|
:param `eventType`: the event type;
|
|
:param `eventId`: the event identifier.
|
|
"""
|
|
|
|
wx.PyCommandEvent.__init__(self, eventType, eventId)
|
|
self._eventType = eventType
|
|
|
|
|
|
def SetSelection(self, selection):
|
|
"""
|
|
Sets the index of the selected button.
|
|
|
|
:param `selection`: an integer indicating the current selected button.
|
|
"""
|
|
|
|
self._selection = selection
|
|
|
|
|
|
def GetSelection(self):
|
|
""" Returns the index of the selected button. """
|
|
|
|
return self._selection
|
|
|
|
|
|
def GetLabel(self):
|
|
""" Returns the text label of the selected button. """
|
|
|
|
return self._label
|
|
|
|
|
|
def SetLabel(self, label):
|
|
"""
|
|
Sets the text label of the selected button.
|
|
|
|
:param `label`: the text label of the selected button.
|
|
"""
|
|
|
|
self._label = label
|
|
|
|
|
|
class ZoomBar(wx.Control):
|
|
"""
|
|
:class:`ZoomBar` is a class that *appoximatively* mimics the behaviour of the Mac Dock,
|
|
inside a :class:`Panel`.
|
|
|
|
This is the main class implementation.
|
|
"""
|
|
|
|
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
|
|
name="ZoomBar"):
|
|
"""
|
|
Default class constructor.
|
|
|
|
:param `parent`: the :class:`ZoomBar` parent. Must not be ``None``;
|
|
:param `id`: window identifier. A value of -1 indicates a default value;
|
|
:param `pos`: the control position. A value of (-1, -1) indicates a default position,
|
|
chosen by either the windowing system or wxPython, depending on platform;
|
|
:param `size`: the control size. A value of (-1, -1) indicates a default size,
|
|
chosen by either the windowing system or wxPython, depending on platform;
|
|
:param `name`: the window name.
|
|
"""
|
|
|
|
wx.Control.__init__(self, parent, id, pos, size, style=wx.BORDER_THEME)
|
|
|
|
# Zoom from the center. If True button zooms upwards.
|
|
self._centerZoom = False
|
|
# Whether you want reflections or not
|
|
self._showReflections = True
|
|
# Allows us to nudge a reflection closer to original
|
|
self._nudgeReflection = 0
|
|
# Extension of the reflection. BMP or PNG etc.
|
|
# Initial size of the buttons
|
|
self._buttonSize = 48
|
|
# Show labels on hovering
|
|
self._showLabels = True
|
|
# used internally
|
|
self._noResize = False
|
|
self._buttons = []
|
|
self._reflectionButtons = []
|
|
|
|
self._imgBar = ImageBar()
|
|
self._previousHit = -1
|
|
self._currentHit = -1
|
|
|
|
wx.CallLater(200, self.OnLeaveWindow, None)
|
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
|
self.Bind(wx.EVT_MOTION, self.OnMotion)
|
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveWindow)
|
|
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
|
|
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
|
|
|
|
if wx.Platform == "__WXMSW__":
|
|
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown)
|
|
|
|
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
|
|
|
|
|
|
def DoGetBestSize(self):
|
|
"""
|
|
Gets the size which best suits the window: for a control, it would be the
|
|
minimal size which doesn't truncate the control, for a panel - the same size
|
|
as it would have after a call to `Fit()`.
|
|
|
|
:note: Overridden from :class:`Control`.
|
|
"""
|
|
|
|
xSize = self._buttonSize*len(self._buttons) + len(self._buttons) + self._buttonSize
|
|
ySize = self._buttonSize*2
|
|
if self._showLabels:
|
|
dc = wx.ClientDC(self)
|
|
dummy, yextent = dc.GetTextExtent("Ajgt")
|
|
ySize += yextent
|
|
|
|
return wx.Size(xSize+50, ySize+20)
|
|
|
|
|
|
# reposition the buttons
|
|
def Reposition(self, toButton):
|
|
"""
|
|
Repositions all the buttons inside the :class:`ZoomBar`.
|
|
|
|
:param `toButton`: the button currently hovered by the mouse (and hence zoomed).
|
|
"""
|
|
|
|
nLeft = toButton._left
|
|
nRight = toButton._left + toButton._width + 1
|
|
nButton = self._buttons.index(toButton)
|
|
|
|
# do any buttons on the right
|
|
for n in range(nButton + 1, len(self._buttons)):
|
|
oButton = self._buttons[n]
|
|
oButton._left = nRight
|
|
|
|
if self._showReflections:
|
|
oButtonR = self._reflectionButtons[n]
|
|
oButtonR._left = nRight
|
|
|
|
nRight = nRight + oButton._width + 1
|
|
|
|
# Reset
|
|
nLeft = toButton._left
|
|
|
|
# now to the left
|
|
if nButton > 0:
|
|
# only for 2nd and more
|
|
for n in range(nButton-1, -1, -1):
|
|
oButton = self._buttons[n]
|
|
oButton._left = nLeft - (oButton._width + 1)
|
|
if self._showReflections:
|
|
oButtonR = self._reflectionButtons[n]
|
|
oButtonR._left = oButton._left
|
|
|
|
nLeft = oButton._left
|
|
|
|
|
|
# method to add required buttons
|
|
def AddButton(self, normalBmp, reflectionBmp=wx.NullBitmap, label="", disabledBmp=wx.NullBitmap,
|
|
disabledReflectionBmp=wx.NullBitmap):
|
|
"""
|
|
Adds a button to :class:`ZoomBar`.
|
|
|
|
:param `normalBmp`: the button main bitmap, an instance of :class:`Bitmap`;
|
|
:param `reflectionBmp`: a bitmap representing a reflection of the main bitmap,
|
|
an instance of :class:`Bitmap`;
|
|
:param `label`: the button label;
|
|
:param `disabledBmp`: the button main bitmap when the button is in a disabled
|
|
state, an instance of :class:`Bitmap`;
|
|
:param `disabledReflectionBmp`: a bitmap representing a reflection of the main bitmap,
|
|
when the button is in a disabled state, an instance of :class:`Bitmap`.
|
|
"""
|
|
|
|
button = ZoomBarImage(self, normalBmp, disabledBmp, label)
|
|
|
|
button.SetSize(self._buttonSize, self._buttonSize)
|
|
button._centerZoom = (self._showReflections and [False] or [self._centerZoom])[0]
|
|
self._buttons.append(button)
|
|
|
|
self.InitialReposition()
|
|
|
|
if self._showReflections and reflectionBmp.IsOk():
|
|
|
|
rbutton = ZoomBarImage(self, reflectionBmp, disabledReflectionBmp)
|
|
rbutton.SetSize(self._buttonSize, self._buttonSize)
|
|
rbutton._centerzoom = False
|
|
rbutton._isAReflection = True
|
|
self._reflectionButtons.append(rbutton)
|
|
|
|
return button
|
|
|
|
|
|
def AddSeparator(self, normalBmp, reflectionBmp=wx.NullBitmap):
|
|
"""
|
|
Adds a separator to :class:`ZoomBar`.
|
|
|
|
:param `normalBmp`: the separator main bitmap, an instance of :class:`Bitmap`;
|
|
:param `reflectionBmp`: a bitmap representing a reflection of the main bitmap,
|
|
an instance of :class:`Bitmap`.
|
|
"""
|
|
|
|
button = self.AddButton(normalBmp, reflectionBmp)
|
|
button._isSeparator = True
|
|
|
|
|
|
def SetZoomFactor(self, zoom):
|
|
"""
|
|
Sets the zoom factor for all the buttons. Larger number gives a greater zoom
|
|
effect.
|
|
|
|
:param `zoom`: a floating point number, greater than or equal to 1.0.
|
|
"""
|
|
|
|
if zoom < 1:
|
|
raise Exception("The zoom factor must be greater or equal to 1")
|
|
|
|
for button in self._buttons:
|
|
button._zoomFactor = zoom
|
|
|
|
self._zoomFactor = zoom
|
|
self.DoLayout()
|
|
|
|
|
|
def GetZoomFactor(self):
|
|
""" Returns the current zoom factor. """
|
|
|
|
return self._zoomFactor
|
|
|
|
|
|
def SetCenterZoom(self, center=True):
|
|
"""
|
|
Sets to zoom from the center.
|
|
|
|
:param `center`: if ``True`` button zooms upwards.
|
|
"""
|
|
|
|
self._centerZoom = center
|
|
|
|
for button in self._buttons:
|
|
button._centerZoom = (self._showReflections and [False] or [self._centerZoom])[0]
|
|
|
|
self.DoLayout()
|
|
|
|
|
|
def GetCenterZoom(self):
|
|
""" Returns ``True`` if buttons zoom upwards. """
|
|
|
|
return self._centerZoom
|
|
|
|
|
|
def SetShowReflections(self, show):
|
|
"""
|
|
Sets whether to show reflections or not.
|
|
|
|
:param `show`: ``True`` to show reflections, ``False`` otherwise.
|
|
"""
|
|
|
|
self._showReflections = show
|
|
self.DoLayout()
|
|
|
|
|
|
def GetShowReflections(self):
|
|
""" Returns ``True`` if reflections bitmap are currently shown. """
|
|
|
|
return self._showReflections
|
|
|
|
|
|
def SetShowLabels(self, show):
|
|
"""
|
|
Sets whether to show button labels or not.
|
|
|
|
:param `show`: ``True`` to show button labels, ``False`` otherwise.
|
|
"""
|
|
|
|
self._showLabels = show
|
|
self.DoLayout()
|
|
|
|
|
|
def GetShowLabels(self):
|
|
""" Returns ``True`` if button labels are currently shown. """
|
|
|
|
return self._showLabels
|
|
|
|
|
|
def SetBarColour(self, colour):
|
|
"""
|
|
Sets the background button bar colour.
|
|
|
|
:param `colour`: an instance of :class:`Colour`;
|
|
"""
|
|
|
|
self._imgBar.SetBarColour(colour)
|
|
self.Refresh()
|
|
|
|
|
|
def GetBarColour(self):
|
|
""" Returns the background button bar colour. """
|
|
|
|
return self._imgBar.GetBarColour()
|
|
|
|
|
|
def SetButtonSize(self, size):
|
|
"""
|
|
Sets the original button size.
|
|
|
|
:param `size`: the new (not-zoomed) button size, in pixels.
|
|
"""
|
|
|
|
self._buttonSize = size
|
|
self.DoLayout()
|
|
|
|
|
|
def GetButtonSize(self):
|
|
""" Returns the original (not zoomed) button size, in pixels. """
|
|
|
|
return self._buttonSize
|
|
|
|
|
|
def EnableButton(self, index, enable=True):
|
|
"""
|
|
Enables/disables the button at position `index`.
|
|
|
|
:param `index`: the index of the button to enable/disable;
|
|
:param `enable`: ``True`` to enable the button, ``False`` to disable it.
|
|
"""
|
|
|
|
if index < 0 or index >= len(self._buttons):
|
|
return False
|
|
|
|
self._buttons[index].Enable(enable)
|
|
self.Refresh()
|
|
|
|
return True
|
|
|
|
|
|
def IsButtonEnabled(self, index):
|
|
"""
|
|
Returns ``True`` if the button at position `index` is enabled, ``False``
|
|
otherwise.
|
|
|
|
:param `index`: the index of the button to check.
|
|
"""
|
|
|
|
if index < 0 or index >= len(self._buttons):
|
|
return False
|
|
|
|
return self._buttons[index].IsEnabled()
|
|
|
|
|
|
def DoLayout(self):
|
|
""" Common method to re-layout :class:`ZoomBar`. """
|
|
|
|
self.ResetSize()
|
|
self.GetContainingSizer().Layout()
|
|
self.Refresh()
|
|
|
|
|
|
def ResetSize(self):
|
|
"""
|
|
Resets all the button sizes and positions, recalculating the optimal :class:`ZoomBar`
|
|
size.
|
|
"""
|
|
|
|
xSize = self._buttonSize*len(self._buttons) + len(self._buttons) + self._buttonSize
|
|
ySize = self._buttonSize*2
|
|
|
|
self._imgBar.SetSize(xSize+self._buttonSize, ySize)
|
|
|
|
for button in self._buttons:
|
|
button.LoopScales(self._buttonSize)
|
|
|
|
if self._showLabels:
|
|
dc = wx.ClientDC(self)
|
|
dummy, yextent = dc.GetTextExtent("Ajgt")
|
|
ySize += yextent
|
|
|
|
if self._showReflections:
|
|
ySize += self._buttonSize/2
|
|
if self._centerZoom:
|
|
ySize += self._buttonSize
|
|
|
|
size = wx.Size(xSize+50, ySize)
|
|
self.SetInitialSize(size)
|
|
self.SnapToBottom(size)
|
|
|
|
|
|
# Sets up the initial buttons and sizes them from the center
|
|
def InitialReposition(self):
|
|
"""
|
|
Sets up the initial buttons and sizes them from the center.
|
|
"""
|
|
|
|
# repositions the button centrally
|
|
# odd buttons one is central - even, half by half
|
|
|
|
if not self._buttons:
|
|
return
|
|
|
|
size = self.GetSize()
|
|
oButton = self._buttons[0]
|
|
totalWidth = oButton._width*len(self._buttons) + len(self._buttons)
|
|
center = size.GetWidth()/2
|
|
nbCenter = totalWidth/2
|
|
nLeft = center - nbCenter
|
|
|
|
if self._showReflections:
|
|
nTop = self._imgBar._top - (oButton._height/2)
|
|
else:
|
|
if self._centerZoom:
|
|
nTop = size.height/2 - oButton._height/2
|
|
else:
|
|
nTop = size.height - oButton._height - 5
|
|
|
|
for oButton in self._buttons:
|
|
oButton._left = nLeft
|
|
oButton._top = nTop
|
|
oButton.SetupProps(self._buttonSize)
|
|
nLeft = nLeft + oButton._width+1
|
|
|
|
# And the reflection if any
|
|
if self._showReflections:
|
|
nLeft = center - nbCenter
|
|
nudge = self._nudgeReflection
|
|
for oButton in self._reflectionButtons:
|
|
oButton._left = nLeft
|
|
oButton._top = (nTop + oButton._height - 2) - nudge
|
|
oButton.SetupProps(self._buttonSize)
|
|
nLeft = nLeft + oButton._width + 1
|
|
|
|
|
|
def OnLeaveWindow(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_LEAVE_WINDOW`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`MouseEvent` event to be processed.
|
|
"""
|
|
|
|
if self.GetScreenRect().Contains(wx.GetMousePosition()):
|
|
return
|
|
|
|
for button in self._buttons:
|
|
button.SetSize(self._buttonSize, self._buttonSize)
|
|
|
|
self.InitialReposition()
|
|
self.Refresh()
|
|
|
|
|
|
def OnSize(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_SIZE`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`SizeEvent` event to be processed.
|
|
"""
|
|
|
|
self.SnapToBottom(event.GetSize())
|
|
self.Refresh()
|
|
event.Skip()
|
|
|
|
|
|
def SnapToBottom(self, size):
|
|
"""
|
|
Snaps the background button bar bitmap and all the buttons to the bottom
|
|
of :class:`ZoomBar`.
|
|
|
|
:param `size`: the current :class:`ZoomBar` size.
|
|
"""
|
|
|
|
backgroundSize = self._imgBar.GetSize()
|
|
xPos = (size.width - backgroundSize.width)/2
|
|
yPos = (size.height - backgroundSize.height)
|
|
|
|
self._imgBar.SetPosition(xPos, yPos)
|
|
self.InitialReposition()
|
|
|
|
|
|
def OnPaint(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_PAINT`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`PaintEvent` event to be processed.
|
|
"""
|
|
|
|
dc = wx.AutoBufferedPaintDC(self)
|
|
|
|
dc.SetBackground(wx.WHITE_BRUSH)
|
|
dc.Clear()
|
|
|
|
background = self._imgBar.GetBitmap()
|
|
pos = self._imgBar.GetPosition()
|
|
|
|
dc.DrawBitmap(background, pos.x, pos.y, True)
|
|
|
|
if not self._buttons:
|
|
return
|
|
|
|
self.DrawButtons(dc)
|
|
self.DrawReflections(dc)
|
|
self.DrawLabels(dc)
|
|
|
|
|
|
def DrawButtons(self, dc):
|
|
"""
|
|
Draws all the main button bitmaps on the :class:`ZoomBar` client window.
|
|
|
|
:param `dc`: an instance of :class:`DC`.
|
|
"""
|
|
|
|
for button in self._buttons:
|
|
pos = button.GetPosition()
|
|
bitmap = button.GetBitmap()
|
|
|
|
dc.DrawBitmap(bitmap, pos.x, pos.y, True)
|
|
|
|
|
|
def DrawReflections(self, dc):
|
|
"""
|
|
Draws all the reflection button bitmaps on the :class:`ZoomBar` client window.
|
|
|
|
:param `dc`: an instance of :class:`DC`.
|
|
"""
|
|
|
|
if self._showReflections:
|
|
for button in self._reflectionButtons:
|
|
pos = button.GetPosition()
|
|
bitmap = button.GetBitmap()
|
|
|
|
dc.DrawBitmap(bitmap, pos.x, pos.y, True)
|
|
|
|
|
|
def DrawLabels(self, dc):
|
|
"""
|
|
Draws all the button labels on the :class:`ZoomBar` client window.
|
|
|
|
:param `dc`: an instance of :class:`DC`.
|
|
"""
|
|
|
|
if not self._showLabels:
|
|
return
|
|
|
|
dc.SetBrush(wx.WHITE_BRUSH)
|
|
dc.SetPen(wx.BLACK_PEN)
|
|
|
|
for button in self._buttons:
|
|
if not button.IsZoomed():
|
|
continue
|
|
label = button.GetLabel()
|
|
if not label:
|
|
continue
|
|
|
|
textWidth, textHeight = dc.GetTextExtent(label)
|
|
buttonPos = button.GetPosition()
|
|
buttonSize = button.GetSize()
|
|
xpos = buttonPos.x + (buttonSize.width - textWidth)/2
|
|
ypos = buttonPos.y - textHeight - 2
|
|
|
|
dc.DrawRectangle(xpos-2, ypos-1, textWidth+4, textHeight+2)
|
|
dc.DrawText(label, xpos, ypos)
|
|
|
|
|
|
def OnEraseBackground(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`EraseEvent` event to be processed.
|
|
|
|
:note: This method is intentionally empty to avoid flicker.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
def OnMotion(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_MOTION`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`MouseEvent` event to be processed.
|
|
"""
|
|
|
|
pos = event.GetPosition()
|
|
hit = self.HitTest(pos)
|
|
|
|
if hit >= 0:
|
|
button = self._buttons[hit]
|
|
if not button.ZoomImage(pos.x):
|
|
return
|
|
|
|
self.Reposition(button)
|
|
else:
|
|
|
|
if self._previousHit < 0:
|
|
return
|
|
|
|
for button in self._buttons:
|
|
button.SetSize(self._buttonSize, self._buttonSize)
|
|
|
|
self.InitialReposition()
|
|
|
|
self._previousHit = hit
|
|
self.Refresh()
|
|
|
|
|
|
def OnLeftDown(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_LEFT_DOWN`` and ``wx.EVT_LEFT_DCLICK`` events for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`MouseEvent` event to be processed.
|
|
"""
|
|
|
|
self._currentHit = self.HitTest(event.GetPosition())
|
|
|
|
|
|
def OnLeftUp(self, event):
|
|
"""
|
|
Handles the ``wx.EVT_LEFT_UP`` event for :class:`ZoomBar`.
|
|
|
|
:param `event`: a :class:`MouseEvent` event to be processed.
|
|
"""
|
|
|
|
if self.HitTest(event.GetPosition()) != self._currentHit:
|
|
return
|
|
|
|
if not self.IsButtonEnabled(self._currentHit):
|
|
return
|
|
|
|
eventOut = ZoomBarEvent(wxEVT_ZOOMBAR, self.GetId())
|
|
eventOut.SetSelection(self._currentHit)
|
|
eventOut.SetLabel(self._buttons[self._currentHit].GetLabel())
|
|
eventOut.SetEventObject(self)
|
|
self.GetEventHandler().ProcessEvent(eventOut)
|
|
|
|
|
|
def HitTest(self, pos):
|
|
"""
|
|
HitTest method for :class:`ZoomBar`.
|
|
|
|
:param `pos`: the current mouse position.
|
|
|
|
:return: an index representing the button on which the mouse is hovering,
|
|
or ``wx.NOT_FOUND`` if no button has been hit.
|
|
"""
|
|
|
|
for index, button in enumerate(self._buttons):
|
|
buttonPos = button.GetPosition()
|
|
if pos.x >= buttonPos.x and pos.x <= buttonPos.x + button._width:
|
|
return index
|
|
|
|
return wx.NOT_FOUND
|
|
|