def __init__(self, g=golly): logging.debug('environment init') saveDir = user_data_dir('LifeGenes','7yl4r-ware') try: makedirs(saveDir) except OSError: pass # probably the dir already exists... self.CELL_LIST_FILENAME = join(saveDir,'lifeGenes_cellList.pk') self.originL = g.getlayer() #starting layer # check for existing geneticColor layer currindex = 0 self.colorIndex = None while currindex < g.numlayers(): if g.getname(currindex) == 'geneticColor': # continue from where we left off self.colorIndex = currindex logging.info('geneticColor layer already exists, loading from file '+self.CELL_LIST_FILENAME) # read cell genes from a file and make self.cellList self.cellList = cellList([0,0]) self.cellList.load(self.CELL_LIST_FILENAME) break else: currindex+=1 if self.colorIndex == None: #if we didn't find existing colorLayer logging.info('color layer not found. creating new environment') if g.empty(): self.cellList = cellList([]) else: # detect existing cells startpatt = g.getcells(g.getrect()) # get starting pattern array [x1,y1,x2,y2,...] self.cellList = cellList(startpatt) logging.info(str(len(startpatt)/2)+' cells found, '+str(len(self.cellList.cells))+' trait objects created.') # add color layer if g.numlayers() + 1 > g.maxlayers(): g.exit("You need to delete a layer.") # create layer for colors self.colorIndex = g.addlayer() g.setname('geneticColor') g.setrule('constant') #use custom constant rule g.setcolors([0,255,0, 0,0,255]) #live states vary from green to blue g.setlayer(self.originL) # set layer back to original layer assert(self.cellList != None)
import errno from os.path import join from os import getcwd, chdir, makedirs from glob import glob import Tkinter as tk try: from PIL import Image, ImageTk except ImportError: raise ImportError( "this function requires the Python Imaging Library (PIL). " + "See http://www.pythonware.com/products/pil/ " + "or https://github.com/python-imaging/Pillow for more." ) saveDir = user_data_dir("LifeGenes", "7yl4r-ware") DNA_COLLECTION_FILE = join(saveDir, "dna_collection.pk") CELL_COLLECTION_DIR = join(saveDir, "cellCollection") class cellPallate: # defines a pallate of saved DNA sequences # ATTRIBUTES: # pallate = list of cell objects in the pallate # pallateImages = a list of image files for each cell in pallate # cellNames = a list of cell object names # selected= number representing currently selected dna sequence in pallate # PUBLIC METHODS: # load = loads dna strings from file into pallate # save = saves dna pallate to file # display =
import logging from LifeGenes.lifegenes_core.__util.appdirs import user_data_dir import errno from os.path import join from os import getcwd, chdir, makedirs from glob import glob import Tkinter as tk try: from PIL import Image, ImageTk except ImportError: raise ImportError("this function requires the Python Imaging Library (PIL). " + "See http://www.pythonware.com/products/pil/ " + "or https://github.com/python-imaging/Pillow for more.") saveDir = user_data_dir('LifeGenes', '7yl4r-ware') DNA_COLLECTION_FILE = join(saveDir, 'dna_collection.pk') CELL_COLLECTION_DIR = join(saveDir, 'cellCollection') class cellPallate: # defines a pallate of saved DNA sequences # ATTRIBUTES: # pallate = list of cell objects in the pallate # pallateImages = a list of image files for each cell in pallate # cellNames = a list of cell object names # selected= number representing currently selected dna sequence in pallate # PUBLIC METHODS: # load = loads dna strings from file into pallate # save = saves dna pallate to file # display = def __init__(self):