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