phoenix_title wx.lib.agw.peakmeter

PeakMeterCtrl mimics the behaviour of equalizers that are usually found in stereos and MP3 players.

Description

PeakMeterCtrl mimics the behaviour of equalizers that are usually found in stereos and MP3 players. This widgets supports:

  • Vertical and horizontal led bands;

  • Settings number of bands and leds per band;

  • Possibility to change the colour for low/medium/high band frequencies;

  • Falloff effects;

  • Showing a background grid for the bands.

And a lot more. Check the demo for an almost complete review of the functionalities.

Usage

Usage example:

import wx
import random

import wx.lib.agw.peakmeter as PM

class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, -1, "PeakMeterCtrl Demo")

        panel = wx.Panel(self)

        # Initialize Peak Meter control 1
        self.vertPeak = PM.PeakMeterCtrl(panel, -1, style=wx.SIMPLE_BORDER, agwStyle=PM.PM_VERTICAL)
        # Initialize Peak Meter control 2
        self.horzPeak = PM.PeakMeterCtrl(panel, -1, style=wx.SUNKEN_BORDER, agwStyle=PM.PM_HORIZONTAL)

        self.vertPeak.SetMeterBands(10, 15)
        self.horzPeak.SetMeterBands(10, 15)

        # Layout the two PeakMeterCtrl
        mainSizer = wx.BoxSizer(wx.HORIZONTAL)
        mainSizer.Add(self.vertPeak, 0, wx.EXPAND | wx.ALL, 15)
        mainSizer.Add(self.horzPeak, 0, wx.EXPAND | wx.ALL, 15)

        panel.SetSizer(mainSizer)
        mainSizer.Layout()

        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer)

        wx.CallLater(500, self.Start)


    def Start(self):
        ''' Starts the PeakMeterCtrl. '''

        self.timer.Start(1000//2)            # 2 fps

        self.vertPeak.Start(1000//18)        # 18 fps
        self.horzPeak.Start(1000//20)        # 20 fps


    def OnTimer(self, event):
        '''
        Handles the ``wx.EVT_TIMER`` event for :class:`PeakMeterCtrl`.

        :param `event`: a :class:`TimerEvent` event to be processed.
        '''

        # Generate 15 random number and set them as data for the meter
        nElements = 15
        arrayData = []

        for i in xrange(nElements):
            nRandom = random.randint(0, 100)
            arrayData.append(nRandom)

        self.vertPeak.SetData(arrayData, 0, nElements)
        self.horzPeak.SetData(arrayData, 0, nElements)


# our normal wxApp-derived class, as usual

app = wx.App(0)

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

Supported Platforms

PeakMeterCtrl has been tested on the following platforms:
  • Windows (Windows XP).

Window Styles

This class supports the following window styles:

Window Styles

Hex Value

Description

PM_HORIZONTAL

0x0

Shows horizontal bands in PeakMeterCtrl.

PM_VERTICAL

0x1

Shows vertical bands in PeakMeterCtrl.

PM_VERTICAL_INVERTED

0x2

Shows inverted vertical bands in PeakMeterCtrl.

Events Processing

No custom events are available for this class.

License And Version

PeakMeterCtrl is distributed under the wxPython license.

Latest Revision: Andrea Gavana @ 31 Jul 2014, 21.00 GMT

Version 0.4

function_summary Functions Summary

DarkenColour

Darkens a colour.

InRange

Returns whether the value val is between valMin and valMax.

LightenColour

Lightens a colour.


class_summary Classes Summary

PeakMeterCtrl

The main PeakMeterCtrl implementation.

PeakMeterData

A simple class which holds data for our PeakMeterCtrl.


Functions



DarkenColour(crColour, byReduceVal)

Darkens a colour.

Parameters:
  • crColour – a valid wx.Colour object;

  • byReduceVal – an integer specifying the amount for which the input colour should be darkened.



InRange(val, valMin, valMax)

Returns whether the value val is between valMin and valMax.

Parameters:
  • val – the value to test;

  • valMin – the minimum range value;

  • valMax – the maximum range value.



LightenColour(crColour, byIncreaseVal)

Lightens a colour.

Parameters:
  • crColour – a valid wx.Colour object;

  • byIncreaseVal – an integer specifying the amount for which the input colour should be brightened.