source: Cell.py

Last change on this file was 5ee3950, checked in by Agnibho Mondal <mail@…>, 4 years ago

Added licensing information

  • Property mode set to 100644
File size: 2.2 KB
Line 
1# Agnibho's Game of Life - Python implementation of Conway's Game of Life
2# Copyright (C) 2014  Agnibho Mondal
3
4# This file is part of Agnibho's Game of Life
5
6# Agnibho's Game of Life is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# Agnibho's Game of Life is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with Agnibho's Game of Life.  If not, see <http://www.gnu.org/licenses/>.
18
19import Tkinter as tk
20
21class Cell():
22  __obj={}
23  __parent={}
24  __state="dead"
25  __buff="dead"
26  __original="dead"
27 
28  def __init__(self, item, parent):
29    self.__obj=item
30    self.__parent=parent
31    self.__parent.tag_bind(self.__obj, '<ButtonPress-1>', self.toggle)
32 
33  def getState(self):
34    return self.__state
35 
36  def makeLive(self):
37    self.__buff="live"
38   
39  def makeDead(self):
40    self.__buff="dead"
41   
42  def commit(self):
43    self.__state=self.__buff
44    if(self.__state=="live"):
45      self.__parent.itemconfig(self.__obj, fill="green")
46    elif(self.__state=="dead"):
47      self.__parent.itemconfig(self.__obj, fill="white")
48         
49   
50  def toggle(self, event=False):
51    if(self.__state=="live"):
52      self.__state="dead"
53      self.__buff="dead"
54      self.__original="dead"
55      self.__parent.itemconfig(self.__obj, fill="white")
56    elif(self.__state=="dead"):
57      self.__state="live"
58      self.__buff="live"
59      self.__original="live"
60      self.__parent.itemconfig(self.__obj, fill="green")
61     
62  def freeze(self):
63    self.__parent.tag_unbind(self.__obj, '<ButtonPress-1>')
64 
65  def unfreeze(self):
66    self.__parent.tag_bind(self.__obj, '<ButtonPress-1>', self.toggle)
67   
68  def revert(self):
69    self.__buff=self.__original
70    self.commit()
71    self.unfreeze()
72   
73  def clear(self):
74    self.__buff="dead"
75    self.__original="dead"
76    self.commit()
77    self.unfreeze()
Note: See TracBrowser for help on using the repository browser.