import multiprocessing import logging as log import PIL from util import MsgQueue from gui import gui from imageanalyzer import ImageAnalyzer from go import Go class Core: def __init__(self): self.grid=None self.go=Go() self.detector=ImageAnalyzer() self.tresW=60.0 self.tresB=30.0 self._ownMessages=MsgQueue(self._handleEvent) self._guiMessages=MsgQueue() self._frame=PIL.Image.open("../images/7.jpg") self._guiProc=multiprocessing.Process(name="gui", target=gui, args=(self._guiMessages,self._ownMessages)) self._guiProc.start() self._guiMessages.send("setCurrentFrame",(self._frame,)) def setCorners(self,corners): self.detector.setGridCorners(corners) self.detector.analyze(self._frame) self._guiMessages.send("setGameState",(self.detector.board,)) def setTresholds(self,tresB=None,tresW=None): if tresB is not None: self.tresB=tresB if tresW is not None: self.tresW=tresW if self.detector.analyze(self._frame): self._guiMessages.send("setGameState",(self.detector.board,)) def listen(self): self._ownMessages.listen() def _handleEvent(self,e): actions={"setCorners":self.setCorners, "setTresholds":self.setTresholds} (actionName,args,kwargs)=e return actions[actionName](*args,**kwargs) core=Core() core.listen() """ core ==== grid go imageAnalyzer gui === corners a) keeps references to important objects and uses them b) gets and sets all relevant data through method calls with core GUI <- addCorner(corner) -> redrawImgView(img,grid) <- refreshTresholds(tresB,tresW) BoardView -> redrawState(go) core-gui: just pass messages with relevant data (!! always pass object copies, don't share instances) """