Debian Codegraph @

DisplayCAL/xh_hstretchstatbmp.py

raw
1 """Custom XML handler for HStretchStaticBitmap controls in wxPython.
2
3 It handles the processing of XML parameters, creation of the control, and its
4 configuration.
5 """
6
7 import wx
8 from wx import xrc
9
10 from DisplayCAL.log import safe_print
11
12 try:
13 from DisplayCAL.wx_windows import HStretchStaticBitmap
14 except ImportError:
15 HStretchStaticBitmap = wx.StaticBitmap
16
17
18 class HStretchStaticBitmapXmlHandler(xrc.XmlResourceHandler):
19 """Custom XML resource handler for HStretchStaticBitmap controls."""
20
21 def __init__(self):
22 xrc.XmlResourceHandler.__init__(self)
23 # Standard styles
24 self.AddWindowStyles()
25
26 def CanHandle(self, node):
27 """Check if the node can be handled by this handler.
28
29 Args:
30 node (xrc.XmlNode): The XML node to check.
31
32 Returns:
33 bool: True if the node is of class HStretchStaticBitmap, False otherwise.
34 """
35 return self.IsOfClass(node, "HStretchStaticBitmap")
36
37 # Process XML parameters and create the object
38 def DoCreateResource(self) -> HStretchStaticBitmap:
39 """Create the HStretchStaticBitmap control from XML parameters.
40
41 Returns:
42 HStretchStaticBitmap: The created HStretchStaticBitmap control.
43 """
44 w = HStretchStaticBitmap(
45 self.GetParentAsWindow(),
46 self.GetID(),
47 self.GetBitmap("bitmap"),
48 pos=self.GetPosition(),
49 size=self.GetSize(),
50 style=self.GetStyle(),
51 name=self.GetName(),
52 )
53
54 self.SetupWindow(w)
55 if self.GetBool("hidden") and w.Shown:
56 safe_print(f"{self.Name} should have been hidden")
57 w.Hide()
58 return w