diff --git a/gui/pygauge.py b/gui/pygauge.py index 9cfb45385..b5a1c1b4d 100644 --- a/gui/pygauge.py +++ b/gui/pygauge.py @@ -45,7 +45,7 @@ class PyGauge(wx.PyWindow): self._range = range self._value = 0 - self._skipDigits = True + self._fractionDigits = 0 self._timerId = wx.NewId() self._timer = None self._timerOver = None @@ -100,8 +100,8 @@ class PyGauge(wx.PyWindow): SetBarColor = SetBarColour GetBarColor = GetBarColour - def SetSkipDigitsFlag(self,flag): - self._skipDigits=flag + def SetFractionDigits(self, digits): + self._fractionDigits=digits def GetBarGradient(self): """ Returns a tuple containing the gradient start and end colours. """ @@ -189,12 +189,12 @@ class PyGauge(wx.PyWindow): if value < 0: self._value = 0 self._overdrive = 0 - + if not self._timer: self._timer = wx.Timer(self, self._timerId) self._animStep = 0 self._timer.Start(self._period) - + def OnEraseBackground(self, event): """ Handles the ``wx.EVT_ERASE_BACKGROUND`` event for L{PyGauge}. @@ -228,7 +228,7 @@ class PyGauge(wx.PyWindow): if self._timer: if self._timer.IsRunning(): value = self._animValue - + if self._border_colour: dc.SetPen(wx.Pen(self.GetBorderColour())) dc.DrawRectangleRect(rect) @@ -244,7 +244,7 @@ class PyGauge(wx.PyWindow): else: c1 =wx.Colour(255,0,0) c2 =wx.Colour(255,0,0) - + else: c1,c2 = self.GetBarGradient() @@ -268,10 +268,8 @@ class PyGauge(wx.PyWindow): if self._overdrive > self._range: value = self._overdrive self._tooltip.SetTip("%.2f/%.2f" % (value, self._range)) - if self._skipDigits == True: - dc.DrawLabel("%d%%" % (value*100/self._range), rect, wx.ALIGN_CENTER) - else: - dc.DrawLabel("%.1f%%" % (value * 100 / self._range) , rect, wx.ALIGN_CENTER) + formatStr = "{0:." + str(self._fractionDigits) + "f}%" + dc.DrawLabel(formatStr.format((value*100/self._range)), rect, wx.ALIGN_CENTER) def OUT_QUAD (self, t, b, c, d): t=float(t) @@ -282,7 +280,7 @@ class PyGauge(wx.PyWindow): t/=d return -c *(t)*(t-2) + b - + def OUT_BOUNCE (self, t, b, c, d): t=float(t) b=float(b) @@ -304,7 +302,7 @@ class PyGauge(wx.PyWindow): else: t-=(2.625/2.75) return c*(7.5625*(t)*t + .984375) + b - + def OnTimer(self,event): @@ -331,7 +329,7 @@ class PyGauge(wx.PyWindow): if self._timerId == event.GetId(): # and self._overdriveTimerId != event.GetId(): stop_timer = False - + if self._animStep > self._animDuration: stop_timer = True diff --git a/gui/statsPane.py b/gui/statsPane.py index a6b3a0587..18e55c9b4 100644 --- a/gui/statsPane.py +++ b/gui/statsPane.py @@ -377,7 +377,7 @@ class StatsPane(wx.Panel): else: gauge = PG.PyGauge(parent, wx.ID_ANY, 100) gauge.SetMinSize((self.getTextExtentW("999.9k/1.3M GJ"), 23)) - gauge.SetSkipDigitsFlag(True) + gauge.SetFractionDigits(2) setattr(self, "gauge%s%s" % (panel.capitalize(),capitalizedType), gauge) stats.Add(gauge, 0, wx.ALIGN_CENTER) @@ -460,7 +460,7 @@ class StatsPane(wx.Panel): lbl.SetBackgroundColour(wx.Colour(bc[0],bc[1],bc[2])) lbl.SetBarColour(wx.Colour(fc[0],fc[1],fc[2])) lbl.SetBarGradient() - lbl.SetSkipDigitsFlag(False) + lbl.SetFractionDigits(1) setattr(self, "labelResistance%s%s" % (tankType.capitalize(), damageType.capitalize()), lbl) box.Add(lbl, 0, wx.ALIGN_CENTER) diff --git a/util.py b/util.py index c58be635a..1a43eabb8 100644 --- a/util.py +++ b/util.py @@ -1,4 +1,4 @@ -def formatAmount(val, prec=4, lowest=0, highest=0): +def formatAmount(val, prec=3, lowest=0, highest=0): """ Add suffix to value, transform value to match new suffix and round it. @@ -15,7 +15,7 @@ def formatAmount(val, prec=4, lowest=0, highest=0): result = u"{0}{1}".format(newMantissa, suffix) return result -def suffixizeAmount(val, lowest, highest): +def suffixizeAmount(val, lowest=-6, highest=9): """ Add suffix to value and transform value to match new suffix. @@ -47,7 +47,7 @@ def suffixizeAmount(val, lowest, highest): else: return val, "" -def processAmount(val, prec): +def processAmount(val, prec=3): """ Round number and return as string.