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
|
import wx
import os
import sys
import glob
import random
import wx.lib.colourselect as csel
from wx.lib import masked
try:
dirName = os.path.dirname(os.path.abspath(__file__))
except:
dirName = os.path.dirname(os.path.abspath(sys.argv[0]))
bitmapDir = os.path.join(dirName, 'bitmaps')
sys.path.append(os.path.split(dirName)[0])
try:
from agw import zoombar as ZB
except ImportError: # if it's not there locally, try the wxPython lib.
import wx.lib.agw.zoombar as ZB
_buttonStatus = {True: "Disable First Button",
False: "Enable First Button"}
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
self.enabled = True
wx.Panel.__init__(self, parent, -1)
self.sizer_1_staticbox = wx.StaticBox(self, -1, "ZoomBar Options")
self.zoomSpin = wx.SpinCtrl(self, -1, "3", min=1, max=5)
self.colourzoom = csel.ColourSelect(self, colour=wx.Colour(97, 97, 97))
self.buttonSize = masked.NumCtrl(self, value=32, allowNegative=False,
min=32, max=72)
self.centerZoom = wx.CheckBox(self, -1, "Center Zoom")
self.showReflections = wx.CheckBox(self, -1, "Show Reflections")
self.showLabels = wx.CheckBox(self, -1, "Show Labels")
self.enableButton = wx.Button(self, -1, "Disable First Button")
self.zbp = ZB.ZoomBar(self, -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)
self.zbp.AddSeparator(sep1, sep2)
bname = os.path.split(std)[1][0:-6]
self.zbp.AddButton(wx.Bitmap(std, wx.BITMAP_TYPE_PNG), wx.Bitmap(ref, wx.BITMAP_TYPE_PNG), bname)
count += 1
self.zbp.ResetSize()
self.SetProperties()
self.DoLayout()
self.Bind(wx.EVT_SPINCTRL, self.OnZoomFactor, self.zoomSpin)
self.Bind(wx.EVT_CHECKBOX, self.OnCenterZoom, self.centerZoom)
self.Bind(wx.EVT_CHECKBOX, self.OnShowReflections, self.showReflections)
self.Bind(wx.EVT_CHECKBOX, self.OnShowLabels, self.showLabels)
self.Bind(wx.EVT_BUTTON, self.OnEnable, self.enableButton)
self.Bind(masked.EVT_NUM, self.OnButtonSize, self.buttonSize)
self.colourzoom.Bind(csel.EVT_COLOURSELECT, self.OnZoomColour)
self.Bind(ZB.EVT_ZOOMBAR, self.OnZoomBar)
def SetProperties(self):
self.centerZoom.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
self.showReflections.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
self.showLabels.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
self.centerZoom.Enable(False)
self.showLabels.SetValue(1)
self.showReflections.SetValue(1)
def DoLayout(self):
mainSizer = wx.BoxSizer(wx.HORIZONTAL)
centerSizer = wx.BoxSizer(wx.VERTICAL)
sizer_1 = wx.StaticBoxSizer(self.sizer_1_staticbox, wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_3 = wx.FlexGridSizer(3, 2, 5, 5)
mainSizer.Add((20, 20), 1, wx.EXPAND, 0)
centerSizer.Add((20, 20), 1, 0, 0)
label_1 = wx.StaticText(self, -1, "Zoom Factor:")
label_1.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
sizer_3.Add(label_1, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_3.Add(self.zoomSpin, 1, wx.ALIGN_CENTER_VERTICAL, 0)
label_2 = wx.StaticText(self, -1, "Bar Colour:")
label_2.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
sizer_3.Add(label_2, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_3.Add(self.colourzoom, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_3 = wx.StaticText(self, -1, "Button Size:")
label_3.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
sizer_3.Add(label_3, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_3.Add(self.buttonSize, 0, wx.ALIGN_CENTER_VERTICAL, 0)
sizer_2.Add(sizer_3, 0, wx.EXPAND|wx.ALL, 5)
sizer_2.Add(self.centerZoom, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_2.Add(self.showReflections, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_2.Add(self.showLabels, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_2.Add(self.enableButton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
centerSizer.Add(sizer_1, 0, wx.EXPAND, 0)
centerSizer.Add(self.zbp, 0, wx.TOP|wx.EXPAND, 20)
centerSizer.Add((0, 0), 1, 0, 0)
mainSizer.Add(centerSizer, 10, wx.EXPAND, 0)
mainSizer.Add((0, 0), 1, wx.EXPAND, 0)
self.SetSizer(mainSizer)
mainSizer.Fit(self)
def OnZoomBar(self, event):
self.log.write("Selected button index and label: %d, %s\n"%(event.GetSelection(), event.GetLabel()))
def OnZoomFactor(self, event):
value = event.GetInt()
self.zbp.SetZoomFactor(value)
event.Skip()
def OnZoomColour(self, event):
colour = event.GetValue()
self.zbp.SetBarColour(colour)
def OnCenterZoom(self, event):
self.zbp.SetCenterZoom(event.IsChecked())
wx.CallAfter(self.ReLayout)
def OnShowReflections(self, event):
if event.IsChecked():
self.centerZoom.SetValue(0)
self.centerZoom.Enable(False)
self.zbp.SetCenterZoom(False)
self.zbp.SetShowReflections(True)
else:
self.centerZoom.Enable(True)
self.zbp.SetShowReflections(False)
wx.CallAfter(self.ReLayout)
def OnShowLabels(self, event):
self.zbp.SetShowLabels(event.IsChecked())
wx.CallAfter(self.ReLayout)
def OnEnable(self, event):
self.zbp.EnableButton(0, not self.enabled)
self.enabled = not self.enabled
obj = event.GetEventObject()
obj.SetLabel(_buttonStatus[self.enabled])
obj.Refresh()
def OnButtonSize(self, event):
value = event.GetValue()
event.Skip()
if value < 32 or value > 72:
return
self.zbp.SetButtonSize(value)
wx.CallAfter(self.ReLayout)
def ReLayout(self):
self.Layout()
self.Refresh()
self.Update()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = ZB.__doc__
if __name__ == '__main__':
import sys, os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|