1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
|
"""
: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 @ 17 Aug 2011, 15.00 GMT
Version 0.1
"""
import wx
import sys
from wx.lib.embeddedimage import PyEmbeddedImage
zoombackgrey = PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAAjkAAAAyCAYAAAC+s8qHAAAABHNCSVQICAgIfAhkiAAAIABJ"
"REFUeJzVXUuv5Udxr/O4xrzEAtvIAnYevkDAJp8piRfeeIGSsEFiY96QbUyiWRgn9reIieTx"
"YIGsAWQZCQkJz3h83/e8s0jquG7Nr17dfeY6JR2dc/rfXVXdXY9f9f88JpPpjEbTL37+s91u"
"tyN+EBF8XenDZPWR1yXp65rktclkAtv5tbwueU+nU5cXv9dtuq81xpLP77VcS45ci+12+8h1"
"OQ/Jg9u9uVk6ete5fTqdXtOb5cs2a66IJ1oDqYMe662Zlpnpg3hZdjqZTGg+n9MTTzxBn/nM"
"Z+jJJ5+k+XxO0+mUttstrVYrWiwWdHV1RVdXV7RYLGi9Xu/HTqdTmk6ntNvtaLPZ0Hq9Nm3e"
"WhO0FtoGJGl7IPrEnuQ1zy/1uvAckH7WONTH20ePpB8TfTIPtDba7lCfaLyUhWxQjtfXrHiI"
"rk0mE5rNZjSbzfa2wv622+1ou93Ser3ePzabDW232zDGWjYuydK5lby91jHGi1l6TXVskjEy"
"ylloblHOQetixXbrPfJBj6QcFPu5T7RPkR8zbbdbGLPRax672WxotVrRP/7TP7c5sUGTUSDn"
"3//tl7urqyu6uLig5XK5X0jPKNiI5GT1swVyvDHS4HW7pgzIschL7IhQsLISteyfdRivTZLc"
"m8w4rbeXBKv66Lmidi0XtVvj9BgLECIeco4jgjSyYwly+MEgZ7fb7UHOYrGg5XJJy+XyGsjh"
"gC4TVg/I8drlOG3HEphG4Eb6aGTfFh0C5PB4ZJMRwJF9NEBhYnDBr+WaWTJ2ux3NZrNrMvT6"
"WglFjplOp3ugw89EtAfGDHCyIEfPHcXZ1r1ApG0lsmUiDATk+lty9HvrYY3zrmViYRTj+H3r"
"+nogx3tvtaF2S4bsK9dytVrR5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AMl4eyJiDe3"
"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.BitmapFromImage(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 = -sys.maxint
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. """
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.NamedColour(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.PyControl):
"""
: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.PyControl.__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:`PyControl`.
"""
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 xrange(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 xrange(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
|