1#!/usr/bin/env python 2 3import wx 4 5import os 6import sys 7import glob 8import random 9 10from wx.lib import masked 11 12try: 13 dirName = os.path.dirname(os.path.abspath(__file__)) 14except: 15 dirName = os.path.dirname(os.path.abspath(sys.argv[0])) 16 17bitmapDir = os.path.join(dirName, 'bitmaps') 18sys.path.append(os.path.split(dirName)[0]) 19 20try: 21 from agw import zoombar as ZB 22except ImportError: # if it's not there locally, try the wxPython lib. 23 import wx.lib.agw.zoombar as ZB 24 25 26_buttonStatus = {True: "Disable First Button", 27 False: "Enable First Button"} 28 29#---------------------------------------------------------------------- 30 31class TestPanel(wx.Panel): 32 33 def __init__(self, parent, log): 34 35 self.log = log 36 self.enabled = True 37 38 wx.Panel.__init__(self, parent, -1) 39 40 self.sizer_1_staticbox = wx.StaticBox(self, -1, "ZoomBar Options") 41 self.zoomSpin = wx.SpinCtrl(self, -1, "3", min=1, max=5) 42 43 self.colourzoom = wx.ColourPickerCtrl(self, colour=wx.Colour(97, 97, 97)) 44 self.buttonSize = masked.NumCtrl(self, value=32, allowNegative=False, 45 min=32, max=72) 46 47 self.centerZoom = wx.CheckBox(self, -1, "Center Zoom") 48 self.showReflections = wx.CheckBox(self, -1, "Show Reflections") 49 self.showLabels = wx.CheckBox(self, -1, "Show Labels") 50 self.enableButton = wx.Button(self, -1, "Disable First Button") 51 52 self.zbp = ZB.ZoomBar(self, -1) 53 54 standard = glob.glob(bitmapDir + "/*96.png") 55 reflections = glob.glob(bitmapDir + "/*96Flip40.png") 56 57 separatorImage = bitmapDir + "/separator.gif" 58 separatorReflection = bitmapDir + "/separatorFlip.png" 59 count = 0 60 61 for std, ref in zip(standard, reflections): 62 if random.randint(0, 1) == 1 and count > 0: 63 sep1 = wx.Bitmap(separatorImage, wx.BITMAP_TYPE_GIF) 64 sep2 = wx.Bitmap(separatorReflection, wx.BITMAP_TYPE_PNG) 65 self.zbp.AddSeparator(sep1, sep2) 66 67 bname = os.path.split(std)[1][0:-6] 68 self.zbp.AddButton(wx.Bitmap(std, wx.BITMAP_TYPE_PNG), wx.Bitmap(ref, wx.BITMAP_TYPE_PNG), bname) 69 count += 1 70 71 self.zbp.ResetSize() 72 73 self.SetProperties() 74 self.DoLayout() 75 76 self.Bind(wx.EVT_SPINCTRL, self.OnZoomFactor, self.zoomSpin) 77 self.Bind(wx.EVT_CHECKBOX, self.OnCenterZoom, self.centerZoom) 78 self.Bind(wx.EVT_CHECKBOX, self.OnShowReflections, self.showReflections) 79 self.Bind(wx.EVT_CHECKBOX, self.OnShowLabels, self.showLabels) 80 self.Bind(wx.EVT_BUTTON, self.OnEnable, self.enableButton) 81 82 self.Bind(masked.EVT_NUM, self.OnButtonSize, self.buttonSize) 83 84 self.colourzoom.Bind(wx.EVT_COLOURPICKER_CHANGED, self.OnZoomColour) 85 86 self.Bind(ZB.EVT_ZOOMBAR, self.OnZoomBar) 87 88 89 def SetProperties(self): 90 91 self.centerZoom.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 92 self.showReflections.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 93 self.showLabels.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 94 95 self.centerZoom.Enable(False) 96 self.showLabels.SetValue(1) 97 self.showReflections.SetValue(1) 98 99 100 def DoLayout(self): 101 102 mainSizer = wx.BoxSizer(wx.HORIZONTAL) 103 centerSizer = wx.BoxSizer(wx.VERTICAL) 104 sizer_1 = wx.StaticBoxSizer(self.sizer_1_staticbox, wx.VERTICAL) 105 sizer_2 = wx.BoxSizer(wx.VERTICAL) 106 sizer_3 = wx.FlexGridSizer(3, 2, 5, 5) 107 mainSizer.Add((20, 20), 1, wx.EXPAND, 0) 108 centerSizer.Add((20, 20), 1, 0, 0) 109 label_1 = wx.StaticText(self, -1, "Zoom Factor:") 110 label_1.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 111 sizer_3.Add(label_1, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5) 112 sizer_3.Add(self.zoomSpin, 1, wx.ALIGN_CENTER_VERTICAL, 0) 113 114 label_2 = wx.StaticText(self, -1, "Bar Colour:") 115 label_2.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 116 sizer_3.Add(label_2, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5) 117 sizer_3.Add(self.colourzoom, 0, wx.ALIGN_CENTER_VERTICAL, 0) 118 119 label_3 = wx.StaticText(self, -1, "Button Size:") 120 label_3.SetFont(wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) 121 sizer_3.Add(label_3, 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 5) 122 sizer_3.Add(self.buttonSize, 0, wx.ALIGN_CENTER_VERTICAL, 0) 123 124 sizer_2.Add(sizer_3, 0, wx.EXPAND|wx.ALL, 5) 125 126 sizer_2.Add(self.centerZoom, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) 127 sizer_2.Add(self.showReflections, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) 128 sizer_2.Add(self.showLabels, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) 129 sizer_2.Add(self.enableButton, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5) 130 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) 131 centerSizer.Add(sizer_1, 0, wx.EXPAND, 0) 132 centerSizer.Add(self.zbp, 0, wx.TOP|wx.EXPAND, 20) 133 centerSizer.Add((0, 0), 1, 0, 0) 134 mainSizer.Add(centerSizer, 10, wx.EXPAND, 0) 135 mainSizer.Add((0, 0), 1, wx.EXPAND, 0) 136 self.SetSizer(mainSizer) 137 mainSizer.Fit(self) 138 139 140 def OnZoomBar(self, event): 141 142 self.log.write("Selected button index and label: %d, %s\n"%(event.GetSelection(), event.GetLabel())) 143 144 145 def OnZoomFactor(self, event): 146 147 value = event.GetInt() 148 self.zbp.SetZoomFactor(value) 149 150 event.Skip() 151 152 153 def OnZoomColour(self, event): 154 155 colour = event.GetEventObject().GetColour() 156 self.zbp.SetBarColour(colour) 157 158 159 def OnCenterZoom(self, event): 160 161 self.zbp.SetCenterZoom(event.IsChecked()) 162 wx.CallAfter(self.ReLayout) 163 164 165 def OnShowReflections(self, event): 166 167 if event.IsChecked(): 168 self.centerZoom.SetValue(0) 169 self.centerZoom.Enable(False) 170 self.zbp.SetCenterZoom(False) 171 self.zbp.SetShowReflections(True) 172 else: 173 self.centerZoom.Enable(True) 174 self.zbp.SetShowReflections(False) 175 176 wx.CallAfter(self.ReLayout) 177 178 179 def OnShowLabels(self, event): 180 181 self.zbp.SetShowLabels(event.IsChecked()) 182 wx.CallAfter(self.ReLayout) 183 184 185 def OnEnable(self, event): 186 187 self.zbp.EnableButton(0, not self.enabled) 188 self.enabled = not self.enabled 189 190 obj = event.GetEventObject() 191 obj.SetLabel(_buttonStatus[self.enabled]) 192 obj.Refresh() 193 194 195 def OnButtonSize(self, event): 196 197 value = event.GetValue() 198 event.Skip() 199 200 if value < 32 or value > 72: 201 return 202 203 self.zbp.SetButtonSize(value) 204 wx.CallAfter(self.ReLayout) 205 206 207 def ReLayout(self): 208 209 self.Layout() 210 self.Refresh() 211 self.Update() 212 213 214#---------------------------------------------------------------------- 215 216def runTest(frame, nb, log): 217 win = TestPanel(nb, log) 218 return win 219 220#---------------------------------------------------------------------- 221 222 223overview = ZB.__doc__ 224 225 226if __name__ == '__main__': 227 import sys, os 228 import run 229 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) 230 231