~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to tools/experimentalResourceEditor/modules/stringDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-03-04 23:55:10 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100304235510-3v6lbhzwrgm0pcca
Tags: 0.8.2-1
* QA upload.
* New upstream release
* debian/control
  - set maintainer to QA group
  - set Homepage field, removing the URL from packages description
  - bump versioned b-d-i on python-support, to properly support Python module
  - replace b-d on python-all-dev with python-all, since building only
    arch:all packages
  - replace Source-Version substvar with source:Version
  - add ${misc:Depends} to binary packages Depends
* debian/watch
  - updated to use the SourceForge redirector; thanks to Raphael Geissert for
    the report and to Dario Minnucci for the patch; Closes: #449904
* debian/{pythoncard-doc, python-pythoncard}.install
  - use wildcards instead of site-packages to fix build with python 2.6;
    thanks to Ilya Barygin for the report and patch; Closes: #572332
* debian/pythoncard-doc.doc-base
  - set section to Programmin/Python
* debian/pythoncard-tools.menu
  - set menu main section to Applications
* debian/pythoncard-tools.postinst
  - removed, needed only to update the menu, but it's now created by debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""
 
3
__version__ = "$Revision: 1.1 $"
 
4
__date__ = "$Date: 2004/10/24 19:21:46 $"
 
5
"""
 
6
 
 
7
from PythonCard import log, model, resource
 
8
import os
 
9
import wx
 
10
 
 
11
NEWSTRING = 'newString'
 
12
SPACER = '  :  '
 
13
 
 
14
def stringResourceFromList(stringList):
 
15
    desc = "         {\n"
 
16
 
 
17
    for s in stringList:
 
18
        desc += """         %s:%s,\n""" % (repr(s), repr(stringList[s]))
 
19
 
 
20
    # close strings
 
21
    desc += "         }\n"
 
22
    d = eval(desc)
 
23
    return resource.Resource(d)
 
24
 
 
25
 
 
26
class StringDialog(model.CustomDialog):
 
27
    def __init__(self, aBg, stringList):        
 
28
        model.CustomDialog.__init__(self, aBg)
 
29
        
 
30
        self.parent = aBg
 
31
        
 
32
        """
 
33
        # KEA 2004-08-22
 
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
 
37
        # the user clicks Ok
 
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
 
41
        """
 
42
        
 
43
        # if some special setup is necessary, do it here
 
44
        self.stringList = stringList
 
45
        sortedStrings = self.stringList.keys()
 
46
        sortedStrings.sort()
 
47
        for s in sortedStrings:
 
48
            label = self.getLabelFromKey(s)
 
49
            self.components.listStrings.append(label)
 
50
 
 
51
    def parseStrings(self, rsrc):
 
52
        stringList = {}
 
53
        for s in rsrc.__dict__:
 
54
            stringList[s] = rsrc.__dict__[s]
 
55
        return stringList
 
56
 
 
57
    def getLabelFromKey(self, key):
 
58
        return key + SPACER + self.stringList[key].split('\n')[0]
 
59
 
 
60
    def updateItemLabel(self, n, key):
 
61
        label = self.getLabelFromKey(key)
 
62
        self.components.listStrings.setString(n, label)
 
63
 
 
64
    def getStringSelectionKey(self):
 
65
        return self.components.listStrings.stringSelection.split()[0]
 
66
 
 
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
 
73
        # name
 
74
        if newName in self.stringList:
 
75
            # replace?
 
76
            pass
 
77
        else:
 
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)
 
83
 
 
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)
 
90
 
 
91
    def displayItemAttributes(self, s):
 
92
        self.components.fldName.text = s
 
93
        self.components.fldValue.text = self.stringList[s]
 
94
 
 
95
    def on_listStrings_select(self, event):
 
96
        self.displayItemAttributes(self.getStringSelectionKey())
 
97
            
 
98
    def on_btnDelete_mouseClick(self, event):
 
99
        sel = self.components.listStrings.selection
 
100
        name = self.getStringSelectionKey()
 
101
        if sel != -1:
 
102
            del self.stringList[name]
 
103
            self.components.listStrings.delete(sel)
 
104
            if len(self.stringList) > 0:
 
105
                if sel > len(self.stringList) - 1:
 
106
                    sel = sel - 1
 
107
                self.components.listStrings.selection = sel
 
108
                self.displayItemAttributes(self.getStringSelectionKey())
 
109
 
 
110
    def on_btnNew_mouseClick(self, event):
 
111
        s = NEWSTRING
 
112
        if s in self.stringList:
 
113
            self.components.listStrings.stringSelection = self.getLabelFromKey(s)
 
114
        else:
 
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())
 
121
 
 
122
    """
 
123
    # KEA 2004-08-22
 
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):
 
128
        try:
 
129
            print self.closeDialog
 
130
            print event.target.name
 
131
            print event.target.id
 
132
        except:
 
133
            pass
 
134
        if self.closeDialog:
 
135
            event.skip()
 
136
        else:
 
137
            self.closeDialog = True
 
138
            wx.PostEvent(self, event)
 
139
    """
 
140
        
 
141
 
 
142
def stringDialog(parent, rsrc):
 
143
    dlg = StringDialog(parent, rsrc)
 
144
    result = dlg.showModal()
 
145
    if result.accepted:
 
146
        result.stringList = stringResourceFromList(dlg.stringList)
 
147
    dlg.destroy()
 
148
    return result
 
149