From: Andy T. <an...@us...> - 2005-12-13 11:13:49
|
Update of /cvsroot/pythoncard/PythonCard/samples/life In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19204/life Modified Files: lexicon.py life.py patterns.py util.py Log Message: Removed all of the plain except: clauses I could Index: lexicon.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/lexicon.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** lexicon.py 28 Sep 2004 05:08:54 -0000 1.18 --- lexicon.py 13 Dec 2005 11:13:23 -0000 1.19 *************** *** 2,8 **** """ __version__ = "$Revision$" __date__ = "$Date$" - """ from PythonCard import model, util --- 2,9 ---- """ + A fairly simple implementation of Conway's Game of Life. + """ __version__ = "$Revision$" __date__ = "$Date$" from PythonCard import model, util *************** *** 37,95 **** data = fp.readlines() fp.close() ! ! lexicon = {} ! # first collect the header ! # up to the first row of ! # ------ ! # then collect the definitions and patterns ! # and finally the bibliography after ! # the second row of ! # ----- ! inIntroduction = 1 ! inBibliography = 0 ! bibliography = '' ! introduction = '' ! term = '' ! for line in data: ! stripped = line.strip() ! if inIntroduction: ! if line.startswith('-----'): ! inIntroduction = 0 ! else: ! introduction += line ! elif inBibliography: ! bibliography += line else: ! if line.startswith('-----'): ! inBibliography = 1 else: ! # collecting an entry ! if stripped == '': ! continue ! elif stripped.startswith(':'): ! # start of new term ! if term != '': ! lexicon[term] = (description, pattern) ! offset = stripped.find(':', 1) ! term = stripped[1:offset] ! description = stripped[offset + 1:].lstrip() ! #crud, term, description = stripped.split(':') ! pattern = '' ! elif stripped.startswith('.') or stripped.startswith('*'): ! pattern += stripped + '\n' else: ! if line.startswith(' '): ! description += '\n\n' + stripped ! else: ! description += '\n' + stripped ! ! if term != '': ! lexicon[term] = (description, pattern) ! lexicon['INTRODUCTION'] = (introduction, '') ! lexicon['BIBLIOGRAPHY'] = (bibliography, '') ! #print len(lexicon) ! return lexicon ! except: ! return None class Lexicon(model.Background): --- 38,94 ---- data = fp.readlines() fp.close() ! except IOError: ! return None ! lexicon = {} ! # first collect the header ! # up to the first row of ! # ------ ! # then collect the definitions and patterns ! # and finally the bibliography after ! # the second row of ! # ----- ! inIntroduction = 1 ! inBibliography = 0 ! bibliography = '' ! introduction = '' ! term = '' ! for line in data: ! stripped = line.strip() ! if inIntroduction: ! if line.startswith('-----'): ! inIntroduction = 0 else: ! introduction += line ! elif inBibliography: ! bibliography += line ! else: ! if line.startswith('-----'): ! inBibliography = 1 ! else: ! # collecting an entry ! if stripped == '': ! continue ! elif stripped.startswith(':'): ! # start of new term ! if term != '': ! lexicon[term] = (description, pattern) ! offset = stripped.find(':', 1) ! term = stripped[1:offset] ! description = stripped[offset + 1:].lstrip() ! #crud, term, description = stripped.split(':') ! pattern = '' ! elif stripped.startswith('.') or stripped.startswith('*'): ! pattern += stripped + '\n' else: ! if line.startswith(' '): ! description += '\n\n' + stripped else: ! description += '\n' + stripped ! if term != '': ! lexicon[term] = (description, pattern) ! lexicon['INTRODUCTION'] = (introduction, '') ! lexicon['BIBLIOGRAPHY'] = (bibliography, '') ! #print len(lexicon) ! return lexicon class Lexicon(model.Background): *************** *** 120,145 **** #filename = name + '.lif' #path = os.path.join(self.application.applicationDirectory, 'patterns', filename) ! try: ! description, patternString = self.lexicon[name] ! if patternString != '': ! crud, patterns, topLeft, size = translateClipboardPattern(patternString) ! #print "topLeft:", topLeft, "size", size ! self.getParent().initAndPlacePatterns(patterns, topLeft, size) ! except: ! pass def on_lstPatterns_select(self, event): name = self.components.lstPatterns.stringSelection ! try: ! description, patternString = self.lexicon[name] ! if patternString == '': ! self.components.fldDescription.text = description ! self.components.stcSize.text = "" ! else: ! crud, patterns, topLeft, size = translateClipboardPattern(patternString) ! self.components.fldDescription.text = description + "\n\n" + patternString ! self.components.stcSize.text = "Size: (%d, %d)" % size ! except: ! pass def on_btnLoad_mouseClick(self, event): --- 119,138 ---- #filename = name + '.lif' #path = os.path.join(self.application.applicationDirectory, 'patterns', filename) ! description, patternString = self.lexicon[name] ! if patternString != '': ! crud, patterns, topLeft, size = translateClipboardPattern(patternString) ! #print "topLeft:", topLeft, "size", size ! self.getParent().initAndPlacePatterns(patterns, topLeft, size) def on_lstPatterns_select(self, event): name = self.components.lstPatterns.stringSelection ! description, patternString = self.lexicon[name] ! if patternString == '': ! self.components.fldDescription.text = description ! self.components.stcSize.text = "" ! else: ! crud, patterns, topLeft, size = translateClipboardPattern(patternString) ! self.components.fldDescription.text = description + "\n\n" + patternString ! self.components.stcSize.text = "Size: (%d, %d)" % size def on_btnLoad_mouseClick(self, event): Index: life.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/life.py,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** life.py 10 Oct 2004 01:20:21 -0000 1.47 --- life.py 13 Dec 2005 11:13:23 -0000 1.48 *************** *** 9,13 **** import psyco psyco.full() ! except: pass --- 9,13 ---- import psyco psyco.full() ! except ImportError: pass *************** *** 67,74 **** basePath = self.application.applicationDirectory self.lexiconPath = os.path.join(self.configPath, 'lexicon.txt') ! try: ! if not os.path.exists(self.lexiconPath): ! shutil.copy2(os.path.join(basePath, 'lexicon.txt'), self.lexiconPath) ! except: # currently lexicon.txt is not part of the distribution # but it might be in the future --- 67,73 ---- basePath = self.application.applicationDirectory self.lexiconPath = os.path.join(self.configPath, 'lexicon.txt') ! if not os.path.exists(self.lexiconPath) and os.path.exists(os.path.join(basePath, 'lexicon.txt')): ! shutil.copy2(os.path.join(basePath, 'lexicon.txt'), self.lexiconPath) ! else: # currently lexicon.txt is not part of the distribution # but it might be in the future *************** *** 364,368 **** bmp.SaveFile(path, fileType) return True ! except: return False else: --- 363,367 ---- bmp.SaveFile(path, fileType) return True ! except IOError: return False else: Index: util.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/util.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** util.py 28 Sep 2004 05:00:26 -0000 1.10 --- util.py 13 Dec 2005 11:13:23 -0000 1.11 *************** *** 56,101 **** data = fp.readlines() fp.close() ! ! if data[0].strip() != '#Life 1.05': ! return None ! ! for line in data[1:]: ! s = line.strip() ! if s == '': ! pass ! elif s.startswith('#N') or s.startswith('#R'): ! # assume Conway (Normal) rules for now ! pass ! elif s.startswith('#D'): ! if description == '': ! description = s[3:].strip() ! else: ! description += "\n" + s[3:].strip() ! elif s.startswith('#P'): ! # beginning of a cell block ! if pattern != {}: ! pattern['size'] = (width, height) ! patterns.append(pattern.copy()) ! x, y = s[3:].split(' ') ! width = 0 ! height = 0 ! pattern = {} ! pattern['position'] = (int(x), int(y)) ! pattern['rows'] = [] ! else: ! pattern['rows'].append(s) ! if len(s) > width: ! width = len(s) ! height += 1 ! if pattern != {}: ! pattern['size'] = (width, height) ! patterns.append(pattern.copy()) ! ! left, top, right, bottom = patternDimensions(patterns) ! #print "bounds", left, top, right, bottom ! #print "size", abs(right - left), abs(bottom - top) ! return description, patterns, (left, top), (abs(right - left), abs(bottom - top)) ! except: return None """ --- 56,98 ---- data = fp.readlines() fp.close() ! except IOError: ! return None ! if data[0].strip() != '#Life 1.05': return None + for line in data[1:]: + s = line.strip() + if s == '': + pass + elif s.startswith('#N') or s.startswith('#R'): + # assume Conway (Normal) rules for now + pass + elif s.startswith('#D'): + if description == '': + description = s[3:].strip() + else: + description += "\n" + s[3:].strip() + elif s.startswith('#P'): + # beginning of a cell block + if pattern != {}: + pattern['size'] = (width, height) + patterns.append(pattern.copy()) + x, y = s[3:].split(' ') + width = 0 + height = 0 + pattern = {} + pattern['position'] = (int(x), int(y)) + pattern['rows'] = [] + else: + pattern['rows'].append(s) + if len(s) > width: + width = len(s) + height += 1 + if pattern != {}: + pattern['size'] = (width, height) + patterns.append(pattern.copy()) + left, top, right, bottom = patternDimensions(patterns) + #print "bounds", left, top, right, bottom + #print "size", abs(right - left), abs(bottom - top) + return description, patterns, (left, top), (abs(right - left), abs(bottom - top)) """ *************** *** 144,152 **** description += "\n" + s else: ! try: ! s, desc = s.split(' ') ! description += "\n" + desc ! except: ! pass # beginning of a cell block if pattern == {}: --- 141,146 ---- description += "\n" + s else: ! s, desc = s.split(' ') ! description += "\n" + desc # beginning of a cell block if pattern == {}: Index: patterns.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/life/patterns.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** patterns.py 28 Sep 2004 05:08:54 -0000 1.17 --- patterns.py 13 Dec 2005 11:13:23 -0000 1.18 *************** *** 2,8 **** """ ! __version__ = "$Revision$" ! __date__ = "$Date$" """ from PythonCard import model --- 2,9 ---- """ ! _A fairly simple implementation of Conway's Game of Life. """ + _version__ = "$Revision$" + __date__ = "$Date$" from PythonCard import model *************** *** 55,78 **** def loadPattern(self, name): ! try: ! path = self.files[name] ! #print num, path ! description, patterns, topLeft, size = readLifeFile(path) ! #print "topLeft:", topLeft, "size", size ! self.GetParent().initAndPlacePatterns(patterns, topLeft, size) ! except: ! pass def on_lstPatterns_select(self, event): path = self.files[self.components.lstPatterns.stringSelection] ! try: ! description, patterns, topLeft, size = readLifeFile(path) ! self.description = description ! self.patterns = patterns ! self.patternSize = size ! self.components.fldDescription.text = description ! self.components.stcSize.text = "Size: (%d, %d)" % size ! except: ! pass def on_btnLoad_mouseClick(self, event): --- 56,73 ---- def loadPattern(self, name): ! path = self.files[name] ! #print num, path ! description, patterns, topLeft, size = readLifeFile(path) ! #print "topLeft:", topLeft, "size", size ! self.GetParent().initAndPlacePatterns(patterns, topLeft, size) def on_lstPatterns_select(self, event): path = self.files[self.components.lstPatterns.stringSelection] ! description, patterns, topLeft, size = readLifeFile(path) ! self.description = description ! self.patterns = patterns ! self.patternSize = size ! self.components.fldDescription.text = description ! self.components.stcSize.text = "Size: (%d, %d)" % size def on_btnLoad_mouseClick(self, event): |