예제 #1
0
    def __init__(self, root, w, h, size, frames, initialState):

        self.canvasLocked = False
        self.globalLock = False
        self.stahp = False

        self.w = w
        self.h = h
        self.size = size
        self.rawField = initialState
        self.frames = frames
        self.field = life.field(self.rawField)
        
        self.root = root
        self.root.title = "Life"
        self.root.geometry(str(149 + w * size) + "x" + str(9 + h * size))

        self.clear = IntVar()
        self.currIter = StringVar()
        self.step = StringVar()

        self.backImg = ImgTk.PhotoImage(file = "res\\prev.png")
        oneBackBtn = Button(self.root, command = self.moveOneBack, image = self.backImg)
        oneBackBtn.place(cnf = {"width": 32, "height": 32, "x": 3, "y": 3})

        currIterLbl = Label(self.root, textvariable = self.currIter)
        currIterLbl.place(cnf = {"width": 67, "height": 32, "x": 38, "y": 3})
        self.currIter.set("0")

        self.fwdImg = ImgTk.PhotoImage(file = "res\\next.png")
        oneForwardBtn = Button(self.root, command = self.moveOneForward, image = self.fwdImg)
        oneForwardBtn.place(cnf = {"width": 32, "height": 32, "x": 108, "y": 3})

        self.manyBackImg = ImgTk.PhotoImage(file = "res\\manyprev.png")
        manyBackBtn = Button(self.root, command = self.moveManyBack, image = self.manyBackImg)
        manyBackBtn.place(cnf = {"width": 32, "height": 32, "x": 3, "y": 38})

        stepEnt = Entry(self.root, textvariable = self.step)
        stepEnt.place(cnf = {"width": 67, "height": 30, "x": 38, "y": 39})
        stepEnt.focus()
        self.step.set("2")

        self.manyFwdImg = ImgTk.PhotoImage(file = "res\\manynext.png")
        manyForwardBtn = Button(self.root, command = self.moveManyForward, image = self.manyFwdImg)
        manyForwardBtn.place(cnf = {"width": 32, "height": 32, "x": 108, "y": 38})

        stopBtn = Button(self.root, text = "Stahp", command = self.stop)
        stopBtn.place(cnf = {"width": 137, "height": 32, "x": 3, "y": 73})

        resetBtn = Button(self.root, text = "Reset", command = self.reset)
        resetBtn.place(cnf = {"width": 137, "height": 32, "x": 3, "y": 108})

        clearChk = Checkbutton(self.root, text = "Clear", variable = self.clear)
        clearChk.place(cnf = {"width": 128, "height": 32, "x": 3, "y": 143})

        self.canvas = Canvas(self.root, height = size * h + 1, width = size * w + 1, bg = "white")
        self.canvas.place(cnf={"x": 143, "y": 3})
        self.canvas.bind("<Button-1>", self.canvasClick)
        self.canvasDraw()
예제 #2
0
 def move(self, delta):
     if not self.canvasLocked:
         self.field = life.field(self.rawField)
     self.canvasLocked = True
     result = self.field.generate(self.field.getCurrIter() + delta)
     if result == "Field too big":
         tkMessageBox.showerror("", u"Слишком большое поле")
     elif result == "No prev":
         tkMessageBox.showinfo("", u"Нет предыдущего состояния")
     else:
         self.rawField = self.field.getField()
         self.canvasDraw()
         self.currIter.set(str(self.field.getCurrIter()))