diff --git a/wx/lib/agw/cubecolourdialog.py b/wx/lib/agw/cubecolourdialog.py index 9628ad47..fbf3784b 100644 --- a/wx/lib/agw/cubecolourdialog.py +++ b/wx/lib/agw/cubecolourdialog.py @@ -62,7 +62,7 @@ Some features: by using the same 500 web colours "database"; - When available, a corresponding "Microsoft Access Code" for the selected colour is displayed, by using the same 500 web colours "database". - + And much more. @@ -76,7 +76,7 @@ Usage example:: # Our normal wxApp-derived class, as usual app = wx.App(0) - + colourData = wx.ColourData() dlg = CCD.CubeColourDialog(None, colourData) @@ -99,7 +99,7 @@ Usage example:: dlg.Destroy() app.MainLoop() - + Window Styles @@ -123,7 +123,7 @@ Events Processing License And Version =================== -:class:`CubeColourDialog` is distributed under the wxPython license. +:class:`CubeColourDialog` is distributed under the wxPython license. Latest Revision: Andrea Gavana @ 19 Dec 2012, 21.00 GMT @@ -1205,9 +1205,9 @@ def rad2deg(x): """ Transforms radians into degrees. - :param `x`: a float representing an angle in radians. + :param `x`: a float representing an angle in radians. """ - + return 180.0*x/pi @@ -1215,7 +1215,7 @@ def deg2rad(x): """ Transforms degrees into radians. - :param `x`: a float representing an angle in degrees. + :param `x`: a float representing an angle in degrees. """ return x*pi/180.0 @@ -1225,8 +1225,8 @@ def toscale(x): """ Normalize a value as a function of the radius. - :param `x`: a float value to normalize - """ + :param `x`: a float value to normalize + """ return x*RADIUS/255.0 @@ -1235,8 +1235,8 @@ def scaletomax(x): """ Normalize a value as a function of the radius. - :param `x`: a float value to normalize - """ + :param `x`: a float value to normalize + """ return x*255.0/RADIUS @@ -1251,7 +1251,7 @@ def rgb2html(colour): hexColour = "#%02x%02x%02x"%(colour.r, colour.g, colour.b) return hexColour.upper() - + def Slope(pt1, pt2): """ Calculates the slope of the line connecting 2 points. @@ -1278,29 +1278,29 @@ def Intersection(line1, line2): """ if line1.slope == line2.slope: - + # Parallel lines, no intersection return wx.Point(0, 0) - + elif line1.slope is None: - + # First Line is vertical, eqn is x=0 # Put x = 0 in second line eqn to get y x = line1.x y = line2.slope*x + line2.c - + elif line2.slope is None: - + # second line is vertical Equation of line is x=0 # Put x = 0 in first line eqn to get y x = line2.x y = line1.slope*line2.x + line1.c - + else: - + y = ((line1.c*line2.slope) - (line2.c*line1.slope))/(line2.slope - line1.slope) x = (y - line1.c)/line1.slope - + return wx.Point(int(x), int(y)) @@ -1312,7 +1312,7 @@ def FindC(line): c = line.y else: c = line.y - line.slope*line.x - + return c @@ -1322,7 +1322,7 @@ def PointOnLine(pt1, pt2, length, maxLen): a = float(length) if pt2.x != pt1.x: - + m = float((pt2.y - pt1.y))/(pt2.x - pt1.x) m2 = m*m a2 = a*a @@ -1330,40 +1330,40 @@ def PointOnLine(pt1, pt2, length, maxLen): c2 = c*c A = 1.0 - + x = pt1.x B = 2.0 * pt1.x x *= x C = x - a2/(m2 + 1) - + x = (B + sqrt(B*B - (4.0*A*C)))/(2.0*A) y = m*x + c pt = wx.Point(int(x), int(y)) if Distance(pt, pt1) > maxLen or Distance(pt, pt2) > maxLen: - + x = (B - sqrt(B*B - (4.0*A*C)))/(2.0*A) y = m*x + c pt = wx.Point(int(x), int(y)) - + else: - + a2 = a*a y = sqrt(a2) x = 0.0 pt = wx.Point(int(x), int(y)) pt.x += pt1.x pt.y += pt1.y - + if Distance(pt, pt1) > maxLen or Distance(pt, pt2) > maxLen: - y = -1.0*y + y = -1.0*y pt = wx.Point(int(x), int(y)) pt.x += pt1.x pt.y += pt1.y - + return pt @@ -1391,13 +1391,13 @@ def AngleFromPoint(pt, center): y = -1*(pt.y - center.y) x = pt.x - center.x if x == 0 and y == 0: - + return 0.0 - + else: - + return atan2(y, x) - + def PtFromAngle(angle, sat, center): """ @@ -1418,7 +1418,7 @@ def PtFromAngle(angle, sat, center): pt = wx.Point(int(x), -int(y)) pt.x += center.x pt.y += center.y - + return pt @@ -1445,7 +1445,7 @@ def DrawCheckerBoard(dc, rect, checkColour, box=5): :param `rect`: the client rectangle on which to draw the checkerboard; :param `checkColour`: the colour used for the dark checkerboards; :param `box`: the checkerboards box sizes. - + :note: Used for the Alpha channel control and the colour panels. """ @@ -1453,17 +1453,17 @@ def DrawCheckerBoard(dc, rect, checkColour, box=5): checkPen = wx.Pen(checkColour) checkBrush = wx.Brush(checkColour) - dc.SetPen(checkPen) + dc.SetPen(checkPen) dc.SetBrush(checkBrush) dc.SetClippingRegion(rect) - - while y < rect.height: + + while y < rect.height: x = box*((y//box)%2) + 2 - while x < rect.width: - dc.DrawRectangle(x, y, box, box) - x += box*2 + while x < rect.width: + dc.DrawRectangle(x, y, box, box) + x += box*2 y += box - + class Colour(wx.Colour): @@ -1486,13 +1486,13 @@ class Colour(wx.Colour): self.g = colour.Green() self.b = colour.Blue() self._alpha = colour.Alpha() - + self.ToHSV() - + def ToRGB(self): """ Converts a HSV triplet into a RGB triplet. """ - + maxVal = self.v delta = (maxVal*self.s)/255.0 minVal = maxVal - delta @@ -1500,54 +1500,54 @@ class Colour(wx.Colour): hue = float(self.h) if self.h > 300 or self.h <= 60: - + self.r = maxVal - + if self.h > 300: - + self.g = int(minVal) hue = (hue - 360.0)/60.0 self.b = int(-(hue*delta - minVal)) - + else: - + self.b = int(minVal) hue = hue/60.0 self.g = int(hue*delta + minVal) - + elif self.h > 60 and self.h < 180: - + self.g = int(maxVal) - + if self.h < 120: - + self.b = int(minVal) hue = (hue/60.0 - 2.0)*delta self.r = int(minVal - hue) - + else: - + self.r = int(minVal) hue = (hue/60.0 - 2.0)*delta self.b = int(minVal + hue) - - + + else: - + self.b = int(maxVal) - + if self.h < 240: - + self.r = int(minVal) hue = (hue/60.0 - 4.0)*delta self.g = int(minVal - hue) - + else: - + self.g = int(minVal) hue = (hue/60.0 - 4.0)*delta self.r = int(minVal + hue) - + def ToHSV(self): """ Converts a RGB triplet into a HSV triplet. """ @@ -1555,37 +1555,37 @@ class Colour(wx.Colour): minVal = float(min(self.r, min(self.g, self.b))) maxVal = float(max(self.r, max(self.g, self.b))) delta = maxVal - minVal - + self.v = int(maxVal) - + if abs(delta) < 1e-6: - + self.h = self.s = 0 - + else: - + temp = delta/maxVal self.s = int(temp*255.0) if self.r == int(maxVal): - + temp = float(self.g-self.b)/delta - + elif self.g == int(maxVal): - + temp = 2.0 + (float(self.b-self.r)/delta) - + else: - + temp = 4.0 + (float(self.r-self.g)/delta) - + temp *= 60 if temp < 0: - + temp += 360 - + elif temp >= 360.0: - + temp = 0 self.h = int(temp) @@ -1596,21 +1596,21 @@ class Colour(wx.Colour): return wx.Colour(self.r, self.g, self.b, self._alpha) - - + + class LineDescription(object): """ Simple class to store description and constants for a line in 2D space. """ def __init__(self, x=0, y=0, slope=None, c=None): """ Default class constructor. - + Used internally. Do not call it in your code! :param `x`: the x coordinate of the first point; :param `y`: the y coordinate of the first point; :param `slope`: the line's slope; - :param `c`: a floating point constant. + :param `c`: a floating point constant. """ self.x = x @@ -1640,7 +1640,7 @@ class BasePyControl(wx.Control): self._bitmap = bitmap mask = wx.Mask(self._bitmap, wx.Colour(192, 192, 192)) self._bitmap.SetMask(mask) - + self._mainDialog = wx.GetTopLevelParent(self) self.Bind(wx.EVT_SIZE, self.OnSize) @@ -1660,13 +1660,13 @@ class BasePyControl(wx.Control): dc = wx.AutoBufferedPaintDC(self) dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour())) - + dc.Clear() dc.DrawBitmap(self._bitmap, 0, 0, True) if self._mainDialog._initOver: self.DrawMarkers(dc) - + def OnEraseBackground(self, event): """ @@ -1674,18 +1674,18 @@ class BasePyControl(wx.Control): :param `event`: a :class:`EraseEvent` event to be processed. - :note: This is intentionally empty to reduce flicker. + :note: This is intentionally empty to reduce flicker. """ pass - + def DrawMarkers(self, dc=None): """ Draws the markers on top of the background bitmap. :param `dc`: an instance of :class:`wx.DC`. - + :note: This method must be overridden in derived classes. """ @@ -1697,12 +1697,12 @@ class BasePyControl(wx.Control): Draws the lines connecting the markers on top of the background bitmap. :param `dc`: an instance of :class:`wx.DC`. - + :note: This method must be overridden in derived classes. """ pass - + def AcceptsFocusFromKeyboard(self): """ @@ -1731,13 +1731,13 @@ class BasePyControl(wx.Control): return False - + def OnLeftDown(self, event): """ Handles the ``wx.EVT_LEFT_DOWN`` for :class:`BasePyControl`. :param `event`: a :class:`MouseEvent` event to be processed. - + :note: This method must be overridden in derived classes. """ @@ -1749,7 +1749,7 @@ class BasePyControl(wx.Control): Handles the ``wx.EVT_LEFT_UP`` for :class:`BasePyControl`. :param `event`: a :class:`MouseEvent` event to be processed. - + :note: This method must be overridden in derived classes. """ @@ -1761,13 +1761,13 @@ class BasePyControl(wx.Control): Handles the ``wx.EVT_MOTION`` for :class:`BasePyControl`. :param `event`: a :class:`MouseEvent` event to be processed. - + :note: This method must be overridden in derived classes. """ pass - - + + def OnSize(self, event): """ Handles the ``wx.EVT_SIZE`` for :class:`BasePyControl`. @@ -1776,7 +1776,7 @@ class BasePyControl(wx.Control): """ self.Refresh() - + def DoGetBestSize(self): """ @@ -1786,9 +1786,9 @@ class BasePyControl(wx.Control): :note: Overridden from :class:`wx.Control`. """ - return wx.Size(self._bitmap.GetWidth(), self._bitmap.GetHeight()) + return wx.Size(self._bitmap.GetWidth(), self._bitmap.GetHeight()) + - class RGBCube(BasePyControl): """ @@ -1801,7 +1801,7 @@ class RGBCube(BasePyControl): Default class constructor. Used internally. Do not call it in your code! - :param `parent`: the control parent window. + :param `parent`: the control parent window. """ BasePyControl.__init__(self, parent, bitmap=RGBCubeImage.GetBitmap()) @@ -1815,7 +1815,7 @@ class RGBCube(BasePyControl): :param `dc`: an instance of :class:`wx.DC`. """ - + if dc is None: dc = wx.ClientDC(self) @@ -1844,7 +1844,7 @@ class RGBCube(BasePyControl): RestoreOldDC(dc, oldPen, oldBrush, oldMode) self._rects = rects - + def DrawLines(self, dc): """ @@ -1852,9 +1852,9 @@ class RGBCube(BasePyControl): :param `dc`: an instance of :class:`wx.DC`. """ - + cuboid = self._mainDialog._cuboid - + dc.DrawLine(cuboid[1], cuboid[2]) dc.DrawLine(cuboid[2], cuboid[3]) dc.DrawLine(cuboid[3], cuboid[4]) @@ -1866,7 +1866,7 @@ class RGBCube(BasePyControl): dc.DrawLine(cuboid[7], cuboid[4]) dc.DrawLine(cuboid[1], cuboid[6]) - + def OnLeftDown(self, event): """ @@ -1874,7 +1874,7 @@ class RGBCube(BasePyControl): :param `event`: a :class:`MouseEvent` event to be processed. """ - + point = wx.Point(event.GetX(), event.GetY()) self._mouseIn = False @@ -1882,29 +1882,29 @@ class RGBCube(BasePyControl): self.CaptureMouse() self._mouseIn = True self._index = RED - + elif self._rects[GREEN].Contains(point): self.CaptureMouse() self._mouseIn = True self._index = GREEN - + elif self._rects[BLUE].Contains(point): self.CaptureMouse() self._mouseIn = True self._index = BLUE - + def OnLeftUp(self, event): """ Handles the ``wx.EVT_LEFT_UP`` for :class:`RGBCube`. :param `event`: a :class:`MouseEvent` event to be processed. """ - + if self.GetCapture(): self.ReleaseMouse() self._mouseIn = False - + def OnMotion(self, event): """ @@ -1912,9 +1912,9 @@ class RGBCube(BasePyControl): :param `event`: a :class:`MouseEvent` event to be processed. """ - + point = wx.Point(event.GetX(), event.GetY()) - + if not (self.GetCapture() and self._mouseIn): event.Skip() return @@ -1926,17 +1926,17 @@ class RGBCube(BasePyControl): dc = wx.ClientDC(self) self.DrawMarkers(dc) - + if self._index == RED: - - if point.y > Vertex.y: + + if point.y > Vertex.y: point.y = Vertex.y - + point.x = Vertex.x val = Distance(point, Vertex) if val > redLen: val = redLen - + val = (float(val)/redLen)*255.0 colour.r = int(val) @@ -1945,17 +1945,17 @@ class RGBCube(BasePyControl): 2*RECT_WIDTH, 2*RECT_WIDTH) bChange = True - + elif self._index == GREEN: - - if point.x > Vertex.x: + + if point.x > Vertex.x: point.x = Vertex.x - + point.y = self._rects[GREEN].GetTop() + RECT_WIDTH val = Distance(point, Vertex) if val > greenLen: val = greenLen - + val = (float(val)/greenLen)*255.0 colour.g = int(val) @@ -1964,9 +1964,9 @@ class RGBCube(BasePyControl): 2*RECT_WIDTH, 2*RECT_WIDTH) bChange = True - + elif self._index == BLUE: - + if point.x < Vertex.x: point.x = Vertex.x @@ -1974,21 +1974,21 @@ class RGBCube(BasePyControl): val = Distance(point, Vertex) if val > blueLen: val = blueLen - + val = (float(val)/blueLen)*255.0 colour.b = int(val) pt = PointOnLine(Vertex, Right, (colour.b*blueLen)/255.0, blueLen) self._rects[BLUE] = wx.Rect(pt.x - RECT_WIDTH, pt.y - RECT_WIDTH, 2*RECT_WIDTH, 2*RECT_WIDTH) - + bChange = True - + if bChange: mainDialog.CalcCuboid() self.DrawMarkers(dc) - + colour.ToHSV() mainDialog.SetSpinVals() mainDialog.CalcRects() @@ -1996,8 +1996,8 @@ class RGBCube(BasePyControl): mainDialog.DrawHSB() mainDialog.DrawBright() mainDialog.DrawAlpha() - - + + class HSVWheel(BasePyControl): """ Implements the drawing, mouse handling and sizing routines for the HSV @@ -2030,10 +2030,10 @@ class HSVWheel(BasePyControl): dc.SetPen(wx.WHITE_PEN) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.XOR) - + dc.DrawRectangle(self._mainDialog._currentRect) RestoreOldDC(dc, oldPen, oldBrush, oldMode) - + def OnLeftDown(self, event): """ @@ -2076,7 +2076,7 @@ class HSVWheel(BasePyControl): if self.GetCapture() and self._mouseIn: self.TrackPoint(point) - + def InCircle(self, pt): """ @@ -2102,7 +2102,7 @@ class HSVWheel(BasePyControl): self.DrawMarkers(dc) mainDialog = self._mainDialog colour = mainDialog._colour - + colour.h = int(rad2deg(AngleFromPoint(pt, mainDialog._centre))) if colour.h < 0: colour.h += 360 @@ -2115,7 +2115,7 @@ class HSVWheel(BasePyControl): self.DrawMarkers(dc) colour.ToRGB() mainDialog.SetSpinVals() - + mainDialog.CalcCuboid() mainDialog.DrawRGB() mainDialog.DrawBright() @@ -2137,10 +2137,10 @@ class BaseLineCtrl(wx.Control): """ wx.Control.__init__(self, parent, size=(20, 200), style=wx.NO_BORDER) - self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) + self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self._mainDialog = wx.GetTopLevelParent(self) - + self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) @@ -2154,12 +2154,12 @@ class BaseLineCtrl(wx.Control): :param `event`: a :class:`EraseEvent` event to be processed. - :note: This is intentionally empty to reduce flicker. + :note: This is intentionally empty to reduce flicker. """ pass - + def OnLeftDown(self, event): """ Handles the ``wx.EVT_LEFT_DOWN`` for :class:`BaseLineCtrl`. @@ -2173,7 +2173,7 @@ class BaseLineCtrl(wx.Control): if not theRect.Contains(point): event.Skip() return - + self.CaptureMouse() self.TrackPoint(point) @@ -2187,7 +2187,7 @@ class BaseLineCtrl(wx.Control): if self.GetCapture(): self.ReleaseMouse() - + def OnMotion(self, event): """ @@ -2219,7 +2219,7 @@ class BaseLineCtrl(wx.Control): :note: Overridden from :class:`wx.Control`. """ - return wx.Size(24, 208) + return wx.Size(24, 208) def BuildRect(self): @@ -2251,7 +2251,7 @@ class BaseLineCtrl(wx.Control): def AcceptsFocus(self): """ - Can this window be given focus by mouse click? + Can this window be given focus by mouse click? :note: This method always returns ``False`` as we do not accept focus from mouse click. @@ -2280,7 +2280,7 @@ class BrightCtrl(BaseLineCtrl): BaseLineCtrl.__init__(self, parent) self.Bind(wx.EVT_PAINT, self.OnPaint) - + def OnPaint(self, event): """ Handles the ``wx.EVT_PAINT`` for :class:`BrightCtrl`. @@ -2291,10 +2291,10 @@ class BrightCtrl(BaseLineCtrl): dc = wx.AutoBufferedPaintDC(self) dc.SetBackground(wx.Brush(self.GetParent().GetBackgroundColour())) dc.Clear() - + colour = self._mainDialog._colour.GetPyColour() brightRect = self.BuildRect() - + target_red = colour.Red() target_green = colour.Green() target_blue = colour.Blue() @@ -2303,21 +2303,21 @@ class BrightCtrl(BaseLineCtrl): target_blue / 255.0) v = 1.0 vstep = 1.0/(brightRect.height-1) - + for y_pos in range(brightRect.y, brightRect.height+brightRect.y): r, g, b = [c * 255.0 for c in colorsys.hsv_to_rgb(h, s, v)] colour = wx.Colour(int(r), int(g), int(b)) - dc.SetPen(wx.Pen(colour, 1, wx.SOLID)) + dc.SetPen(wx.Pen(colour, 1, wx.PENSTYLE_SOLID)) dc.DrawRectangle(brightRect.x, y_pos, brightRect.width, 1) v = v - vstep dc.SetPen(wx.BLACK_PEN) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangle(brightRect) - + self.DrawMarkers(dc) - - + + def TrackPoint(self, pt): """ Tracks a mouse action inside the palette control. @@ -2333,11 +2333,11 @@ class BrightCtrl(BaseLineCtrl): d = 0 if d > 255: d = 255 - + mainDialog = self._mainDialog colour = mainDialog._colour - mainDialog.DrawMarkers() + mainDialog.DrawMarkers() colour.v = int(d) colour.ToRGB() @@ -2358,10 +2358,10 @@ class BrightCtrl(BaseLineCtrl): if dc is None: dc = wx.ClientDC(self) - + colour = self._mainDialog._colour brightRect = self.BuildRect() - + y = int(colour.v/255.0*brightRect.height) y = brightRect.GetBottom() - y brightMark = wx.Rect(brightRect.x-2, y-4, brightRect.width+4, 8) @@ -2370,7 +2370,7 @@ class BrightCtrl(BaseLineCtrl): dc.SetPen(wx.Pen(wx.WHITE, 2)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.XOR) - + dc.DrawRectangle(brightMark) RestoreOldDC(dc, oldPen, oldBrush, oldMode) @@ -2378,7 +2378,7 @@ class BrightCtrl(BaseLineCtrl): class AlphaCtrl(BaseLineCtrl): """ Implements the drawing, mouse handling and sizing routines for the alpha - channel control. + channel control. """ def __init__(self, parent): @@ -2407,7 +2407,7 @@ class AlphaCtrl(BaseLineCtrl): fullRect = self.GetClientRect() bmp = wx.Bitmap(fullRect.width, fullRect.height) mem_dc.SelectObject(bmp) - + rect = self.BuildRect() backBrush = wx.Brush(self.GetParent().GetBackgroundColour()) mem_dc.SetBackground(backBrush) @@ -2419,16 +2419,16 @@ class AlphaCtrl(BaseLineCtrl): DrawCheckerBoard(mem_dc, rect, checkColour) self.DrawAlphaShading(mem_dc, rect) mem_dc.DestroyClippingRegion() - + self.DrawMarkers(mem_dc) - + mem_dc.SetBrush(wx.TRANSPARENT_BRUSH) mem_dc.SetPen(wx.BLACK_PEN) mem_dc.DrawRectangle(rect) mem_dc.SelectObject(wx.NullBitmap) pdc.DrawBitmap(bmp, 0, 0) - + def DrawAlphaShading(self, dc, rect): """ @@ -2439,19 +2439,19 @@ class AlphaCtrl(BaseLineCtrl): """ gcdc = wx.GCDC(dc) - + colour = self._mainDialog._colour.GetPyColour() - + alpha = 255 vstep = 255.0*2/(rect.height-1) r, g, b = colour.Red(), colour.Green(), colour.Blue() colour_gcdc = wx.Colour(r, g, b, alpha) gcdc.SetBrush(wx.TRANSPARENT_BRUSH) - + for y_pos in range(rect.y, rect.height+rect.y, 2): colour_gcdc = wx.Colour(r, g, b, int(alpha)) - gcdc.SetPen(wx.Pen(colour_gcdc, 1, wx.SOLID)) + gcdc.SetPen(wx.Pen(colour_gcdc, 1, wx.PENSTYLE_SOLID)) gcdc.DrawRectangle(rect.x, y_pos, rect.width, 2) alpha = alpha - vstep @@ -2486,10 +2486,10 @@ class AlphaCtrl(BaseLineCtrl): if dc is None: dc = wx.ClientDC(self) - + colour = self._mainDialog._colour alphaRect = self.BuildRect() - + y = int(colour._alpha/255.0*alphaRect.height) y = alphaRect.GetBottom() - y alphaMark = wx.Rect(alphaRect.x-2, y-4, alphaRect.width+4, 8) @@ -2498,11 +2498,11 @@ class AlphaCtrl(BaseLineCtrl): dc.SetPen(wx.Pen(wx.WHITE, 2)) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetLogicalFunction(wx.XOR) - + dc.DrawRectangle(alphaMark) RestoreOldDC(dc, oldPen, oldBrush, oldMode) - - + + class ColourPanel(wx.Panel): """ Simple custom class used to display "old" and "new" colour panels, with alpha @@ -2520,13 +2520,13 @@ class ColourPanel(wx.Panel): wx.Panel.__init__(self, parent, style=style) self._mainDialog = wx.GetTopLevelParent(self) - + self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_SIZE, self.OnSize) self._colour = Colour(wx.WHITE) - + def OnPaint(self, event): """ @@ -2542,7 +2542,7 @@ class ColourPanel(wx.Panel): rect = self.GetClientRect() bmp = wx.Bitmap(rect.width, rect.height) mem_dc.SelectObject(bmp) - + backBrush = wx.Brush(self.GetParent().GetBackgroundColour()) mem_dc.SetBackground(backBrush) mem_dc.Clear() @@ -2568,11 +2568,11 @@ class ColourPanel(wx.Panel): :param `event`: a :class:`EraseEvent` event to be processed. - :note: This is intentionally empty to reduce flicker. + :note: This is intentionally empty to reduce flicker. """ pass - + def OnSize(self, event): """ @@ -2583,7 +2583,7 @@ class ColourPanel(wx.Panel): self.Refresh() - + def RefreshColour(self, colour): """ Refresh the panel after a colour/alpha change. @@ -2593,8 +2593,8 @@ class ColourPanel(wx.Panel): self._colour = colour self.Refresh() - - + + def AcceptsFocusFromKeyboard(self): """ Can this window be given focus by keyboard navigation? If not, the @@ -2637,14 +2637,14 @@ class CustomPanel(wx.Control): :param `parent`: the control parent window; :param `colourData`: an instance of :class:`wx.ColourData`. """ - + wx.Control.__init__(self, parent, style=wx.NO_BORDER) self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self._colourData = colourData self._customColours = [None]*16 self._mainDialog = wx.GetTopLevelParent(self) - + self.InitializeColours() self._smallRectangleSize = wx.Size(20, 16) @@ -2656,14 +2656,14 @@ class CustomPanel(wx.Control): self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) - + def InitializeColours(self): """ Initializes the 16 custom colours in :class:`CustomPanel`. """ curr = self._colourData.GetColour() self._colourSelection = -1 - + for i in range(16): c = self._colourData.GetCustomColour(i) if c.IsOk(): @@ -2706,7 +2706,7 @@ class CustomPanel(wx.Control): :param `event`: a :class:`EraseEvent` event to be processed. - :note: This is intentionally empty to reduce flicker. + :note: This is intentionally empty to reduce flicker. """ pass @@ -2720,7 +2720,7 @@ class CustomPanel(wx.Control): """ self.Refresh() - + def OnLeftDown(self, event): """ @@ -2730,7 +2730,7 @@ class CustomPanel(wx.Control): """ x, y = event.GetX(), event.GetY() - + selX = (x - self._customColourRect.x)//(self._smallRectangleSize.x + self._gridSpacing) selY = (y - self._customColourRect.y)//(self._smallRectangleSize.y + self._gridSpacing) ptr = selX + selY*8 @@ -2740,7 +2740,7 @@ class CustomPanel(wx.Control): self._colourSelection = ptr self._mainDialog._colour = Colour(self._customColours[self._colourSelection]) - + self.PaintCustomColour(dc, selX, selY) self.PaintHighlight(dc, True) self._mainDialog.DrawAll() @@ -2755,7 +2755,7 @@ class CustomPanel(wx.Control): for i in range(2): for j in range(8): - + ptr = i*8 + j x = (j*(self._smallRectangleSize.x+self._gridSpacing)) + self._customColourRect.x y = (i*(self._smallRectangleSize.y+self._gridSpacing)) + self._customColourRect.y @@ -2766,7 +2766,7 @@ class CustomPanel(wx.Control): dc.SetBrush(brush) dc.DrawRectangle(x, y, self._smallRectangleSize.x, self._smallRectangleSize.y) - + def PaintHighlight(self, dc, draw=True): """ @@ -2806,7 +2806,7 @@ class CustomPanel(wx.Control): :param `dc`: an instance of :class:`wx.DC`; :param `selX`: the x coordinate of the custom colour subpanel; - :param `selY`: the y coordinate of the custom colour subpanel. + :param `selY`: the y coordinate of the custom colour subpanel. """ dc.SetPen(wx.BLACK_PEN) @@ -2832,13 +2832,13 @@ class CustomPanel(wx.Control): self._colourSelection += 1 self._colourSelection = self._colourSelection%16 - + dc = wx.ClientDC(self) self._customColours[self._colourSelection] = colour.GetPyColour() self._colourData.SetCustomColour(self._colourSelection, self._customColours[self._colourSelection]) self.PaintCustomColours(dc) - + class CubeColourDialog(wx.Dialog): """ @@ -2865,7 +2865,7 @@ class CubeColourDialog(wx.Dialog): self._colour = Colour(self._colourData.GetColour()) self._oldColour = Colour(self._colourData.GetColour()) - + self._inMouse = False self._initOver = False self._inDrawAll = False @@ -2888,13 +2888,13 @@ class CubeColourDialog(wx.Dialog): self.showAlpha = wx.CheckBox(self.mainPanel, -1, _("Show Alpha Control")) self.customColours = CustomPanel(self.mainPanel, self._colourData) self.addCustom = wx.Button(self.mainPanel, -1, _("Add to custom colours")) - + self.okButton = wx.Button(self.mainPanel, -1, _("OK")) self.cancelButton = wx.Button(self.mainPanel, -1, _("Cancel")) self.oldColourPanel = ColourPanel(self.mainPanel, style=wx.SIMPLE_BORDER) self.newColourPanel = ColourPanel(self.mainPanel, style=wx.SIMPLE_BORDER) - + self.redSpin = wx.SpinCtrl(self.mainPanel, -1, "180", min=0, max=255, style=wx.SP_ARROW_KEYS) self.greenSpin = wx.SpinCtrl(self.mainPanel, -1, "180", min=0, max=255, @@ -2913,7 +2913,7 @@ class CubeColourDialog(wx.Dialog): self.htmlCode = wx.TextCtrl(self.mainPanel, -1, "", style=wx.TE_READONLY) self.webSafe = wx.TextCtrl(self.mainPanel, -1, "", style=wx.TE_READONLY) self.htmlName = wx.TextCtrl(self.mainPanel, -1, "", style=wx.TE_READONLY) - + self.SetProperties() self.DoLayout() @@ -2924,7 +2924,7 @@ class CubeColourDialog(wx.Dialog): spin.Bind(wx.EVT_SPINCTRL, self.OnSpinCtrl) self.Bind(wx.EVT_SPINCTRL, self.OnAlphaSpin, self.alphaSpin) - + self.Bind(wx.EVT_BUTTON, self.OnOk, self.okButton) self.Bind(wx.EVT_BUTTON, self.OnCancel, self.cancelButton) self.Bind(wx.EVT_BUTTON, self.OnAddCustom, self.addCustom) @@ -2936,8 +2936,8 @@ class CubeColourDialog(wx.Dialog): self.Centre(wx.BOTH) wx.CallAfter(self.InitDialog) - - + + def SetProperties(self): """ Sets some initial properties for :class:`CubeColourDialog` (sizes, values). """ @@ -2976,7 +2976,7 @@ class CubeColourDialog(wx.Dialog): htmlSizer2 = wx.BoxSizer(wx.VERTICAL) htmlSizer_a = wx.BoxSizer(wx.VERTICAL) htmlSizer_b = wx.BoxSizer(wx.VERTICAL) - + hsvSizer = wx.StaticBoxSizer(self.hsvSizer_staticbox, wx.HORIZONTAL) rgbSizer = wx.StaticBoxSizer(self.rgbSizer_staticbox, wx.VERTICAL) alphaSizer = wx.StaticBoxSizer(self.alphaSizer_staticbox, wx.VERTICAL) @@ -2993,11 +2993,11 @@ class CubeColourDialog(wx.Dialog): htmlSizer1.Add(htmlSizer_a, 0) htmlSizer1.Add(htmlSizer_b, 0, wx.LEFT, 10) mainSizer.Add(htmlSizer1, (1, 0), (1, 1), wx.LEFT|wx.RIGHT, 10) - + htmlLabel3 = wx.StaticText(self.mainPanel, -1, _("HTML Name")) htmlSizer2.Add(htmlLabel3, 0, wx.TOP|wx.BOTTOM, 3) htmlSizer2.Add(self.htmlName, 0) - + mainSizer.Add(htmlSizer2, (1, 1), (1, 1), wx.LEFT|wx.RIGHT, 10) customLabel = wx.StaticText(self.mainPanel, -1, _("Custom Colours")) @@ -3013,7 +3013,7 @@ class CubeColourDialog(wx.Dialog): mainSizer.Add(hsvSizer, (2, 1), (1, 1), wx.ALL|wx.EXPAND, 10) alphaSizer.Add(self.alphaCtrl, 0, wx.TOP|wx.ALIGN_CENTER, 15) mainSizer.Add(alphaSizer, (2, 2), (1, 1), wx.ALL|wx.EXPAND, 10) - + oldLabel = wx.StaticText(self.mainPanel, -1, _("Old Colour")) panelSizer.Add(oldLabel, 0, wx.BOTTOM, 3) panelSizer.Add(self.oldColourPanel, 0, wx.BOTTOM|wx.EXPAND, 20) @@ -3066,7 +3066,7 @@ class CubeColourDialog(wx.Dialog): mainSizer.Hide(self.showAlpha) mainSizer.Hide(alphaSizer) mainSizer.Hide(alphaValueSizer) - + dialogSizer.Add(self.mainPanel, 1, wx.EXPAND) self.SetAutoLayout(True) self.SetSizer(dialogSizer) @@ -3077,7 +3077,7 @@ class CubeColourDialog(wx.Dialog): self.mainSizer = mainSizer self.dialogSizer = dialogSizer self.alphaSizers = [alphaSizer, alphaValueSizer] - + def InitDialog(self): """ Initialize the :class:`CubeColourDialog`. """ @@ -3097,13 +3097,13 @@ class CubeColourDialog(wx.Dialog): self._initOver = True wx.CallAfter(self.Refresh) - + def CalcSlopes(self): """ Calculates the line slopes in the RGB colour cube. """ self._lines = {RED: LineDescription(), GREEN: LineDescription(), BLUE: LineDescription} - + self._lines[RED].slope = Slope(Top, Vertex) self._lines[GREEN].slope = Slope(Left, Vertex) self._lines[BLUE].slope = Slope(Right, Vertex) @@ -3178,7 +3178,7 @@ class CubeColourDialog(wx.Dialog): lines[8].c = FindC(lines[8]) self._cuboid[5] = Intersection(lines[7], lines[8]) - + def CalcRects(self): """ Calculates the brightness control user-selected rect. """ @@ -3202,7 +3202,7 @@ class CubeColourDialog(wx.Dialog): self.hsvBitmap.DrawMarkers() self.rgbBitmap.DrawMarkers() self.brightCtrl.DrawMarkers() - + def DrawRGB(self): """ Refreshes the RGB colour cube. """ @@ -3214,7 +3214,7 @@ class CubeColourDialog(wx.Dialog): """ Refreshes the HSB colour wheel. """ self.hsvBitmap.Refresh() - + def DrawBright(self): """ Refreshes the brightness control. """ @@ -3225,32 +3225,32 @@ class CubeColourDialog(wx.Dialog): def DrawAlpha(self): """ Refreshes the alpha channel control. """ - self.alphaCtrl.Refresh() - - + self.alphaCtrl.Refresh() + + def SetSpinVals(self): """ Sets the values for all the spin controls. """ self.redSpin.SetValue(self._colour.r) self.greenSpin.SetValue(self._colour.g) self.blueSpin.SetValue(self._colour.b) - + self.hueSpin.SetValue(self._colour.h) self.saturationSpin.SetValue(self._colour.s) self.brightnessSpin.SetValue(self._colour.v) - self.alphaSpin.SetValue(self._colour._alpha) + self.alphaSpin.SetValue(self._colour._alpha) self.SetPanelColours() self.SetCodes() - + def SetPanelColours(self): """ Assigns colours to the colour panels. """ self.oldColourPanel.RefreshColour(self._oldColour) self.newColourPanel.RefreshColour(self._colour) - + def SetCodes(self): """ Sets the HTML/MS Access codes (if any) in the text controls. """ @@ -3268,12 +3268,12 @@ class CubeColourDialog(wx.Dialog): self.webSafe.SetValue("") self.accessCode.SetValue("") self.htmlName.SetValue("") - - + + def OnCloseWindow(self, event): """ Handles the ``wx.EVT_CLOSE`` event for :class:`CubeColourDialog`. - + :param `event`: a :class:`CloseEvent` event to be processed. """ @@ -3283,7 +3283,7 @@ class CubeColourDialog(wx.Dialog): def OnKeyUp(self, event): """ Handles the ``wx.EVT_CHAR_HOOK`` event for :class:`CubeColourDialog`. - + :param `event`: a :class:`KeyEvent` event to be processed. """ @@ -3291,14 +3291,14 @@ class CubeColourDialog(wx.Dialog): self.EndModal(wx.ID_CANCEL) event.Skip() - + def ShowModal(self): """ Shows :class:`CubeColourDialog` as a modal dialog. Program flow does not return until the dialog has been dismissed with `EndModal`. - :note: Overridden from :class:`Dialog`. + :note: Overridden from :class:`Dialog`. """ return wx.Dialog.ShowModal(self) @@ -3313,31 +3313,31 @@ class CubeColourDialog(wx.Dialog): show = self.GetAGWWindowStyleFlag() & CCD_SHOW_ALPHA self._agwStyle = agwStyle - + self.mainSizer.Show(self.alphaSizers[0], show) self.mainSizer.Show(self.alphaSizers[1], show) self.mainSizer.Fit(self.mainPanel) self.mainSizer.SetSizeHints(self.mainPanel) - self.mainSizer.Layout() + self.mainSizer.Layout() self.dialogSizer.Fit(self) self.dialogSizer.SetSizeHints(self) self.Layout() self.Refresh() self.Update() - + def GetAGWWindowStyleFlag(self): """ Returns the :class:`CubeColourDialog` window style flags. - :see: :meth:`~CubeColourDialog.SetAGWWindowStyleFlag` for a list of possible flags. + :see: :meth:`~CubeColourDialog.SetAGWWindowStyleFlag` for a list of possible flags. """ - return self._agwStyle - - + return self._agwStyle + + def OnOk(self, event): """ Handles the Ok ``wx.EVT_BUTTON`` event for :class:`CubeColourDialog`. @@ -3368,7 +3368,7 @@ class CubeColourDialog(wx.Dialog): self.customColours.AddCustom(self._colour) - + def OnShowAlpha(self, event): """ Shows/hides the alpha channel control in :class:`CubeColourDialog`. @@ -3385,7 +3385,7 @@ class CubeColourDialog(wx.Dialog): agwStyle &= ~CCD_SHOW_ALPHA self.SetAGWWindowStyleFlag(agwStyle) - + def OnSpinCtrl(self, event): """ @@ -3420,14 +3420,14 @@ class CubeColourDialog(wx.Dialog): self._colour._alpha = colourVal self.DrawAlpha() - + def AssignColourValue(self, attribute, colourVal, maxVal, position): """ Common code to handle spin control changes. """ originalVal = getattr(self._colour, attribute) if colourVal != originalVal and self._initOver: - + if colourVal < 0: colourVal = 0 if colourVal > maxVal: @@ -3440,7 +3440,7 @@ class CubeColourDialog(wx.Dialog): self._colour.ToRGB() self.DrawAll() - + def DrawAll(self): """ Draws all the custom controls after a colour change. """ @@ -3450,7 +3450,7 @@ class CubeColourDialog(wx.Dialog): dc1 = wx.ClientDC(self.hsvBitmap) self.hsvBitmap.DrawMarkers(dc1) - + dc2 = wx.ClientDC(self.rgbBitmap) self.rgbBitmap.DrawMarkers(dc2) self.rgbBitmap.DrawLines(dc2) @@ -3460,7 +3460,7 @@ class CubeColourDialog(wx.Dialog): dc4 = wx.ClientDC(self.alphaCtrl) self.alphaCtrl.DrawMarkers(dc4) - + self.CalcCuboid() self.CalcRects() @@ -3468,7 +3468,7 @@ class CubeColourDialog(wx.Dialog): self.DrawHSB() self.DrawBright() self.DrawAlpha() - + self.SetSpinVals() self._inDrawAll = False @@ -3485,7 +3485,7 @@ class CubeColourDialog(wx.Dialog): return (self._colour.r, self._colour.g, self._colour.b, self._colour._alpha) - + def GetHSVAColour(self): """ Returns a 4-elements tuple of hue, saturation, brightness, alpha components. """ @@ -3498,7 +3498,7 @@ if __name__ == '__main__': # Our normal wxApp-derived class, as usual app = wx.App(0) - + colourData = wx.ColourData() colourData.SetColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)) dlg = CubeColourDialog(None, colourData)