root/trunk/ide/ClassDesignerCustomPropertyDialog.py

Revision 3515, 4.9 kB (checked in by paul, 1 year ago)

Added the ignore and eol-style props to ide, and removed unneeded files.

  • Property svn:eol-style set to native
Line 
1 # -*- coding: utf-8 -*-
2 import dabo
3 import dabo.dEvents as dEvents
4 if __name__ == "__main__":
5     dabo.ui.loadUI("wx")
6 # This is because I'm a lazy typist
7 dui = dabo.ui
8 from dabo.dLocalize import _
9
10
11 class ClassDesignerCustomPropertyDialog(dui.dOkCancelDialog):
12     def addControls(self):
13         sz = dui.dGridSizer(MaxCols=2, HGap=8, VGap=12)
14         lbl = dui.dLabel(self, Caption=_("Property Name"))
15         self.txtPropName = dui.dTextBox(self, SelectOnEntry=True)
16         self.txtPropName.bindEvent(dEvents.KeyChar, self.onKeyPropName)
17         sz.append(lbl, halign="right")
18         sz.append(self.txtPropName, "x")
19
20         lbl = dui.dLabel(self, Caption=_("Comment"))
21         self.txtComment = dui.dTextBox(self, SelectOnEntry=True)
22         sz.append(lbl, halign="right")
23         sz.append(self.txtComment, "x")
24
25         lbl = dui.dLabel(self, Caption=_("Default Value"))
26         self.txtDefaultVal = dui.dTextBox(self, SelectOnEntry=True, Value=None,
27                 OnKeyChar=self.updEnabled)
28         self.ddType = dui.dDropdownList(self, Choices=["", "string",
29                 "integer", "float", "boolean", "datetime"])
30         self.ddType.PositionValue = 0
31         self.ddType.DynamicEnabled = self.needDefType
32         sz.append(lbl, halign="right")
33         hsz = dui.dSizer("h")
34         hsz.append(self.txtDefaultVal, 1)
35         hsz.append(self.ddType, halign="right", border=5, borderSides="left")
36         sz.append(hsz, "x")
37
38         self.chkGet = chk = dui.dCheckBox(self, Alignment="right",
39                 Caption=_("Get Method"))
40         self.txtGet = dui.dTextBox(self, SelectOnEntry=True)
41         sz.append(chk, halign="right")
42         sz.append(self.txtGet, "x")
43         chk.DataSource = self.txtGet
44         chk.DataField = "Enabled"
45         chk.Value = True
46
47         self.chkSet = chk = dui.dCheckBox(self, Alignment="right",
48                 Caption=_("Set Method"))
49         self.txtSet = dui.dTextBox(self, SelectOnEntry=True)
50         sz.append(chk, halign="right")
51         sz.append(self.txtSet, "x")
52         chk.DataSource = self.txtSet
53         chk.DataField = "Enabled"
54         chk.Value = True
55
56         self.chkDel = chk = dui.dCheckBox(self, Alignment="right",
57                 Caption=_("Del Method"))
58         self.txtDel = dui.dTextBox(self, SelectOnEntry=True)
59         sz.append(chk, halign="right")
60         sz.append(self.txtDel, "x")
61         chk.DataSource = self.txtDel
62         chk.DataField = "Enabled"
63         chk.Value = False
64        
65         sz.setColExpand(True, 1)
66         self.Sizer.append1x(sz, border=12)
67         self.AutoSize = False
68         dabo.ui.callAfter(self.fitToSizer)
69         dabo.ui.setAfter(self, "Width", 700)
70         self.Caption = _("Custom Property Definition")
71         self.update()
72
73
74     def onKeyPropName(self, evt):
75         dui.callAfter(self.createPropNames)
76        
77    
78     def createPropNames(self):
79         """Occurs when the user types anything in the Prop Name textbox."""
80         pos = self.txtPropName.InsertionPosition
81         propName = self.txtPropName.Value.strip()
82         if not propName:
83             return
84         # Capitalize it
85         propName = propName[0].upper() + propName[1:]
86         self.txtPropName.Value = propName
87         getName = "_get%s" % propName
88         setName = "_set%s" % propName
89         delName = "_del%s" % propName
90         currGet = self.txtGet.Value.strip()
91         currSet = self.txtSet.Value.strip()
92         currDel = self.txtDel.Value.strip()
93         if not currGet or currGet.startswith("_get"):
94             self.txtGet.Value = getName
95         if not currSet or currSet.startswith("_set"):
96             self.txtSet.Value = setName
97         if not currDel or currDel.startswith("_del"):
98             self.txtDel.Value = delName
99         self.txtPropName.InsertionPosition = pos
100         self.refresh()
101        
102        
103     def setData(self, dct):
104         """This method receives a dict containing the various
105         property values as the keys.
106         """
107         self.txtPropName.Value = dct["propName"]
108         self.txtComment.Value = dct["comment"]
109         self.txtDefaultVal.Value = dct["defaultValue"]
110         self.ddType.Value = dct["defaultType"]
111         if dct["getter"] is None:
112             self.txtGet.Value = ""
113             self.chkGet.Value = False
114         else:
115             self.txtGet.Value = dct["getter"]
116             self.chkGet.Value = True
117         if dct["setter"] is None:
118             self.txtSet.Value = ""
119             self.chkSet.Value = False
120         else:
121             self.txtSet.Value = dct["setter"]
122             self.chkSet.Value = True
123         if dct["deller"] is None:
124             self.txtDel.Value = ""
125             self.chkDel.Value = False
126         else:
127             self.txtDel.Value = dct["deller"]
128             self.chkDel.Value = True
129         self.createPropNames()
130         dui.callAfter(self.refresh)
131
132
133     def getData(self):
134         """This method returns a dict containing the various
135         property values as the keys.
136         """
137         ret = {}
138         ret["propName"] = self.txtPropName.Value
139         ret["comment"] = self.txtComment.Value
140         ret["defaultValue"] = self.txtDefaultVal.Value
141         ret["defaultType"] = self.ddType.Value
142         if self.chkGet.Value:
143             ret["getter"] = self.txtGet.Value
144         else:
145             ret["getter"] = None
146         if self.chkSet.Value:
147             ret["setter"] = self.txtSet.Value
148         else:
149             ret["setter"] = None
150         if self.chkDel.Value:
151             ret["deller"] = self.txtDel.Value
152         else:
153             ret["deller"] = None
154         return ret
155
156
157     def needDefType(self):
158         ret = bool(self.txtDefaultVal.Value)
159         return ret
160    
161    
162     def updEnabled(self, evt):
163         dabo.ui.callAfterInterval(500, self.setEnabled)
164    
165    
166     def setEnabled(self):
167         hasDefault = bool(self.txtDefaultVal.Value)
168         self.ddType.Enabled = hasDefault
169         if not hasDefault:
170             # Clear the default type
171             self.ddType.PositionValue = 0
Note: See TracBrowser for help on using the browser.