Ensure that resources gauge is not drawn with a width of 0 to make GTK happy
This commit is contained in:
@@ -312,47 +312,53 @@ class PyGauge(wx.PyWindow):
|
||||
r = copy.copy(rect)
|
||||
r.width = w
|
||||
|
||||
if r.width > 0:
|
||||
# If we draw it with zero width, GTK throws errors. This way,
|
||||
# only draw it if the gauge will actually show something.
|
||||
# We stick other calculations in this block to avoid wasting
|
||||
# time on them if not needed. See GH issue #282
|
||||
|
||||
pv = value
|
||||
xv=1
|
||||
transition = 0
|
||||
|
||||
if pv <= 100:
|
||||
xv = pv/100
|
||||
pv = value
|
||||
xv=1
|
||||
transition = 0
|
||||
|
||||
elif pv <=101:
|
||||
xv = pv -100
|
||||
transition = 1
|
||||
if pv <= 100:
|
||||
xv = pv/100
|
||||
transition = 0
|
||||
|
||||
elif pv <= 103:
|
||||
xv = (pv -101)/2
|
||||
transition = 2
|
||||
elif pv <=101:
|
||||
xv = pv -100
|
||||
transition = 1
|
||||
|
||||
elif pv <= 105:
|
||||
xv = (pv -103)/2
|
||||
transition = 3
|
||||
elif pv <= 103:
|
||||
xv = (pv -101)/2
|
||||
transition = 2
|
||||
|
||||
else:
|
||||
pv = 106
|
||||
xv = pv -100
|
||||
transition = -1
|
||||
elif pv <= 105:
|
||||
xv = (pv -103)/2
|
||||
transition = 3
|
||||
|
||||
if transition != -1:
|
||||
colorS,colorE = self.transitionsColors[transition]
|
||||
color = colorUtils.CalculateTransitionColor(colorS, colorE, xv)
|
||||
else:
|
||||
color = wx.Colour(191,48,48)
|
||||
else:
|
||||
pv = 106
|
||||
xv = pv -100
|
||||
transition = -1
|
||||
|
||||
if self.gradientEffect > 0:
|
||||
gcolor = colorUtils.BrightenColor(color, float(self.gradientEffect) / 100)
|
||||
gMid = colorUtils.BrightenColor(color, float(self.gradientEffect/2) / 100)
|
||||
else:
|
||||
gcolor = colorUtils.DarkenColor(color, float(-self.gradientEffect) / 100)
|
||||
gMid = colorUtils.DarkenColor(color, float(-self.gradientEffect/2) / 100)
|
||||
if transition != -1:
|
||||
colorS,colorE = self.transitionsColors[transition]
|
||||
color = colorUtils.CalculateTransitionColor(colorS, colorE, xv)
|
||||
else:
|
||||
color = wx.Colour(191,48,48)
|
||||
|
||||
if self.gradientEffect > 0:
|
||||
gcolor = colorUtils.BrightenColor(color, float(self.gradientEffect) / 100)
|
||||
gMid = colorUtils.BrightenColor(color, float(self.gradientEffect/2) / 100)
|
||||
else:
|
||||
gcolor = colorUtils.DarkenColor(color, float(-self.gradientEffect) / 100)
|
||||
gMid = colorUtils.DarkenColor(color, float(-self.gradientEffect/2) / 100)
|
||||
|
||||
gBmp = drawUtils.DrawGradientBar(r.width, r.height, gMid, color, gcolor)
|
||||
dc.DrawBitmap(gBmp, r.left, r.top)
|
||||
|
||||
gBmp = drawUtils.DrawGradientBar(r.width, r.height, gMid, color, gcolor)
|
||||
dc.DrawBitmap(gBmp,r.left, r.top)
|
||||
else:
|
||||
colour=self.GetBarColour()
|
||||
dc.SetBrush(wx.Brush(colour))
|
||||
@@ -397,7 +403,6 @@ class PyGauge(wx.PyWindow):
|
||||
dc.SetTextForeground(wx.Colour(255,255,255))
|
||||
dc.DrawLabel(formatStr.format(value), rect, wx.ALIGN_CENTER)
|
||||
|
||||
|
||||
def OnTimer(self,event):
|
||||
"""
|
||||
Handles the ``wx.EVT_TIMER`` event for L{PyfaGauge}.
|
||||
|
||||
@@ -33,9 +33,10 @@ def DrawFilledBitmap(width, height, color):
|
||||
return canvas
|
||||
|
||||
def DrawGradientBar(width, height, gStart, gEnd, gMid = None, fillRatio = 4):
|
||||
# we need to have dimensions to draw
|
||||
assert width > 0 and height > 0
|
||||
canvas = wx.EmptyBitmap(width,height)
|
||||
|
||||
|
||||
mdc = wx.MemoryDC()
|
||||
mdc.SelectObject(canvas)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user