KnobCtrl lets the user select a numerical value by rotating it.
KnobCtrl lets the user select a numerical value by rotating it. It works like a scrollbar: just set the ticks range property and read the value property in the associated EVT_KC_ANGLE_CHANGING/EVT_KC_ANGLE_CHANGED events. Simple but effective.
It can be easily used if you want to simulate the volume knob of a music player or similar functionalities.
Usage example:
import wx
import wx.lib.agw.knobctrl as KC
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "KnobCtrl Demo")
panel = wx.Panel(self)
knob1 = KC.KnobCtrl(panel, -1, size=(100, 100))
knob2 = KC.KnobCtrl(panel, -1, size=(100, 100))
knob1.SetTags(range(0, 151, 10))
knob1.SetAngularRange(-45, 225)
knob1.SetValue(45)
knob2.SetTags(range(0, 151, 10))
knob2.SetAngularRange(0, 270)
knob2.SetValue(100)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(knob1, 0, wx.EXPAND|wx.ALL, 20)
main_sizer.Add(knob2, 0, wx.EXPAND|wx.ALL, 20)
panel.SetSizer(main_sizer)
main_sizer.Layout()
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
KnobCtrl implements two events that can be intercepted by the user:
The first one can be “vetoed” by eliminating the event.Skip() at the end of the event handler.
This class supports the following window styles:
Window Styles | Hex Value | Description |
---|---|---|
KC_BUFFERED_DC | 0x1 | Flag to use double buffering (recommendeded = 1). |
This class processes the following events:
Event Name | Description |
---|---|
EVT_KC_ANGLE_CHANGED | Notify the client that the knob has changed its value. |
EVT_KC_ANGLE_CHANGING | Notify the client that the knob is changing its value. |
KnobCtrl is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 17 Aug 2011, 15.00 GMT
Version 0.3
BufferedWindow | A Buffered window class. |
KnobCtrl | This class can be used to simulate a knob volume control often found in |
KnobCtrlEvent | Represent details of the events that the KnobCtrl object sends. |