diff --git a/DisplayCAL/display_cal.py b/DisplayCAL/display_cal.py index d8564698..0e81de05 100644 --- a/DisplayCAL/display_cal.py +++ b/DisplayCAL/display_cal.py @@ -3712,7 +3712,10 @@ def init_controls(self): # background. Replace with ThemedGenButton which does not have # that issue subst = BorderGradientButton( - btn.Parent, bitmap=geticon(16, "start"), label=btn.Label, name=btn.Name + parent=btn.Parent, + bitmap=geticon(16, "start"), + label=btn.Label, + name=btn.Name, ) subst.SetBackgroundColour(btn.Parent.BackgroundColour) if sys.platform == "win32": diff --git a/DisplayCAL/lib/agw/artmanager.py b/DisplayCAL/lib/agw/artmanager.py index 7898a449..51056389 100644 --- a/DisplayCAL/lib/agw/artmanager.py +++ b/DisplayCAL/lib/agw/artmanager.py @@ -1,12 +1,12 @@ +# -*- coding: utf-8 -*- """Drawing routines and customizations for AGW widgets `LabelBook` and `FlatMenu`.""" import io import random import sys -from ctypes import WinDLL from typing import Callable, Type -from fmresources import ( +from DisplayCAL.lib.agw.fmresources import ( BU_EXT_LEFT_ALIGN_STYLE, BU_EXT_RIGHT_ALIGN_STYLE, BU_EXT_RIGHT_TO_LEFT_STYLE, @@ -48,15 +48,13 @@ class DCSaver(object): - """ - Construct a DC saver. + """Construct a DC saver. The dc is copied as-is. """ def __init__(self, pdc: wx.DC) -> None: - """ - Initialize the default class constructor. + """Initialize the default class constructor. Args: pdc: an instance of :class:`wx.DC`. @@ -81,8 +79,7 @@ class RendererBase(object): """Base class for all theme renderers.""" def __init__(self) -> None: - """ - Initialize the default class constructor. + """Initialize the default class constructor. Intentionally empty. """ @@ -91,8 +88,7 @@ def __init__(self) -> None: def DrawButtonBorders( self, dc: wx.DC, rect: wx.Rect, penColour: wx.Colour, brushColour: wx.Colour ) -> None: - """ - Draws borders for buttons. + """Draws borders for buttons. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -202,8 +198,7 @@ def DrawBitmapBorders( del dcsaver def GetMenuFaceColour(self) -> wx.Colour: - """ - Return the foreground colour for the menu. + """Return the foreground colour for the menu. Returns: An instance of :class:`wx.Colour`. @@ -213,8 +208,7 @@ def GetMenuFaceColour(self) -> wx.Colour: ) def GetTextColourEnable(self) -> wx.Colour: - """ - Return the colour used for text colour when enabled. + """Return the colour used for text colour when enabled. Returns: An instance of :class:`wx.Colour`. @@ -222,8 +216,7 @@ def GetTextColourEnable(self) -> wx.Colour: return wx.BLACK def GetTextColourDisable(self) -> wx.Colour: - """ - Return the colour used for text colour when disabled. + """Return the colour used for text colour when disabled. Returns: An instance of :class:`wx.Colour`. @@ -233,8 +226,7 @@ def GetTextColourDisable(self) -> wx.Colour: ) def GetFont(self) -> wx.Font: - """ - Return the font used for text. + """Return the font used for text. Returns: An instance of :class:`wx.Font`. @@ -248,8 +240,7 @@ def DrawButton( state: int, input: None | bool | wx.Colour = None, ) -> None: - """ - Draws a button using the appropriate theme. + """Draw a button using the appropriate theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -314,8 +305,7 @@ def DrawButton( state: int, input: None | bool | wx.Colour = None, ) -> None: - """ - Draws a button using the XP theme. + """Draws a button using the XP theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -331,8 +321,7 @@ def DrawButton( def DrawButtonTheme( self, dc: wx.DC, rect: wx.Rect, state: int, useLightColours: None | bool ) -> None: - """ - Draws a button using the XP theme. + """Draws a button using the XP theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -358,8 +347,7 @@ def DrawButtonTheme( def DrawButtonColour( self, dc: wx.DC, rect: wx.Rect, state: int, colour: wx.Colour ) -> None: - """ - Draws a button using the XP theme. + """Draws a button using the XP theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -382,8 +370,7 @@ def DrawButtonColour( self.DrawButtonBorders(dc, rect, penColour, brushColour) def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the menu bar background according to the active theme. + """Draws the menu bar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -414,8 +401,7 @@ def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: del dcsaver def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the toolbar background according to the active theme. + """Draws the toolbar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -447,8 +433,7 @@ def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: del dcsaver def GetTextColourEnable(self) -> wx.Colour: - """ - Return the colour used for text colour when enabled. + """Return the colour used for text colour when enabled. Returns: An instance of :class:`wx.Colour`. @@ -469,8 +454,7 @@ def __init__(self) -> None: RendererBase.__init__(self) def GetColoursAccordingToState(self, state: int) -> tuple[int, int, int, int]: - """ - Return a tuple according to the menu item state. + """Return a tuple according to the menu item state. Args: state (int): one of the following bits: @@ -525,8 +509,7 @@ def DrawButton( state: int, input: None | bool | wx.Colour = None, ) -> None: - """ - Draws a button using the MS Office 2007 theme. + """Draw a button using the MS Office 2007 theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -542,8 +525,7 @@ def DrawButton( def DrawButtonTheme( self, dc: wx.DC, rect: wx.Rect, state: int, useLightColours: None | bool ) -> None: - """ - Draws a button using the MS Office 2007 theme. + """Draw a button using the MS Office 2007 theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -559,8 +541,7 @@ def DrawButtonTheme( def DrawButtonColour( self, dc: wx.DC, rect: wx.Rect, state: int, colour: wx.Colour ) -> None: - """ - Draws a button using the MS Office 2007 theme. + """Draw a button using the MS Office 2007 theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -620,8 +601,7 @@ def DrawButtonColour( del dcsaver def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the menu bar background according to the active theme. + """Draw the menu bar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -693,8 +673,7 @@ def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: del dcsaver def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the toolbar background according to the active theme. + """Draw the toolbar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -775,8 +754,7 @@ def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: del dcsaver def GetTextColourEnable(self) -> wx.Colour: - """ - Return the colour used for text colour when enabled. + """Return the colour used for text colour when enabled. Returns: An instance of :class:`wx.Colour`. @@ -819,8 +797,7 @@ def __init__(self) -> None: self._menuBarSelColour = wx.Colour(0, 0, 0) # Default to black def SetTransparency(self, amount: int) -> None: - """ - Set the alpha channel value for transparent windows. + """Set the alpha channel value for transparent windows. Args: amount (int): the actual transparency value (between 0 and 255). @@ -838,8 +815,7 @@ def SetTransparency(self, amount: int) -> None: self._transparency: int = amount def GetTransparency(self) -> int: - """ - Return the alpha channel value for transparent windows. + """Return the alpha channel value for transparent windows. Returns: An integer representing the alpha channel value. @@ -849,8 +825,7 @@ def GetTransparency(self) -> int: def ConvertToBitmap( self, xpm: list[str] | bytes, alpha: None | list[int] = None ) -> wx.Bitmap: - """ - Convert the given image to a bitmap, optionally overlaying an alpha channel. + """Convert the given image to a bitmap, optionally overlaying an alpha channel. Args: xpm (list[str] | bytes): a list of strings formatted as XPM or a @@ -945,8 +920,7 @@ def FillStockBitmaps(self) -> None: self._bitmaps.update({"arrow_up": bmp}) def GetStockBitmap(self, name: str) -> wx.Bitmap: - """ - Return a bitmap from a stock. + """Return a bitmap from a stock. Args: name (str): the bitmap name. @@ -959,8 +933,7 @@ def GetStockBitmap(self, name: str) -> wx.Bitmap: @classmethod def Get(cls: Type["ArtManager"]) -> "ArtManager": - """ - Accessor to the unique art manager object. + """Accessor to the unique art manager object. Returns: An instance of :class:`ArtManager`. @@ -984,8 +957,7 @@ def Free(cls: Type["ArtManager"]) -> None: del cls._instance def OnSysColourChange(self, event: wx.SysColourChangedEvent) -> None: - """ - Handle the ``wx.EVT_SYS_COLOUR_CHANGED`` event for :class:`ArtManager`. + """Handle the ``wx.EVT_SYS_COLOUR_CHANGED`` event for :class:`ArtManager`. Args: event (wx.SysColourChangedEvent): a :class:`SysColourChangedEvent` @@ -995,8 +967,7 @@ def OnSysColourChange(self, event: wx.SysColourChangedEvent) -> None: self.InitColours() def LightColour(self, colour: wx.Colour, percent: int) -> wx.Colour: - """ - Return light contrast of `colour`. + """Return light contrast of `colour`. The colour returned is from the scale of `colour` ==> white. @@ -1025,8 +996,7 @@ def LightColour(self, colour: wx.Colour, percent: int) -> wx.Colour: return wx.Colour(int(r), int(g), int(b), int(a)) def DarkColour(self, colour: wx.Colour, percent: int) -> wx.Colour: - """ - Like :meth:`~ArtManager.LightColour`, but creates a darker colour by `percent`. + """Like :meth:`~ArtManager.LightColour`, but creates a darker colour by `percent`. Args: colour (wx.Colour): the input colour to be darkened, @@ -1059,8 +1029,7 @@ def PaintStraightGradientBox( endColour: wx.Colour, vertical: bool = True, ) -> None: - """ - Paint the rectangle with gradient colouring. + """Paint the rectangle with gradient colouring. The gradient lines are either horizontal or vertical. @@ -1098,8 +1067,7 @@ def PaintGradientRegion( endColour: wx.Colour, vertical: bool = True, ) -> None: - """ - Paint a region with gradient colouring. + """Paint a region with gradient colouring. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1154,8 +1122,7 @@ def PaintDiagonalGradientBox( startAtUpperLeft: bool = True, trimToSquare: bool = True, ) -> None: - """ - Paint rectangle with gradient colouring. + """Paint rectangle with gradient colouring. The gradient lines are diagonal and may start from the upper left corner or from the upper right corner. @@ -1215,8 +1182,7 @@ def PaintDiagonalGradientBox( def calculate_sizes( self, rect: wx.Rect, trimToSquare: bool ) -> tuple[int, int, int, float]: - """ - Calculate the sizes for the gradient drawing. + """Calculate the sizes for the gradient drawing. Args: rect (wx.Rect): the rectangle to be filled with gradient shading. @@ -1251,8 +1217,7 @@ def calculate_sizes( def calculate_steps( self, startColour: wx.Colour, endColour: wx.Colour, size: int ) -> tuple[float, float, float]: - """ - Calculate the gradient steps for the diagonal gradient drawing. + """Calculate the gradient steps for the diagonal gradient drawing. Args: startColour (wx.Colour): the first colour of the gradient shading. @@ -1284,8 +1249,7 @@ def draw_upper_triangle( proportion: float, startAtUpperLeft: bool, ) -> None: - """ - Draw the upper triangle of the diagonal gradient. + """Draw the upper triangle of the diagonal gradient. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1335,8 +1299,7 @@ def draw_lower_triangle( proportion: float, startAtUpperLeft: bool, ) -> None: - """ - Draw the lower triangle of the diagonal gradient. + """Draw the lower triangle of the diagonal gradient. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1383,8 +1346,7 @@ def draw_line_and_point( startAtUpperLeft: bool, lower: bool = False, ) -> None: - """ - Draw a line and a point for the diagonal gradient. + """Draw a line and a point for the diagonal gradient. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1460,8 +1422,7 @@ def PaintCrescentGradientBox( endColour: wx.Colour, concave: bool = True, ) -> None: - """ - Paint a region with gradient colouring. + """Paint a region with gradient colouring. The gradient is in crescent shape which fits the 2007 style. @@ -1507,8 +1468,7 @@ def PaintCrescentGradientBox( ) def FrameColour(self) -> wx.Colour: - """ - Return the surrounding colour for a control. + """Return the surrounding colour for a control. Returns: An instance of :class:`wx.Colour`. @@ -1516,8 +1476,7 @@ def FrameColour(self) -> wx.Colour: return wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION) def BackgroundColour(self) -> wx.Colour: - """ - Return the background colour of a control when not in focus. + """Return the background colour of a control when not in focus. Returns: An instance of :class:`wx.Colour`. @@ -1525,8 +1484,7 @@ def BackgroundColour(self) -> wx.Colour: return self.LightColour(self.FrameColour(), 75) def HighlightBackgroundColour(self) -> wx.Colour: - """ - Return the background colour of a control when it is in focus. + """Return the background colour of a control when it is in focus. Returns: An instance of :class:`wx.Colour`. @@ -1536,8 +1494,7 @@ def HighlightBackgroundColour(self) -> wx.Colour: def MixColours( self, firstColour: wx.Colour, secondColour: wx.Colour, percent: int ) -> wx.Colour: - """ - Return mix of input colours. + """Return mix of input colours. Args: firstColour (wx.Colour): the first colour to be mixed, @@ -1571,8 +1528,7 @@ def MixColours( ) def RandomColour(self) -> wx.Colour: - """ - Create a random colour. + """Create a random colour. Returns: An instance of :class:`wx.Colour`. @@ -1584,8 +1540,7 @@ def RandomColour(self) -> wx.Colour: return wx.Colour(r, g, b) def IsDark(self, colour: wx.Colour) -> bool: - """ - Return whether a colour is dark or light. + """Return whether a colour is dark or light. Args: colour (wx.Colour): an instance of :class:`wx.Colour`. @@ -1601,8 +1556,7 @@ def IsDark(self, colour: wx.Colour) -> bool: return False def TruncateText(self, dc: wx.DC, text: str, maxWidth: int) -> str | None: - """ - Truncate a given string to fit given width size. + """Truncate a given string to fit given width size. If the text does not fit into the given width it is truncated to fit. The format of the fixed text is ``truncate text ...``. @@ -1648,8 +1602,7 @@ def DrawButton( state: int, input: None | bool | wx.Colour = None, ) -> None: - """ - Colour rectangle according to the theme. + """Colour rectangle according to the theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1672,8 +1625,7 @@ def DrawButtonTheme( state: int, useLightColours: bool = True, ) -> None: - """ - Draws a button using the appropriate theme. + """Draws a button using the appropriate theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1700,8 +1652,7 @@ def DrawButtonTheme( def DrawButtonColour( self, dc: wx.DC, rect: wx.Rect, theme: int, state: int, colour: wx.Colour ) -> None: - """ - Draws a button using the appropriate theme. + """Draws a button using the appropriate theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1714,8 +1665,7 @@ def DrawButtonColour( renderer.DrawButton(dc, rect, state, colour) def CanMakeWindowsTransparent(self) -> bool: - """ - Use internally. + """Use internally. Returns: A boolean indicating whether the system supports transparency of @@ -1735,8 +1685,7 @@ def CanMakeWindowsTransparent(self) -> bool: return False def MakeWindowTransparent(self, wnd: wx.TopLevelWindow, amount: int) -> None: - """ - Use internally. + """Use internally. Makes a toplevel window transparent if the system supports it. @@ -1835,8 +1784,7 @@ def DrawBitmapShadow( dc.DrawBitmap(self._bottom, xx, yy, True) def DropShadow(self, wnd: wx.TopLevelWindow, drop: bool = True) -> None: - """ - Add a shadow under the window (Windows only). + """Add a shadow under the window (Windows only). Args: wnd (wx.TopLevelWindow): the window for which we are dropping a shadow, @@ -1851,14 +1799,14 @@ def DropShadow(self, wnd: wx.TopLevelWindow, drop: bool = True) -> None: hwnd: int = wnd.GetHandle() if not hasattr(self, "_winlib"): - try: - import win32api + try: + import win32api - self._winlib = win32api.LoadLibrary("user32") - except ImportError: - import ctypes + self._winlib = win32api.LoadLibrary("user32") + except ImportError: + import ctypes - self._winlib = ctypes.windll.user32 + self._winlib = ctypes.windll.user32 import win32con @@ -1874,11 +1822,9 @@ def DropShadow(self, wnd: wx.TopLevelWindow, drop: bool = True) -> None: return else: csstyle |= CS_DROPSHADOW # Nothing to be done - else: - if csstyle & CS_DROPSHADOW: - csstyle &= ~(CS_DROPSHADOW) + csstyle &= ~CS_DROPSHADOW else: return # Nothing to be done @@ -1894,8 +1840,7 @@ def GetBitmapStartLocation( text: str = "", style: int = 0, ) -> tuple[float, float]: - """ - Return the top left `x` and `y` coordinates of the bitmap drawing. + """Return the top left `x` and `y` coordinates of the bitmap drawing. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -1969,8 +1914,7 @@ def GetBitmapStartLocation( def GetTextStartLocation( self, dc: wx.DC, rect: wx.Rect, bitmap: wx.Bitmap, text: str, style: int = 0 ) -> tuple[float, float, str | None]: - """ - Return the top left `x` and `y` coordinates of the text drawing. + """Return the top left `x` and `y` coordinates of the text drawing. In case the text is too long, the text is being fixed (the text is cut and a '...' mark is added in the end). @@ -2040,8 +1984,7 @@ def DrawTextAndBitmap( grayBitmap: wx.Bitmap = wx.NullBitmap, style: int = 0, ) -> None: - """ - Draws the text & bitmap on the input dc. + """Draw the text & bitmap on the input dc. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -2145,8 +2088,7 @@ def DrawTextAndBitmap( dc.DrawText(after, startLocationX + w1 + w2, startLocationY) def CalcButtonBestSize(self, label: str, bmp: wx.Bitmap) -> wx.Size: - """ - Return the best fit size for the supplied label & bitmap. + """Return the best fit size for the supplied label & bitmap. Args: label (str): the button label. @@ -2186,8 +2128,7 @@ def CalcButtonBestSize(self, label: str, bmp: wx.Bitmap) -> wx.Size: return wx.Size(width, height) def GetMenuFaceColour(self) -> wx.Colour: - """ - Return the colour used for the menu foreground. + """Return the colour used for the menu foreground. Returns: An instance of :class:`wx.Colour`. @@ -2196,8 +2137,7 @@ def GetMenuFaceColour(self) -> wx.Colour: return renderer.GetMenuFaceColour() def GetTextColourEnable(self) -> wx.Colour: - """ - Return the colour used for enabled menu items. + """Return the colour used for enabled menu items. Returns: An instance of :class:`wx.Colour`. @@ -2206,8 +2146,7 @@ def GetTextColourEnable(self) -> wx.Colour: return renderer.GetTextColourEnable() def GetTextColourDisable(self) -> wx.Colour: - """ - Return the colour used for disabled menu items. + """Return the colour used for disabled menu items. Returns: An instance of :class:`wx.Colour`. @@ -2216,8 +2155,7 @@ def GetTextColourDisable(self) -> wx.Colour: return renderer.GetTextColourDisable() def GetFont(self) -> wx.Font: - """ - Return the font used by this theme. + """Return the font used by this theme. Returns: An instance of :class:`wx.Font`. @@ -2226,8 +2164,7 @@ def GetFont(self) -> wx.Font: return renderer.GetFont() def GetAccelIndex(self, label: str) -> tuple[int, str]: - """ - Return the mnemonic index and the label without the ampersand mnemonic. + """Return the mnemonic index and the label without the ampersand mnemonic. (e.g. 'lab&el' ==> will result in 3 and labelOnly = label). @@ -2254,8 +2191,7 @@ def GetAccelIndex(self, label: str) -> tuple[int, str]: return indexAccel, labelOnly def GetThemeBaseColour(self, useLightColours: bool | None = True) -> wx.Colour: - """ - Return the theme base colour or the active caption colour lightened by 30%. + """Return the theme base colour or the active caption colour lightened by 30%. Args: useLightColours (bool | None): ``True`` to use light colours, @@ -2270,8 +2206,7 @@ def GetThemeBaseColour(self, useLightColours: bool | None = True) -> wx.Colour: return self.LightColour(self.FrameColour(), 30) def GetAlignBuffer(self) -> int: - """ - Return the padding buffer for a text or bitmap. + """Return the padding buffer for a text or bitmap. Returns: An integer representing the padding buffer. @@ -2279,8 +2214,7 @@ def GetAlignBuffer(self) -> int: return self._alignmentBuffer def SetMenuTheme(self, theme: int) -> None: - """ - Set the menu theme, possible values (Style2007, StyleXP, StyleVista). + """Set the menu theme, possible values (Style2007, StyleXP, StyleVista). Args: theme (int): a rendering theme class, either `StyleXP`, @@ -2289,8 +2223,7 @@ def SetMenuTheme(self, theme: int) -> None: self._menuTheme = theme def GetMenuTheme(self) -> int: - """ - Return the currently used menu theme. + """Return the currently used menu theme. Returns: An integer representing the currently used theme for the menu. @@ -2298,8 +2231,7 @@ def GetMenuTheme(self) -> int: return self._menuTheme def AddMenuTheme(self, render: RendererBase) -> int: - """ - Add a new theme to the stock. + """Add a new theme to the stock. Args: render (RendererBase): a rendering theme class, @@ -2315,8 +2247,7 @@ def AddMenuTheme(self, render: RendererBase) -> int: return lastRenderer def SetMS2007ButtonSunken(self, sunken: bool) -> None: - """ - Set MS 2007 button style sunken or not. + """Set MS 2007 button style sunken or not. Args: sunken (bool): ``True`` to have a sunken border effect, ``False`` otherwise. @@ -2324,8 +2255,7 @@ def SetMS2007ButtonSunken(self, sunken: bool) -> None: self._ms2007sunken: bool = sunken def GetMS2007ButtonSunken(self) -> bool: - """ - Return the sunken flag for MS 2007 buttons. + """Return the sunken flag for MS 2007 buttons. Returns: A boolean indicating whether the MS 2007 buttons are sunken. @@ -2333,8 +2263,7 @@ def GetMS2007ButtonSunken(self) -> bool: return self._ms2007sunken def GetMBVerticalGradient(self) -> bool: - """ - Return ``True`` if the menu bar should be painted with vertical gradient. + """Return ``True`` if the menu bar should be painted with vertical gradient. Returns: A boolean indicating whether the menu bar should be painted with @@ -2343,8 +2272,7 @@ def GetMBVerticalGradient(self) -> bool: return self._verticalGradient def SetMBVerticalGradient(self, v: bool) -> None: - """ - Set the menu bar gradient style. + """Set the menu bar gradient style. Args: v (bool): ``True`` for a vertical shaded gradient, ``False`` otherwise. @@ -2352,8 +2280,7 @@ def SetMBVerticalGradient(self, v: bool) -> None: self._verticalGradient: bool = v def DrawMenuBarBorder(self, border: bool) -> None: - """ - Enable menu border drawing (XP style only). + """Enable menu border drawing (XP style only). Args: border (bool): ``True`` to draw the menubar border, ``False`` otherwise. @@ -2361,8 +2288,7 @@ def DrawMenuBarBorder(self, border: bool) -> None: self._drowMBBorder: bool = border def GetMenuBarBorder(self) -> bool: - """ - Return menu bar border drawing flag. + """Return menu bar border drawing flag. Returns: A boolean indicating whether the menu bar border is to be drawn. @@ -2370,8 +2296,7 @@ def GetMenuBarBorder(self) -> bool: return self._drowMBBorder def GetMenuBgFactor(self) -> int: - """ - Get the visibility depth of the menu in Metallic style. + """Get the visibility depth of the menu in Metallic style. The higher the value, the menu bar will look more raised. @@ -2381,8 +2306,7 @@ def GetMenuBgFactor(self) -> int: return self._menuBgFactor def DrawDragSash(self, rect: wx.Rect) -> None: - """ - Draws resize sash. + """Draws resize sash. Args: rect (wx.Rect): the sash client rectangle. @@ -2399,8 +2323,7 @@ def DrawDragSash(self, rect: wx.Rect) -> None: dc.Blit(rect.x, rect.y, rect.width, rect.height, mem_dc, 0, 0, wx.XOR) def TakeScreenShot(self, rect: wx.Rect, bmp: wx.Bitmap) -> None: - """ - Take a screenshot of the screen at given position & size (rect). + """Take a screenshot of the screen at given position & size (rect). Args: rect (wx.Rect): the screen rectangle we wish to capture. @@ -2438,8 +2361,7 @@ def TakeScreenShot(self, rect: wx.Rect, bmp: wx.Bitmap) -> None: memDC.SelectObject(wx.NullBitmap) def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the toolbar background according to the active theme. + """Draws the toolbar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -2451,8 +2373,7 @@ def DrawToolBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: renderer.DrawToolBarBg(dc, rect) def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: - """ - Draws the menu bar background according to the active theme. + """Draws the menu bar background according to the active theme. Args: dc (wx.DC): an instance of :class:`wx.DC`. @@ -2463,8 +2384,7 @@ def DrawMenuBarBg(self, dc: wx.DC, rect: wx.Rect) -> None: renderer.DrawMenuBarBg(dc, rect) def SetMenuBarColour(self, scheme: str) -> None: - """ - Set the menu bar colour scheme to use. + """Set the menu bar colour scheme to use. Args: scheme (str): a string representing a colour scheme @@ -2476,8 +2396,7 @@ def SetMenuBarColour(self, scheme: str) -> None: self._menuBarBgColour = self._colourSchemeMap[scheme] def GetMenuBarColourScheme(self) -> str: - """ - Return the current colour scheme. + """Return the current colour scheme. Returns: A string representing the current colour scheme. @@ -2485,8 +2404,7 @@ def GetMenuBarColourScheme(self) -> str: return self._menuBarColourScheme def GetMenuBarFaceColour(self) -> wx.Colour: - """ - Return the menu bar face colour. + """Return the menu bar face colour. Returns: An instance of :class:`wx.Colour`. @@ -2494,8 +2412,7 @@ def GetMenuBarFaceColour(self) -> wx.Colour: return self._menuBarBgColour def GetMenuBarSelectionColour(self) -> wx.Colour: - """ - Return the menu bar selection colour. + """Return the menu bar selection colour. Returns: An instance of :class:`wx.Colour`. @@ -2512,8 +2429,7 @@ def InitColours(self) -> None: } def GetColourSchemes(self) -> list[str]: - """ - Return the available colour schemes. + """Return the available colour schemes. Returns: A list of strings representing the available colour schemes. @@ -2521,8 +2437,7 @@ def GetColourSchemes(self) -> list[str]: return list(self._colourSchemeMap) def CreateGreyBitmap(self, bmp: wx.Bitmap) -> wx.Bitmap: - """ - Create a grey bitmap image from the input bitmap. + """Create a grey bitmap image from the input bitmap. Args: bmp (wx.Bitmap): a valid :class:`wx.Bitmap` object to be greyed out. @@ -2535,8 +2450,7 @@ def CreateGreyBitmap(self, bmp: wx.Bitmap) -> wx.Bitmap: return wx.Bitmap(img.ConvertToGreyscale()) def GetRaiseToolbar(self) -> bool: - """ - Return ``True`` if we are dropping a shadow under a toolbar. + """Return ``True`` if we are dropping a shadow under a toolbar. Returns: A boolean indicating whether a shadow is dropped under a toolbar. @@ -2544,8 +2458,7 @@ def GetRaiseToolbar(self) -> bool: return self._raiseTB def SetRaiseToolbar(self, rais: bool) -> None: - """ - Enables/disables toolbar shadow drop. + """Enables/disables toolbar shadow drop. Args: rais (bool): ``True`` to drop a shadow below a toolbar, ``False`` otherwise. diff --git a/DisplayCAL/lib/agw/gradientbutton.py b/DisplayCAL/lib/agw/gradientbutton.py index 97b0f503..5c664170 100644 --- a/DisplayCAL/lib/agw/gradientbutton.py +++ b/DisplayCAL/lib/agw/gradientbutton.py @@ -24,17 +24,16 @@ # ---------------------------------------------------------------------------- # """ -:class:`~wx.lib.agw.gradientbutton.GradientButton` is another custom-drawn button class which mimics Windows CE mobile -gradient buttons. +:class:`~wx.lib.agw.gradientbutton.GradientButton` is another custom-drawn button class +which mimics Windows CE mobile gradient buttons. Description =========== -:class:`GradientButton` is another custom-drawn button class which mimics -Windows CE mobile gradient buttons, -using a tri-vertex blended gradient plus some ClearType bold font -(best effect with Tahoma Bold). :class:`GradientButton` supports: +:class:`GradientButton` is another custom-drawn button class which mimics Windows CE +mobile gradient buttons, using a tri-vertex blended gradient plus some ClearType bold +font (best effect with Tahoma Bold). :class:`GradientButton` supports: * Triple blended gradient background, with customizable colours; * Custom colours for the "pressed" state; @@ -43,7 +42,6 @@ And a lot more. Check the demo for an almost complete review of the functionalities. - Usage ===== @@ -79,7 +77,6 @@ def __init__(self, parent): app.MainLoop() - Supported Platforms =================== @@ -130,8 +127,7 @@ class GradientButtonEvent(wx.PyCommandEvent): """Event sent from :class:`GradientButton` when the button is activated.""" def __init__(self, eventType, eventId): - """ - Default class constructor. + """Default class constructor. Args: eventType: the event type; @@ -143,8 +139,7 @@ def __init__(self, eventType, eventId): self.theButton = None def SetButtonObj(self, btn): - """ - Sets the event object for the event. + """Sets the event object for the event. Args: btn: the button object, an instance of :class:`GradientButton`. @@ -153,12 +148,12 @@ def SetButtonObj(self, btn): self.theButton = btn def GetButtonObj(self): - """Returns the object associated with this event.""" + """Return the object associated with this event.""" return self.theButton -class GradientButton(wx.PyControl): +class GradientButton(wx.Control): """This is the main class implementation of :class:`GradientButton`.""" def __init__( @@ -174,27 +169,26 @@ def __init__( validator=wx.DefaultValidator, name="gradientbutton", ): - """ - Default class constructor. + """Default class constructor. Args: - parent: the :class:`GradientButton` parent; - id: window identifier. A value of -1 indicates a default value; - bitmap: the button bitmap (if any); - label: the button text label; - pos: the control position. A value of (-1, -1) indicates a default position, + parent (GradientButton): The :class:`GradientButton` parent; + id (wx.WindowID): Window identifier. A value of -1 indicates a default + value. + bitmap (Union[None, wx.Bitmap]): The button bitmap (if any); + label (str): The button text label; + pos (wx.Point): The control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform; - size: the control size. A value of (-1, -1) indicates a default size, + size (wx.Size): The control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform; - style: the button style (unused); - align: text/bitmap alignment. wx.CENTER or wx.LEFT; - validator: the validator associated to the button; - name: the button name. + style (int): The button style (unused); + align (int): Text/bitmap alignment. wx.CENTER or wx.LEFT; + validator (wx.Validator): The validator associated to the button; + name (str): the button name. """ - - wx.Control.__init__(self, parent, id, pos, size, style, validator, name) + super().__init__(parent, id, pos, size, style, validator, name) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None) @@ -207,14 +201,12 @@ def __init__( self.Bind(wx.EVT_KILL_FOCUS, self.OnLoseFocus) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) - self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown) self._mouseAction = None - self.SetBitmapLabel(bitmap) self._hasFocus = False - self._alignment = align + self.SetBitmapLabel(bitmap) self.SetLabel(label) self.InheritAttributes() @@ -223,8 +215,7 @@ def __init__( self.SetBaseColours() def SetBitmapLabel(self, bitmap): - """ - Sets the bitmap label for the button. + """Set the bitmap label for the button. Args: bitmap: the bitmap label to set, an instance of :class:`wx.Bitmap`. @@ -234,8 +225,7 @@ def SetBitmapLabel(self, bitmap): self.Refresh() def SetBaseColours(self, startcolour=wx.BLACK, foregroundcolour=wx.WHITE): - """ - Sets the bottom, top, pressed and foreground colour + """Set the bottom, top, pressed and foreground colour Args: startcolour: based colour to be used for bottom, top and pressed @@ -256,8 +246,7 @@ def SetBaseColours(self, startcolour=wx.BLACK, foregroundcolour=wx.WHITE): self.SetForegroundColour(foregroundcolour) def LightColour(self, colour, percent): - """ - Return light contrast of `colour`. + """Return light contrast of `colour`. The colour returned is from the scale of `colour` ==> white. @@ -283,8 +272,7 @@ def LightColour(self, colour, percent): return wx.Colour(int(r), int(g), int(b), int(a)) def OnSize(self, event): - """ - Handles the ``wx.EVT_SIZE`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_SIZE`` event for :class:`GradientButton`. Args: event: a :class:`wx.SizeEvent` event to be processed. @@ -294,8 +282,7 @@ def OnSize(self, event): self.Refresh() def OnLeftDown(self, event): - """ - Handles the ``wx.EVT_LEFT_DOWN`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_LEFT_DOWN`` event for :class:`GradientButton`. Args: event: a :class:`MouseEvent` event to be processed. @@ -310,8 +297,7 @@ def OnLeftDown(self, event): event.Skip() def OnLeftUp(self, event): - """ - Handles the ``wx.EVT_LEFT_UP`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_LEFT_UP`` event for :class:`GradientButton`. Args: event: a :class:`MouseEvent` event to be processed. @@ -336,8 +322,7 @@ def OnLeftUp(self, event): event.Skip() def OnMouseEnter(self, event): - """ - Handles the ``wx.EVT_ENTER_WINDOW`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_ENTER_WINDOW`` event for :class:`GradientButton`. Args: event: a :class:`MouseEvent` event to be processed. @@ -351,8 +336,7 @@ def OnMouseEnter(self, event): event.Skip() def OnMouseLeave(self, event): - """ - Handles the ``wx.EVT_LEAVE_WINDOW`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_LEAVE_WINDOW`` event for :class:`GradientButton`. Args: event: a :class:`MouseEvent` event to be processed. @@ -363,8 +347,7 @@ def OnMouseLeave(self, event): event.Skip() def OnGainFocus(self, event): - """ - Handles the ``wx.EVT_SET_FOCUS`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_SET_FOCUS`` event for :class:`GradientButton`. Args: event: a :class:`FocusEvent` event to be processed. @@ -375,8 +358,7 @@ def OnGainFocus(self, event): self.Update() def OnLoseFocus(self, event): - """ - Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_KILL_FOCUS`` event for :class:`GradientButton`. Args: event: a :class:`FocusEvent` event to be processed. @@ -387,8 +369,7 @@ def OnLoseFocus(self, event): self.Update() def OnKeyDown(self, event): - """ - Handles the ``wx.EVT_KEY_DOWN`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_KEY_DOWN`` event for :class:`GradientButton`. Args: event: a :class:`KeyEvent` event to be processed. @@ -400,8 +381,7 @@ def OnKeyDown(self, event): event.Skip() def OnKeyUp(self, event): - """ - Handles the ``wx.EVT_KEY_UP`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_KEY_UP`` event for :class:`GradientButton`. Args: event: a :class:`KeyEvent` event to be processed. @@ -414,8 +394,7 @@ def OnKeyUp(self, event): event.Skip() def OnPaint(self, event): - """ - Handles the ``wx.EVT_PAINT`` event for :class:`GradientButton`. + """Handle the ``wx.EVT_PAINT`` event for :class:`GradientButton`. Args: event: a :class:`PaintEvent` event to be processed. @@ -468,7 +447,6 @@ def OnPaint(self, event): gradientRect.Offset((0, gradientRect.GetHeight())) if capture != self: - if self._mouseAction == HOVER: bottomStart, bottomEnd = self.LightColour( self._bottomStartColour, 10 @@ -492,7 +470,6 @@ def OnPaint(self, event): shadowOffset = 0 else: - rc2 = wx.Rect( x + 1, gradientRect.height // 2, gradientRect.width, gradientRect.height ) @@ -538,8 +515,7 @@ def OnPaint(self, event): gc.DrawText(label, pos_x + bw + shadowOffset, (height - th) / 2 + shadowOffset) def GetPath(self, gc, rc, r): - """ - Returns a rounded :class:`GraphicsPath` rectangle. + """Return a rounded :class:`GraphicsPath` rectangle. Args: gc: an instance of :class:`GraphicsContext`; @@ -554,8 +530,7 @@ def GetPath(self, gc, rc, r): return path def SetInitialSize(self, size=None): - """ - Given the current font and bezel width settings, calculate and set a good size. + """Given the current font and bezel width settings, calculate and set a good size. Args: size: an instance of :class:`wx.Size`. @@ -568,18 +543,15 @@ def SetInitialSize(self, size=None): SetBestSize = SetInitialSize def AcceptsFocus(self): - """ - Can this window be given focus by mouse click?. + """Return True if this window can be given focus by mouse click?. Note: Overridden from :class:`wx.Control`. """ - return self.IsShown() and self.IsEnabled() def GetDefaultAttributes(self): - """ - Overridden base class virtual. + """Overridden base class virtual. By default we should use the same font/colour attributes as the native :class:`Button`. @@ -588,8 +560,7 @@ def GetDefaultAttributes(self): return wx.Button.GetClassDefaultAttributes() def ShouldInheritColours(self): - """ - Overridden base class virtual. + """Overridden base class virtual. Buttons usually don't inherit the parent's colours. @@ -600,8 +571,7 @@ def ShouldInheritColours(self): return False def Enable(self, enable=True): - """ - Enables/disables the button. + """Enable/disable the button. Args: enable: ``True`` to enable the button, ``False`` to disable it. @@ -614,8 +584,7 @@ def Enable(self, enable=True): self.Refresh() def SetTopStartColour(self, colour): - """ - Sets the top start colour for the gradient shading. + """Set the top start colour for the gradient shading. Args: colour: a valid :class:`wx.Colour` object. @@ -625,13 +594,12 @@ def SetTopStartColour(self, colour): self.Refresh() def GetTopStartColour(self): - """Returns the top start colour for the gradient shading.""" + """Return the top start colour for the gradient shading.""" return self._topStartColour def SetTopEndColour(self, colour): - """ - Sets the top end colour for the gradient shading. + """Set the top end colour for the gradient shading. Args: colour: a valid :class:`wx.Colour` object. @@ -641,13 +609,12 @@ def SetTopEndColour(self, colour): self.Refresh() def GetTopEndColour(self): - """Returns the top end colour for the gradient shading.""" + """Return the top end colour for the gradient shading.""" return self._topEndColour def SetBottomStartColour(self, colour): - """ - Sets the top bottom colour for the gradient shading. + """Set the top bottom colour for the gradient shading. Args: colour: a valid :class:`wx.Colour` object. @@ -657,13 +624,12 @@ def SetBottomStartColour(self, colour): self.Refresh() def GetBottomStartColour(self): - """Returns the bottom start colour for the gradient shading.""" + """Return the bottom start colour for the gradient shading.""" return self._bottomStartColour def SetBottomEndColour(self, colour): - """ - Sets the bottom end colour for the gradient shading. + """Set the bottom end colour for the gradient shading. Args: colour: a valid :class:`wx.Colour` object. @@ -673,7 +639,7 @@ def SetBottomEndColour(self, colour): self.Refresh() def GetBottomEndColour(self): - """Returns the bottom end colour for the gradient shading.""" + """Return the bottom end colour for the gradient shading.""" return self._bottomEndColour @@ -689,7 +655,7 @@ def SetPressedTopColour(self, colour): self.Refresh() def GetPressedTopColour(self): - """Returns the pressed top start colour for the gradient shading.""" + """Return the pressed top start colour for the gradient shading.""" return self._pressedTopColour @@ -705,13 +671,12 @@ def SetPressedBottomColour(self, colour): self.Refresh() def GetPressedBottomColour(self): - """Returns the pressed bottom start colour for the gradient shading.""" + """Return the pressed bottom start colour for the gradient shading.""" return self._pressedBottomColour def SetForegroundColour(self, colour): - """ - Sets the :class:`GradientButton` foreground (text) colour. + """Set the :class:`GradientButton` foreground (text) colour. Args: colour: a valid :class:`wx.Colour` object. @@ -724,15 +689,13 @@ def SetForegroundColour(self, colour): self.Refresh() def DoGetBestSize(self): - """ - Overridden base class virtual. + """Overridden base class virtual. Determines the best size of the button based on the label and bezel size. Note: Overridden from :class:`wx.Control`. """ - label = self.GetLabel() if not label: return wx.Size(112, 48) @@ -752,15 +715,13 @@ def DoGetBestSize(self): return wx.Size(retWidth + constant, retHeight + constant) def SetDefault(self): - """Sets the default button.""" - + """Set the default button.""" tlw = wx.GetTopLevelParent(self) if hasattr(tlw, "SetDefaultItem"): tlw.SetDefaultItem(self) def Notify(self): - """Actually sends a ``wx.EVT_BUTTON`` event to the listener (if any).""" - + """Actually send a ``wx.EVT_BUTTON`` event to the listener (if any).""" evt = GradientButtonEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.GetId()) evt.SetButtonObj(self) evt.SetEventObject(self) diff --git a/DisplayCAL/wxwindows.py b/DisplayCAL/wxwindows.py index 06bcf0d0..fb3d0776 100644 --- a/DisplayCAL/wxwindows.py +++ b/DisplayCAL/wxwindows.py @@ -3456,7 +3456,16 @@ def __init__( ): self.dpiscale = getcfg("app.dpi") / get_default_dpi() GradientButton.__init__( - self, parent, id, bitmap, label, pos, size, style, validator, name + self, + parent=parent, + id=id, + bitmap=bitmap, + label=label, + pos=pos, + size=size, + style=style, + validator=validator, + name=name, ) self._bgcolour = bgcolour # Original bgcolour self._fgcolour = fgcolour # Original fgcolour @@ -3720,7 +3729,16 @@ def __init__( self.use_sierra_style = sys.platform == "darwin" self._enabled = True GradientButton.__init__( - self, parent, id, bitmap, label, pos, size, style, validator, name + self, + parent=parent, + id=id, + bitmap=bitmap, + label=label, + pos=pos, + size=size, + style=style, + validator=validator, + name=name ) self.SetFont(adjust_font_size_for_gcdc(self.GetFont())) self._bitmapdisabled = self._bitmap