From: Kevin A. <ka...@us...> - 2004-09-28 05:00:45
|
Update of /cvsroot/pythoncard/PythonCard/samples/life In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5502 Modified Files: lexicon.py life.py life.rsrc.py patterns.py util.py Log Message: added downloading for lexicon and patterns added config directory support Index: lexicon.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/lexicon.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** lexicon.py 8 Aug 2004 18:07:43 -0000 1.16 --- lexicon.py 28 Sep 2004 05:00:25 -0000 1.17 *************** *** 32,38 **** """ ! def readLexiconFile(): try: ! fp = open('lexicon.txt') data = fp.readlines() fp.close() --- 32,38 ---- """ ! def readLexiconFile(path): try: ! fp = open(path) data = fp.readlines() fp.close() *************** *** 99,106 **** self.components.fldDescription.lineNumbersVisible = False self.components.fldDescription.setEditorStyle('text') self.populatePatternsList() def populatePatternsList(self): ! self.lexicon = readLexiconFile() if self.lexicon is None: self.getParent().menuBar.setEnabled('menuAutomataLexicon', False) --- 99,107 ---- self.components.fldDescription.lineNumbersVisible = False self.components.fldDescription.setEditorStyle('text') + self.lexiconPath = self.GetParent().lexiconPath self.populatePatternsList() def populatePatternsList(self): ! self.lexicon = readLexiconFile(self.lexiconPath) if self.lexicon is None: self.getParent().menuBar.setEnabled('menuAutomataLexicon', False) Index: life.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/life.py,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** life.py 28 Sep 2004 03:12:55 -0000 1.44 --- life.py 28 Sep 2004 05:00:26 -0000 1.45 *************** *** 12,22 **** pass - from PythonCard import clipboard, dialog, graphic, model, util - import wx import os, sys from patterns import Patterns from lexicon import Lexicon - from util import readLifeFile, translateClipboardPattern, placePattern, neighborsTuple --- 12,23 ---- pass import os, sys + import shutil + import wx + import util as lifeutil + from PythonCard import clipboard, configuration, dialog, graphic, model, util from patterns import Patterns from lexicon import Lexicon *************** *** 24,27 **** --- 25,29 ---- def on_initialize(self, event): + self.createConfigDir() self.filename = None *************** *** 59,62 **** --- 61,80 ---- self.panel.Layout() + def createConfigDir(self): + self.configPath = os.path.join(configuration.homedir, 'life') + if not os.path.exists(self.configPath): + os.mkdir(self.configPath) + basePath = self.application.applicationDirectory + self.lexiconPath = os.path.join(self.configPath, 'lexicon.txt') + if not os.path.exists(self.lexiconPath): + shutil.copy2(os.path.join(basePath, 'lexicon.txt'), self.lexiconPath) + self.patternsPath = os.path.join(self.configPath, 'patterns') + if not os.path.exists(self.patternsPath): + os.mkdir(self.patternsPath) + basePath = os.path.join(basePath, 'patterns') + for name in os.listdir(basePath): + if name.lower().endswith('.lif') and not os.path.exists(os.path.join(self.patternsPath, name)): + shutil.copy2(os.path.join(basePath, name), os.path.join(self.patternsPath, name)) + def initGrid(self): # a populated grid has (x, y) tuples for keys *************** *** 120,124 **** for cell in grid: sum = 0 ! #neighbors = neighborsTuple(cell[0], cell[1]) # it is a bit faster to inline this rather than # calling a function --- 138,142 ---- for cell in grid: sum = 0 ! #neighbors = lifeutil.neighborsTuple(cell[0], cell[1]) # it is a bit faster to inline this rather than # calling a function *************** *** 198,202 **** if alive: # make sure neighbors are in grid ! for neighbor in neighborsTuple(col, row): self.grid.setdefault(neighbor, 0) --- 216,220 ---- if alive: # make sure neighbors are in grid ! for neighbor in lifeutil.neighborsTuple(col, row): self.grid.setdefault(neighbor, 0) *************** *** 304,308 **** column = centerX + x - xDiff row = centerY + y - yDiff ! self.grid = placePattern(self.grid, column, row, pattern['rows']) self.displayGeneration() --- 322,326 ---- column = centerX + x - xDiff row = centerY + y - yDiff ! self.grid = lifeutil.placePattern(self.grid, column, row, pattern['rows']) self.displayGeneration() *************** *** 317,321 **** self.filename = path ! description, patterns, topLeft, size = readLifeFile(path) print description print "topLeft:", topLeft, "size", size --- 335,339 ---- self.filename = path ! description, patterns, topLeft, size = lifeutil.readLifeFile(path) print description print "topLeft:", topLeft, "size", size *************** *** 359,363 **** data = clipboard.getClipboard() if isinstance(data, str): ! description, patterns, topLeft, size = translateClipboardPattern(data) print description print "topLeft:", topLeft, "size", size --- 377,381 ---- data = clipboard.getClipboard() if isinstance(data, str): ! description, patterns, topLeft, size = lifeutil.translateClipboardPattern(data) print description print "topLeft:", topLeft, "size", size *************** *** 412,416 **** def on_menuAutomataPatternsList_select(self, event): self.patternsWindow.visible = True ! if __name__ == '__main__': app = model.Application(Life) --- 430,446 ---- def on_menuAutomataPatternsList_select(self, event): self.patternsWindow.visible = True ! ! def on_menuAutomataDownloadLexiconAndPatterns_select(self, event): ! cwd = os.getcwd() ! os.chdir(self.application.applicationDirectory) ! self.statusBar.text = 'Downloading Lexicon...' ! lifeutil.getLexicon(self.configPath) ! self.lexiconWindow.populatePatternsList() ! self.statusBar.text = 'Downloading Patterns...' ! lifeutil.getPatterns(self.configPath) ! self.patternsWindow.populatePatternsList() ! os.chdir(cwd) ! self.statusBar.text = 'Done' ! if __name__ == '__main__': app = model.Application(Life) Index: life.rsrc.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/life.rsrc.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** life.rsrc.py 10 May 2004 05:02:16 -0000 1.6 --- life.rsrc.py 28 Sep 2004 05:00:26 -0000 1.7 *************** *** 63,66 **** --- 63,70 ---- 'name':'menuAutomataPatternsList', 'label':"Patterns List Window"}, + { 'type':'MenuItem', 'name':'automataSep1', 'label':'-' }, + { 'type':'MenuItem', + 'name':'menuAutomataDownloadLexiconAndPatterns', + 'label':"Download Lexicon and Patterns"}, ] }, { 'type':'Menu', Index: util.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/util.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** util.py 18 Mar 2004 22:10:45 -0000 1.9 --- util.py 28 Sep 2004 05:00:26 -0000 1.10 *************** *** 213,229 **** # downloading another copy ! def getLexicon(): filename = 'lexicon.txt' zipname = 'lex_asc.zip' url = 'http://www.argentum.freeserve.co.uk/' + zipname ! urllib.urlretrieve(url, zipname) ! zz = zipfile.ZipFile(zipname) ! savefile(filename, zz.read(filename)) ! def getPatterns(): zipname = 'lifep.zip' url = 'http://www.ibiblio.org/lifepatterns/' + zipname ! urllib.urlretrieve(url, zipname) ! zz = zipfile.ZipFile(zipname) for name in zz.namelist(): ! savefile(os.path.join('patterns', name), zz.read(name)) --- 213,231 ---- # downloading another copy ! def getLexicon(path): filename = 'lexicon.txt' zipname = 'lex_asc.zip' + zippath = os.path.join(path, zipname) url = 'http://www.argentum.freeserve.co.uk/' + zipname ! urllib.urlretrieve(url, zippath) ! zz = zipfile.ZipFile(zippath) ! savefile(os.path.join(path, filename), zz.read(filename)) ! def getPatterns(path): zipname = 'lifep.zip' + zippath = os.path.join(path, zipname) url = 'http://www.ibiblio.org/lifepatterns/' + zipname ! urllib.urlretrieve(url, zippath) ! zz = zipfile.ZipFile(zippath) for name in zz.namelist(): ! savefile(os.path.join(path, 'patterns', name), zz.read(name)) Index: patterns.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/patterns.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** patterns.py 10 May 2004 00:45:20 -0000 1.15 --- patterns.py 28 Sep 2004 05:00:26 -0000 1.16 *************** *** 21,24 **** --- 21,25 ---- self.components.fldDescription.lineNumbersVisible = 0 self.components.fldDescription.setEditorStyle('text') + self.patternsPath = self.GetParent().patternsPath self.populatePatternsList() *************** *** 38,42 **** def populatePatternsList(self): ! files = glob.glob(os.path.join(self.application.applicationDirectory, 'patterns', '*.[Ll][Ii][Ff]')) items = [] self.files = {} --- 39,43 ---- def populatePatternsList(self): ! files = glob.glob(os.path.join(self.patternsPath, '*.[Ll][Ii][Ff]')) items = [] self.files = {} *************** *** 54,59 **** def loadPattern(self, name): - #filename = name + '.lif' - #path = os.path.join(self.application.applicationDirectory, 'patterns', filename) try: path = self.files[name] --- 55,58 ---- |