double valued gauge in wxpython
Does anyone know of a double valued gauge in wxPython? I would like to show the range of a set of data that has been selected, I have the max and min values of the gauge and then I'd like to highlight the region of the gauge between two values. The normal 开发者_运维百科wx.Gauge highlights from the gauge minimum (always the bottom of the gauge) to the set value.
Thanks
I'm not aware of any built-in widgets with the appearance of wx.Gauge that can do what you're looking for.
One option with a different appearance is RulerCtrl, which can give you two value indicators on a scale with whatever range you want. It just takes a bit of extra work to adapt it since not all of its properties are exposed in the listed methods. Quick example:
import wx
import wx.lib.agw.rulerctrl as rc
class MinMax(rc.RulerCtrl):
def __init__(self, parent, range_min, range_max, orient=wx.HORIZONTAL):
rc.RulerCtrl.__init__(self, parent, orient)
self.SetRange(range_min, range_max)
self.LabelMinor(False)
self.range_min = range_min
self.range_max = range_max
self.AddIndicator(wx.NewId(), range_min)
self.AddIndicator(wx.NewId(), range_max)
self.Bind(rc.EVT_INDICATOR_CHANGING, self.OnIndicatorChanging)
def GetMinIndicatorValue(self):
return self._indicators[0]._value
def GetMaxIndicatorValue(self):
return self._indicators[1]._value
def SetMinIndicatorValue(self, value):
# Value must be within range and <= Max indicator value.
if value < self.range_min or value > self.GetMaxIndicatorValue():
raise ValueError('Out of bounds!')
self._indicators[0]._value=value
self.Refresh()
def SetMaxIndicatorValue(self, value):
# Value must be within range and >= Min indicator value.
if value > self.range_max or value < self.GetMinIndicatorValue():
raise ValueError('Out of bounds!')
self._indicators[1]._value=value
self.Refresh()
def OnIndicatorChanging(self, evt):
# Eat the event so the user can't change values manually.
# Do some validation here and evt.Skip() if you want to allow it.
# Related: EVT_INDICATOR_CHANGED
pass
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
self.minmax = MinMax(self, 0, 100)
self.minmax.SetSpacing(20)
self.minmax.SetMinIndicatorValue(30)
self.minmax.SetMaxIndicatorValue(84)
self.Show()
app = wx.App(redirect=False)
frame = MainWindow(None, wx.ID_ANY, "Range Indicator")
app.MainLoop()
精彩评论