3
__version__ = "$Revision: 1.1 $"
4
__date__ = "$Date: 2004/10/24 19:21:46 $"
7
from PythonCard import log, model, resource
11
NEWSTRING = 'newString'
14
def stringResourceFromList(stringList):
18
desc += """ %s:%s,\n""" % (repr(s), repr(stringList[s]))
23
return resource.Resource(d)
26
class StringDialog(model.CustomDialog):
27
def __init__(self, aBg, stringList):
28
model.CustomDialog.__init__(self, aBg)
34
# workaround/hack to make sure closeField message
35
# is processed prior to the dialog being closed
36
# this occurs when one of the fields are edited and then
38
# this hack works because we don't process on_close
39
# the first time, but rather delay it by posting a second close message
40
self.closeDialog = False
43
# if some special setup is necessary, do it here
44
self.stringList = stringList
45
sortedStrings = self.stringList.keys()
47
for s in sortedStrings:
48
label = self.getLabelFromKey(s)
49
self.components.listStrings.append(label)
51
def parseStrings(self, rsrc):
53
for s in rsrc.__dict__:
54
stringList[s] = rsrc.__dict__[s]
57
def getLabelFromKey(self, key):
58
return key + SPACER + self.stringList[key].split('\n')[0]
60
def updateItemLabel(self, n, key):
61
label = self.getLabelFromKey(key)
62
self.components.listStrings.setString(n, label)
64
def getStringSelectionKey(self):
65
return self.components.listStrings.stringSelection.split()[0]
67
def on_fldName_closeField(self, event):
68
print "closeField fldName", event.target.text
69
newName = event.target.text
70
previousName = self.getStringSelectionKey()
71
# if the name changes then we have to check to see
72
# if the dictionary already has a key with the new
74
if newName in self.stringList:
78
sel = self.components.listStrings.selection
79
self.stringList[newName] = self.stringList[previousName]
80
del self.stringList[previousName]
81
#self.components.listStrings.setString(sel, newName)
82
self.updateItemLabel(sel, newName)
84
def on_fldValue_closeField(self, event):
85
print "closeField fldValue", event.target.text
86
sel = self.components.listStrings.selection
87
name = self.getStringSelectionKey()
88
self.stringList[name] = event.target.text
89
self.updateItemLabel(sel, name)
91
def displayItemAttributes(self, s):
92
self.components.fldName.text = s
93
self.components.fldValue.text = self.stringList[s]
95
def on_listStrings_select(self, event):
96
self.displayItemAttributes(self.getStringSelectionKey())
98
def on_btnDelete_mouseClick(self, event):
99
sel = self.components.listStrings.selection
100
name = self.getStringSelectionKey()
102
del self.stringList[name]
103
self.components.listStrings.delete(sel)
104
if len(self.stringList) > 0:
105
if sel > len(self.stringList) - 1:
107
self.components.listStrings.selection = sel
108
self.displayItemAttributes(self.getStringSelectionKey())
110
def on_btnNew_mouseClick(self, event):
112
if s in self.stringList:
113
self.components.listStrings.stringSelection = self.getLabelFromKey(s)
115
self.stringList[s] = ''
116
sel = len(self.stringList) - 1
117
self.components.listStrings.append(s)
118
self.components.listStrings.stringSelection = s
119
self.updateItemLabel(sel, s)
120
self.displayItemAttributes(self.getStringSelectionKey())
124
# experiment to workaround Mac closeField bug
125
# ignore for now along with the extra debug print statements in closeField
126
# event handlers above
127
def on_mouseClick(self, event):
129
print self.closeDialog
130
print event.target.name
131
print event.target.id
137
self.closeDialog = True
138
wx.PostEvent(self, event)
142
def stringDialog(parent, rsrc):
143
dlg = StringDialog(parent, rsrc)
144
result = dlg.showModal()
146
result.stringList = stringResourceFromList(dlg.stringList)