Skip to content

Commit

Permalink
Trim trailing space wx directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Metallicow committed Dec 5, 2016
1 parent c6ed20e commit 17aaf52
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
96 changes: 48 additions & 48 deletions wx/lib/colourchooser/pycolourchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ColourChangedEvent(ColourChangedEventBase):
"""Adds GetColour()/GetValue() for compatibility with ColourPickerCtrl and colourselect"""
def __init__(self, newColour):
super().__init__(newColour = newColour)

def GetColour(self):
return self.newColour

Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(self, parent, id):
(slabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.sentry, 0, wx.FIXED_MINSIZE),
(vlabel, 0, wx.ALIGN_CENTER_VERTICAL), (self.ventry, 0, wx.FIXED_MINSIZE),
])

self.hentry.Bind(wx.EVT_KILL_FOCUS, self.onHSVKillFocus)
self.sentry.Bind(wx.EVT_KILL_FOCUS, self.onHSVKillFocus)
self.ventry.Bind(wx.EVT_KILL_FOCUS, self.onHSVKillFocus)
Expand Down Expand Up @@ -332,7 +332,7 @@ def setCustomColour (self, index, true_colour, base_colour, slidepos):
colour slider and set everything to its original position."""
self.custom_boxs[index].SetColour(true_colour)
self.custom_colours[index] = (base_colour, slidepos)

def setSliderToV(self, v):
"""Set a new HSV value for the v slider. Does not update displayed colour."""
min = self.slider.GetMin()
Expand All @@ -345,19 +345,19 @@ def getVFromSlider(self):
val = self.slider.GetValue()
min = self.slider.GetMin()
max = self.slider.GetMax()

# Snap to exact min/max values
if val == 0:
return 1
if val == max - 1:
return 0

return 1 - (val / max)

def colourToHSV(self, colour):
"""Convert wx.Colour to hsv triplet"""
return colorsys.rgb_to_hsv(colour.Red() / 255.0, colour.Green() / 255.0, colour.Blue() / 255.0)

def hsvToColour(self, hsv):
"""Convert hsv triplet to wx.Colour"""
# Allow values to go full range from 0 to 255
Expand All @@ -366,9 +366,9 @@ def hsvToColour(self, hsv):
r *= 255.0
g *= 255.0
b *= 255.0

return wx.Colour(r, g, b)

def getColourFromControls(self):
"""
Calculate current colour from HS box position and V slider.
Expand All @@ -380,9 +380,9 @@ def getColourFromControls(self):
v = self.getVFromSlider()
if s < 0.04: # Allow pure white
s = 0

return self.hsvToColour((h, s, v))

def updateDisplayColour(self, colour):
"""Update the displayed color box (solid) and send the EVT_COLOUR_CHANGED"""
self.solid.SetColour(colour)
Expand All @@ -395,18 +395,18 @@ def UpdateColour(self, colour):
self.updateDisplayColour(colour)
self.colour_slider.SetBaseColour(colour)
self.colour_slider.ReDraw()

# Update the Vslider and the HS current selection dot
h,s,v = self.colourToHSV(colour)
self.setSliderToV(v)

# Convert RGB to (x,y) == (hue, saturation)

width, height = self.palette.GetSize()
x = width * h
y = height * (1 - s)
self.palette.HighlightPoint(x, y)

self.UpdateEntries(colour)

def UpdateEntries(self, colour):
Expand All @@ -426,15 +426,15 @@ def UpdateEntries(self, colour):
self.hentry.SetValue("%.2f" % (h))
self.sentry.SetValue("%.2f" % (s))
self.ventry.SetValue("%.2f" % (v))

def onColourSliderClick(self, y):
"""Shared helper for onSliderDown()/onSliderMotion()"""
v = self.colour_slider.GetVFromClick(y)
self.setSliderToV(v)

# Now with the slider updated, update all controls
colour = self.getColourFromControls()

self.updateDisplayColour(colour) # Update display
self.UpdateEntries(colour)

Expand All @@ -444,15 +444,15 @@ def onColourSliderClick(self, y):
# x = width * h
# y = height * (1 - s)
# self.palette.HighlightPoint(x, y)

def onSliderDown(self, event):
"""Handle mouse click on the colour slider palette"""
self.onColourSliderClick(event.GetY())
self.colour_slider.CaptureMouse()

def onSliderUp(self, event):
self.colour_slider.ReleaseMouse()

def onSliderMotion(self, event):
"""Handle mouse-down drag on the colour slider palette"""
if event.LeftIsDown():
Expand All @@ -462,10 +462,10 @@ def onPaletteDown(self, event):
"""Stores state that the mouse has been pressed and updates
the selected colour values."""
self.doPaletteClick(event.GetX(), event.GetY())

# Prevent mouse from leaving window, so that we will also get events
# when mouse is dragged along the edges of the rectangle.
self.palette.CaptureMouse()
self.palette.CaptureMouse()

def onPaletteUp(self, event):
"""Stores state that the mouse is no longer depressed."""
Expand All @@ -476,7 +476,7 @@ def onPaletteMotion(self, event):
mouse button is depressed."""
if event.LeftIsDown():
self.doPaletteClick(event.GetX(), event.GetY())

def onPaletteCaptureLost(self, event):
pass # I don't think we have to call ReleaseMouse in this event

Expand All @@ -485,13 +485,13 @@ def doPaletteClick(self, m_x, m_y):
over the palette."""
# Get the colour value, combine with H slider value, and update
colour = self.palette.GetValue(m_x, m_y)

