MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / __init__

Method __init__

gui/builtinItemStatsViews/attributeSlider.py:57–117  ·  view source on GitHub ↗
(self, parent, baseValue, minValue, maxValue, inverse=False, id=-1)

Source from the content-addressed store, hash-verified

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
111 b = 4
112 vsizer1 = wx.BoxSizer(wx.VERTICAL)
113 vsizer1.Add(self.ctrl, 0, wx.LEFT | wx.RIGHT | wx.CENTER, b)
114 vsizer1.Add(self.slider, 0, wx.EXPAND | wx.ALL , b)

Callers

nothing calls this directly

Calls 3

AttributeGaugeClass · 0.90
__init__Method · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected