code cleanup

This commit is contained in:
blitzmann
2017-11-27 21:05:06 -05:00
parent 2365112292
commit 2936b88c3d
43 changed files with 193 additions and 172 deletions

View File

@@ -2,7 +2,7 @@
import wx
def Brighten(color: wx.Colour, factor: [0, 1]):
def Brighten(color, factor):
""" Brightens a Color using a factor between 0 and 1"""
r, g, b, a = color
@@ -15,7 +15,7 @@ def Brighten(color: wx.Colour, factor: [0, 1]):
return wx.Colour(r, g, b, a)
def Darken(color: wx.Colour, factor: [0, 1]):
def Darken(color, factor):
""" Darkens a Color using a factor between 0 and 1"""
r, g, b, a = color
@@ -33,16 +33,16 @@ def Darken(color: wx.Colour, factor: [0, 1]):
return wx.Colour(r, g, b, a)
def _getBrightness(color: wx.Colour):
def _getBrightness(color):
"""
Calculates brightness of color
http://stackoverflow.com/a/596243/788054
"""
r, g, b, a = color
return 0.299*r + 0.587*g + 0.114*b
return 0.299 * r + 0.587 * g + 0.114 * b
def GetSuitable(color: wx.Colour, factor: [0, 1]):
def GetSuitable(color, factor: [0, 1]):
"""
Calculates a suitable color based on original color (wx.Colour), its
brightness, and a factor (darken/brighten by factor depending on
@@ -57,7 +57,7 @@ def GetSuitable(color: wx.Colour, factor: [0, 1]):
return Brighten(color, factor)
def CalculateTransition(s_color: wx.Colour, e_color: wx.Colour, delta: [0, 1]):
def CalculateTransition(s_color, e_color, delta):
"""
Calculates the color between a given start and end color using a delta
value between 0 and 1
@@ -70,4 +70,4 @@ def CalculateTransition(s_color: wx.Colour, e_color: wx.Colour, delta: [0, 1]):
tG = sG + (eG - sG) * delta
tB = sB + (eB - sB) * delta
return wx.Colour(tR, tG, tB, (sA + eA)/2)
return wx.Colour(tR, tG, tB, (sA + eA) / 2)

View File

@@ -6,14 +6,14 @@ from . import color
def RenderGradientBar(windowColor, width, height, sFactor, eFactor, mFactor=None , fillRatio=2):
if sFactor == 0 and eFactor == 0 and mFactor is None:
return DrawFilledBitmap(width,height, windowColor)
return DrawFilledBitmap(width, height, windowColor)
gStart = color.GetSuitable(windowColor, sFactor)
if mFactor:
gMid = color.GetSuitable(windowColor, mFactor)
else:
gMid = color.GetSuitable(windowColor, sFactor + (eFactor - sFactor) / 2)
gMid = color.GetSuitable(windowColor, sFactor + (eFactor - sFactor) / 2)
gEnd = color.GetSuitable(windowColor, eFactor)
@@ -21,7 +21,7 @@ def RenderGradientBar(windowColor, width, height, sFactor, eFactor, mFactor=None
def DrawFilledBitmap(width, height, color):
canvas = wx.Bitmap(width,height)
canvas = wx.Bitmap(width, height)
mdc = wx.MemoryDC()
mdc.SelectObject(canvas)
@@ -33,8 +33,9 @@ def DrawFilledBitmap(width, height, color):
return canvas
def DrawGradientBar(width, height, gStart, gEnd, gMid=None, fillRatio=4):
canvas = wx.Bitmap(width,height)
canvas = wx.Bitmap(width, height)
mdc = wx.MemoryDC()
mdc.SelectObject(canvas)
@@ -47,7 +48,7 @@ def DrawGradientBar(width, height, gStart, gEnd, gMid=None, fillRatio=4):
mdc.GradientFillLinear(r, gStart, gMid, wx.SOUTH)
r.SetTop(r.GetHeight())
r.SetHeight(height * (fillRatio - 1)/fillRatio + (1 if height % fillRatio != 0 else 0))
r.SetHeight(height * (fillRatio - 1) / fillRatio + (1 if height % fillRatio != 0 else 0))
mdc.GradientFillLinear(r, gMid, gEnd, wx.SOUTH)