# Update colour, but do not move V slider
self.colour_slider.SetBaseColour(colour)
self.colour_slider.ReDraw()

colour = self.getColourFromControls()

self.updateDisplayColour(colour) # Update display
self.UpdateEntries(colour)

Expand All @@ -504,58 +504,58 @@ def onScroll(self, event):
colour = self.getColourFromControls()
self.updateDisplayColour(colour)
self.UpdateEntries(colour)

def getValueAsFloat(self, textctrl):
"""If you type garbage, you get, literally, nothing (0)"""
try:
return float(textctrl.GetValue())
except ValueError:
return 0

def onHSVKillFocus(self, event):
h = self.getValueAsFloat(self.hentry)

h = self.getValueAsFloat(self.hentry)
s = self.getValueAsFloat(self.sentry)
v = self.getValueAsFloat(self.ventry)

if h > 0.9999:
h = 0.9999
if s > 0.9999:
s = 0.9999
if v > 0.9999:
v = 0.9999

if h < 0:
h = 0
if s < 0:
s = 0
if v < 0:
v = 0

colour = self.hsvToColour((h, s, v))
self.SetValue(colour) # infinite loop?

def onRGBKillFocus(self, event):
r = self.getValueAsFloat(self.rentry)
g = self.getValueAsFloat(self.gentry)
b = self.getValueAsFloat(self.bentry)

if r > 255:
r = 255
if g > 255:
g = 255
if b > 255:
b = 255

if r < 0:
r = 0
if g < 0:
g = 0
if b < 0:
b = 0

self.SetValue(wx.Colour((r, g, b)))

def SetValue(self, colour):
"""Updates the colour chooser to reflect the given wxColour."""
self.UpdateColour(colour)
Expand All @@ -566,24 +566,24 @@ def GetValue(self):

def main():
"""Simple test display."""

class CCTestDialog(wx.Dialog):
def __init__(self, parent, initColour):
super().__init__(parent, title="Pick A Colo(u)r")

sizer = wx.BoxSizer(wx.VERTICAL)
self.chooser = PyColourChooser(self, wx.ID_ANY)
self.chooser.SetValue(initColour)
sizer.Add(self.chooser)

self.SetSizer(sizer)
sizer.Fit(self)

class CCTestFrame(wx.Frame):
def __init__(self):
super().__init__(None, -1, 'PyColourChooser Test')
sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add(wx.StaticText(self, label="CLICK ME"), 0, wx.CENTER)

self.box = pycolourbox.PyColourBox(self, id=wx.ID_ANY, size=(100,100))
Expand All @@ -593,16 +593,16 @@ def __init__(self):

self.SetSizer(sizer)
sizer.Fit(self)

def onClick(self, cmdEvt):
with CCTestDialog(self, self.box.GetColour()) as dialog:
dialog.chooser.Bind(EVT_COLOUR_CHANGED, self.onColourChanged)
dialog.ShowModal()
self.box.SetColour(dialog.chooser.GetValue())

def onColourChanged(self, event):
self.box.SetColour(event.GetValue())

class App(wx.App):
def OnInit(self):
frame = CCTestFrame()
Expand All @@ -616,7 +616,7 @@ def OnInit(self):
frame.Show(True)
self.SetTopWindow(frame)
return True

app = App(False)
app.MainLoop()

Expand Down
2 changes: 1 addition & 1 deletion wx/lib/colourchooser/pycolourslider.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def GetVFromClick(self, pos):
return 1 # Snap to max
if pos >= height - 1:
return 0 # Snap to 0

return 1 - (pos / self.HEIGHT)

def DrawBuffer(self):
Expand Down
12 changes: 6 additions & 6 deletions wx/lib/colourchooser/pypalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PyPalette(canvas.Canvas):

HORIZONTAL_STEP = 2
VERTICAL_STEP = 4

def __init__(self, parent, id):
"""Creates a palette object."""
# Load the pre-generated palette XPM
Expand All @@ -127,13 +127,13 @@ def __init__(self, parent, id):

self.palette = Image.GetBitmap()
self.point = None

canvas.Canvas.__init__ (self, parent, id, forceClientSize=IMAGE_SIZE)

def DoGetBestClientSize(self):
"""Overridden to create a client window that exactly fits our bitmap"""
return self.palette.GetSize()

def xInBounds(self, x):
"""Limit x to [0,width)"""
if x < 0:
Expand Down Expand Up @@ -161,7 +161,7 @@ def GetValue(self, x, y):
def DrawBuffer(self):
"""Draws the palette XPM into the memory buffer."""
self.buffer.DrawBitmap(self.palette, 0, 0, 0)

if self.point:
colour = wx.Colour(0, 0, 0)
self.buffer.SetPen(wx.Pen(colour, 1, wx.PENSTYLE_SOLID))
Expand All @@ -173,7 +173,7 @@ def HighlightPoint(self, x, y):
the coordinate point"""
self.point = (self.xInBounds(x), self.yInBounds(y))
self.ReDraw()

def ClearPoint(self):
self.point = None

Expand Down

0 comments on commit 17aaf52

Please sign in to comment.