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.PySimpleApp()
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
This code snippet can be downloaded, see this example script.
Note
Some of the AGW snippets of code in the documentation use images and external files (to create bitmaps or access external data). As these files are not provided in these snippets, you should make the approriate modifications to the code to actually run it.
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
Module author: Andrea Gavana <andrea.gavana@gmail.com>
A graphical representation of the SVN commits in the last year.
Click on any date in the picture to jump to that particular revision page, containing information about committers, log messages and SVN diffs.
Revision Graph For knobctrl