X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Fsrc%2Fgraphics.py;h=72b907f36d9f9ee528daafc40619f201cf0c5c4d;hp=041b137fd9cafc7d42f93d27f5b37aed7622b1ed;hb=HEAD;hpb=877034f05346e24fdf822f6e6149ad50d891f030 diff --git a/qchess/src/graphics.py b/qchess/src/graphics.py index 041b137..72b907f 100644 --- a/qchess/src/graphics.py +++ b/qchess/src/graphics.py @@ -1,9 +1,12 @@ graphics_enabled = True + try: import pygame + os.environ["SDL_VIDEO_ALLOW_SCREENSAVER"] = "1" except: graphics_enabled = False +import time @@ -24,6 +27,9 @@ class GraphicsThread(StoppableThread): self.error = 0 self.lock = threading.RLock() self.cond = threading.Condition() + self.sleep_timeout = None + self.last_event = time.time() + self.blackout = False #print "Test font" pygame.font.Font(os.path.join(os.path.curdir, "data", "DejaVuSans.ttf"), 32).render("Hello", True,(0,0,0)) @@ -47,19 +53,28 @@ 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 + self.blackout = False + + elif pygame.mouse.get_focused() and not self.blackout: + os.system("xset dpms force off") + self.blackout = True + self.window.fill((0,0,0)) pygame.display.flip() for event in pygame.event.get(): - if event.type == pygame.QUIT: + 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: game.final_result = "" @@ -71,10 +86,13 @@ 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) + + - + @@ -349,6 +367,18 @@ class GraphicsThread(StoppableThread): #print "Reject " + str(i) + str(event.pos) + " vs " + str(t) + # Function to choose between dedicated server or normal play + def SelectServer(self): + + choice = self.SelectButton(["Normal", "Join Eigenserver"],prompt="Game type?") + if choice == 0: + return None + choice = self.SelectButton(["progcomp.ucc", "other"], prompt="Address?") + if choice == 0: + return "progcomp.ucc.asn.au" + else: + return self.getstr(prompt = "Enter address:") + # Function to pick players in a nice GUI way def SelectPlayers(self, players = []): @@ -411,7 +441,7 @@ class GraphicsThread(StoppableThread): time.sleep(1) p = None players.append(p) - elif choice == 2: + elif choice == 1: address = "" while address == "": self.board.display_grid(self.window, self.grid_sz)