MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / AttributeSlider

Class AttributeSlider

gui/builtinItemStatsViews/attributeSlider.py:53–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51
52
53class AttributeSlider(wx.Panel):
54 # Slider which abstracts users values from internal values (because the built in slider does not deal with floats
55 # and the like), based on http://wxpython-users.wxwidgets.narkive.com/ekgBzA7u/anyone-ever-thought-of-a-floating-point-slider
56
57 def __init__(self, parent, baseValue, minValue, maxValue, inverse=False, id=-1):
58 wx.Panel.__init__(self, parent, id=id)
59
60 self.parent = parent
61
62 self.base_value = baseValue
63
64 self.UserMinValue = minValue
65 self.UserMaxValue = maxValue
66
67 self.inverse = inverse
68
69 def getStep(valRange):
70 """
71 Find step for the passed range, which is based on 1, 2 or 5.
72 Step returned will make sure that range fits 10..50 of them,
73 as close to 10 as possible.
74 """
75 steps = {1: None, 2: None, 5: None}
76 for baseInc in steps:
77 baseIncAmount = valRange / baseInc
78 incScale = math.floor(math.log10(baseIncAmount) - 1)
79 steps[baseInc] = baseInc * 10 ** incScale
80 chosenBase = min(steps, key=lambda base: valRange / steps[base])
81 chosenStep = steps[chosenBase]
82 if inverse:
83 chosenStep *= -1
84 return chosenStep
85
86 def getDigitPlaces(minValue, maxValue):
87 minDigits = 3
88 maxDigits = 5
89 currentDecision = minDigits
90 for value in (floatUnerr(minValue), floatUnerr(maxValue)):
91 for currentDigit in range(minDigits, maxDigits + 1):
92 if round(value, currentDigit) == value:
93 if currentDigit > currentDecision:
94 currentDecision = currentDigit
95 break
96 # Max decimal places we can afford to show was not enough
97 else:
98 return maxDigits
99 return currentDecision
100
101 self.ctrl = wx.SpinCtrlDouble(self, min=minValue, max=maxValue, inc=getStep(maxValue - minValue))
102 self.ctrl.SetDigits(getDigitPlaces(minValue, maxValue))
103
104 self.ctrl.Bind(wx.EVT_SPINCTRLDOUBLE, self.UpdateValue)
105 # GTK scrolls spinboxes with mousewheel, others do not
106 if "wxGTK" not in wx.PlatformInfo:
107 self.ctrl.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
108
109 self.slider = AttributeGauge(self, size=(-1, 8))
110

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected