X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fgraphics.py;fp=qchess%2Fsrc%2Fgraphics.py;h=6fd646d1fef033a17f79bc24228621f90f964ed7;hp=8d95db8c74223249cb2cafa074378cd5a1ee3534;hb=c0c346f95a6d19d8967928aeeeb4937e1a99f2f4;hpb=5287b4f869be70ddae4b59a44c448be33f95ccda diff --git a/qchess/src/graphics.py b/qchess/src/graphics.py index 8d95db8..6fd646d 100644 --- a/qchess/src/graphics.py +++ b/qchess/src/graphics.py @@ -4,6 +4,7 @@ try: except: graphics_enabled = False +import time @@ -24,6 +25,8 @@ class GraphicsThread(StoppableThread): self.error = 0 self.lock = threading.RLock() self.cond = threading.Condition() + self.sleep_timeout = None + self.last_event = time.time() #print "Test font" pygame.font.Font(os.path.join(os.path.curdir, "data", "DejaVuSans.ttf"), 32).render("Hello", True,(0,0,0)) @@ -47,18 +50,24 @@ class GraphicsThread(StoppableThread): while not self.stopped(): - #print "Display grid" - self.board.display_grid(window = self.window, grid_sz = self.grid_sz) # Draw the board + if self.sleep_timeout == None or (time.time() - self.last_event) < self.sleep_timeout: + + #print "Display grid" + self.board.display_grid(window = self.window, grid_sz = self.grid_sz) # Draw the board - #print "Display overlay" - self.overlay() + #print "Display overlay" + self.overlay() - #print "Display pieces" - self.board.display_pieces(window = self.window, grid_sz = self.grid_sz) # Draw the board + #print "Display pieces" + self.board.display_pieces(window = self.window, grid_sz = self.grid_sz) # Draw the board + + else: + self.window.fill((0,0,0)) pygame.display.flip() for event in pygame.event.get(): + self.last_event = time.time() if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_q): if isinstance(game, GameThread): with game.lock: @@ -71,8 +80,11 @@ class GraphicsThread(StoppableThread): break elif event.type == pygame.MOUSEBUTTONDOWN: self.mouse_down(event) + elif event.type == pygame.MOUSEBUTTONUP: - self.mouse_up(event) + self.mouse_up(event) + +