ZoomBar.py :  » GUI » wxPython » wxPython-src-2.8.11.0 » wxPython » demo » agw » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » wxPython 
wxPython » wxPython src 2.8.11.0 » wxPython » demo » agw » ZoomBar.py
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
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:])

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.