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