~toolpart/+junk/pythoncard

« back to all changes in this revision

Viewing changes to samples/life/lexicon.py

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2006-11-12 17:52:13 UTC
  • mfrom: (2.1.5 feisty)
  • Revision ID: james.westby@ubuntu.com-20061112175213-tv8bnl6rtpa2qw1o
Tags: 0.8.1-8.1
* Non-maintainer upload.
* Fix path to findfiles, codeEditor and resourceEditor:
   + patch from Ernest ter Kuile <ernestjw@xs4all.nl>. (Closes: #397018)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
3
"""
4
 
__version__ = "$Revision: 1.9 $"
5
 
__date__ = "$Date: 2004/04/02 20:16:25 $"
 
4
__version__ = "$Revision: 1.18 $"
 
5
__date__ = "$Date: 2004/09/28 05:08:54 $"
6
6
"""
7
7
 
8
 
from PythonCardPrototype import model, util
9
 
from wxPython import wx
 
8
from PythonCard import model, util
 
9
import wx
10
10
 
11
11
import os
12
12
 
16
16
:101: (p5)  Found by Achim Flammenkamp in August 1994.  The name was
17
17
   suggested by Bill Gosper, noting that the phase shown below displays
18
18
   the period in binary.
19
 
        ....**......**....
20
 
        ...*.*......*.*...
21
 
        ...*..........*...
22
 
        **.*..........*.**
23
 
        **.*.*..**..*.*.**
24
 
        ...*.*.*..*.*.*...
25
 
        ...*.*.*..*.*.*...
26
 
        **.*.*..**..*.*.**
27
 
        **.*..........*.**
28
 
        ...*..........*...
29
 
        ...*.*......*.*...
30
 
        ....**......**....
 
19
    ....**......**....
 
20
    ...*.*......*.*...
 
21
    ...*..........*...
 
22
    **.*..........*.**
 
23
    **.*.*..**..*.*.**
 
24
    ...*.*.*..*.*.*...
 
25
    ...*.*.*..*.*.*...
 
26
    **.*.*..**..*.*.**
 
27
    **.*..........*.**
 
28
    ...*..........*...
 
29
    ...*.*......*.*...
 
30
    ....**......**....
31
31
 
32
32
"""
33
33
 
34
 
def readLexiconFile():
 
34
def readLexiconFile(path):
35
35
    try:
36
 
        fp = open('lexicon.txt')
 
36
        fp = open(path)
37
37
        data = fp.readlines()
38
38
        fp.close()
39
39
    
94
94
 
95
95
class Lexicon(model.Background):
96
96
 
97
 
    def on_openBackground(self, event):
 
97
    def on_initialize(self, event):
98
98
        #self.initSizers()
99
 
        self.components.fldDescription.lineNumbersVisible = 0
 
99
        self.components.fldDescription.lineNumbersVisible = False
100
100
        self.components.fldDescription.setEditorStyle('text')
 
101
        self.lexiconPath = self.getParent().lexiconPath
101
102
        self.populatePatternsList()
102
103
 
103
104
    def populatePatternsList(self):
104
 
        self.lexicon = readLexiconFile()
 
105
        self.lexicon = readLexiconFile(self.lexiconPath)
105
106
        if self.lexicon is None:
106
 
            self.getParent().menuBar.setEnabled('menuAutomataLexicon', 0)
107
 
            # KEA 2004-04-02
108
 
            # won't work until wxPython 2.5
109
 
            # self.visible = False
110
 
            self.Hide()
 
107
            self.getParent().menuBar.setEnabled('menuAutomataLexicon', False)
 
108
            self.visible = False
111
109
        else:
112
110
            items = self.lexicon.keys()
113
111
            items = util.caseinsensitive_sort(items)
115
113
            self.components.lstPatterns.selection = 0
116
114
            # now simulate the user doing a selection
117
115
            self.on_lstPatterns_select(None)
 
116
            self.getParent().menuBar.setEnabled('menuAutomataLexicon', True)
 
117
            self.visible = True
118
118
 
119
119
    def loadPattern(self, name):
120
120
        #filename = name + '.lif'
121
 
        #path = os.path.join(self.stack.app.applicationDirectory, 'patterns', filename)
 
121
        #path = os.path.join(self.application.applicationDirectory, 'patterns', filename)
122
122
        try:
123
123
            description, patternString = self.lexicon[name]
124
124
            if patternString != '':
129
129
            pass
130
130
 
131
131
    def on_lstPatterns_select(self, event):
132
 
        #name = event.target.selected
133
 
        #filename = name + '.lif'
134
 
        #path = os.path.join(self.stack.app.applicationDirectory, 'patterns', filename)
135
 
        #path = self.files[event.target.selection]
136
 
        name = self.components.lstPatterns.selected
 
132
        name = self.components.lstPatterns.stringSelection
137
133
        try:
138
134
            description, patternString = self.lexicon[name]
139
135
            if patternString == '':
147
143
            pass
148
144
 
149
145
    def on_btnLoad_mouseClick(self, event):
150
 
        self.loadPattern(self.components.lstPatterns.selected)
 
146
        self.loadPattern(self.components.lstPatterns.stringSelection)
151
147
 
152
148
    def on_lstPatterns_mouseDoubleClick(self, event):
153
 
        self.loadPattern(self.components.lstPatterns.selected)
 
149
        self.loadPattern(self.components.lstPatterns.stringSelection)
154
150
 
155
151
    def on_close(self, event):
156
 
        # KEA 2004-04-02
157
 
        # won't work until wxPython 2.5
158
 
        # self.visible = False
159
 
        self.Hide()
 
152
        self.visible = False