diff --git a/src/gui.py b/src/gui.py --- a/src/gui.py +++ b/src/gui.py @@ -1,14 +1,13 @@ import tkinter as tk from PIL import ImageTk import PIL + +import config from corners import * from grid import * from image_analyzer import * from go import * -showBigPoints=True -showGrid=False - class Application(tk.Frame): def __init__(self, master=None): @@ -36,8 +35,11 @@ class Application(tk.Frame): self.boardView.grid(column=1,row=0) # more controls below the board - self.scaleTresB=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=lambda x: self.redrawImgView()) - self.scaleTresW=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=lambda x: self.redrawImgView()) + def _refreshTresholds(_): + self.refreshTresholds() + self.redrawImgView() + self.scaleTresB=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=_refreshTresholds) + self.scaleTresW=tk.Scale(self, orient=tk.HORIZONTAL, length=200, from_=0.0, to=100.0, command=_refreshTresholds) self.scaleTresB.set(30.0) self.scaleTresW.set(60.0) self.scaleTresB.grid(column=0,row=1,columnspan=2) @@ -69,7 +71,7 @@ class Application(tk.Frame): for corner in self.corners.corners: self.markPoint(corner.x,corner.y) - if self.boardGrid!=None and showGrid: + if self.boardGrid!=None and config.gui.showGrid: for r in range(19): a=self.boardGrid.intersections[r][0] b=self.boardGrid.intersections[r][-1] @@ -79,7 +81,7 @@ class Application(tk.Frame): b=self.boardGrid.intersections[-1][c] self.imgView.create_line(a.x,a.y,b.x,b.y,fill='#00ff00') - if self.boardGrid!=None and showBigPoints: + if self.boardGrid!=None and config.gui.showBigPoints: for r in range(19): for c in range(19): ((r1,c1),(r2,c2))=self.boardView.detector.relevantRect(self.boardGrid.intersections[r][c],*(self.boardGrid.stoneSizeAt(r,c,sizeCoef))) @@ -89,7 +91,7 @@ class Application(tk.Frame): shift=EPoint(origWidth-self.img.width()*sizeCoef,origHeight-self.img.height()*sizeCoef)/2 - self.boardView.redrawState(self.imgOrig,sizeCoef,shift,tresB,tresW) + self.boardView.redrawState(self.imgOrig,sizeCoef,shift) ## Marks a point at the image with a green cross. Used for corners. def markPoint(self,x,y): @@ -98,6 +100,10 @@ class Application(tk.Frame): self.imgView.grid() + def refreshTresholds(self): + self.boardView.detector.tresB=self.scaleTresB.get() + self.boardView.detector.tresW=self.scaleTresW.get() + ## Handles and presents the game state as detected by the program. class BoardView(tk.Canvas): @@ -113,14 +119,11 @@ class BoardView(tk.Canvas): self.grid() ## Redraws and reananalyzes the board view. - # - # @param tresB upper intensity treshold for a pixel to be considered black, [0-100] - # @param tresW lower intensity treshold for a pixel to be considered white, [0-100] - def redrawState(self,img,sizeCoef,shift,tresB,tresW): + def redrawState(self,img,sizeCoef,shift): self.create_rectangle(0,0,360,360,fill="#ffcc00") self.drawGrid() - self.detector.analyze(img,tresB,tresW,sizeCoef,shift) + self.detector.analyze(img,sizeCoef,shift) for r,row in enumerate(self.detector.board): for c,point in enumerate(row): @@ -161,5 +164,6 @@ class BoardView(tk.Canvas): root = tk.Tk() +root.title("OneEye {0}.{1}".format(*config.misc.version)) app = Application(master=root) app.mainloop()