Debian Codegraph @

misc/xrced_plugins/xh_floatspin.py

raw
1 import wx
2 import wx.xrc as xrc
3
4 try:
5 import wx.lib.agw.floatspin as floatspin
6 except ImportError:
7 from DisplayCAL import floatspin
8
9
10 class FloatSpinCtrlXmlHandler(xrc.XmlResourceHandler):
11 def __init__(self):
12 xrc.XmlResourceHandler.__init__(self)
13 # Standard styles
14 self.AddWindowStyles()
15 # Custom styles
16 self.AddStyle("FS_LEFT", floatspin.FS_LEFT)
17 self.AddStyle("FS_RIGHT", floatspin.FS_RIGHT)
18 self.AddStyle("FS_CENTRE", floatspin.FS_CENTRE)
19 self.AddStyle("FS_READONLY", floatspin.FS_READONLY)
20
21 def CanHandle(self, node):
22 return self.IsOfClass(node, "FloatSpin")
23
24 # Process XML parameters and create the object
25 def DoCreateResource(self):
26 try:
27 min_val = float(self.GetText("min_val"))
28 except:
29 min_val = None
30 try:
31 max_val = float(self.GetText("max_val"))
32 except:
33 max_val = None
34 try:
35 increment = float(self.GetText("increment"))
36 except:
37 increment = 1.0
38 w = floatspin.FloatSpin(
39 parent=self.GetParentAsWindow(),
40 id=self.GetID(),
41 pos=self.GetPosition(),
42 size=self.GetSize(),
43 style=self.GetStyle(),
44 min_val=min_val,
45 max_val=max_val,
46 increment=increment,
47 name=self.GetName(),
48 )
49
50 try:
51 w.SetValue(float(self.GetText("value")))
52 except:
53 w.SetValue(0.0)
54
55 try:
56 w.SetDigits(int(self.GetText("digits")))
57 except:
58 pass
59
60 self.SetupWindow(w)
61 if self.GetBool("hidden") and w.Shown:
62 print(f"{self.Name} should have been hidden")
63 w.Hide()
64 return w