From: <Blu...@us...> - 2010-04-24 22:05:43
|
Revision: 338 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=338&view=rev Author: BlueWolf_ Date: 2010-04-24 22:05:37 +0000 (Sat, 24 Apr 2010) Log Message: ----------- Moved the sh a bit and added a event-loop. Use the close-button to exit. Ctrl+c acts random Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/layout.py trunk/client/playground.py trunk/client/windows.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-04-24 21:22:36 UTC (rev 337) +++ trunk/client/VP.py 2010-04-24 22:05:37 UTC (rev 338) @@ -9,43 +9,49 @@ class Main(): def __init__(self): - # This will be available ([sh]ared) to all functions - self.sh = {} - self.blit_lock = threading.Lock() # Fire up pygame os.environ['SDL_VIDEO_CENTERED']='1' pygame.init() pygame.display.set_caption('Virtual Playground') - self.sh['screen'] = pygame.display.set_mode((1000, 700)) + sh['screen'] = pygame.display.set_mode((1000, 700)) #icon = load_image('img','icon.png') #pygame.display.set_icon(icon) pygame.key.set_repeat(250, 40) pygame.scrap.init() - # Give the program a way to close itself. Just call .set() and - # all your problems will be gone - self.sh['close'] = threading.Event() - - # Give the surfaces a way to blit themselves - self.sh['update'] = self.update + sh['update'] = self.update # Create all our surfaces - self.sh['playground'] = Playground(self.sh) - self.sh['layout'] = Layout(self.sh) - self.sh['windows'] = Windows(self.sh) + sh['playground'] = Playground() + sh['layout'] = Layout() + sh['windows'] = Windows() self.update() - - # Wait until someone decides to close VP (Why??) - try: self.sh['close'].wait(31556926) # A timeout of a year, - # should be enough - except: print + # Wait for all the events to come + try: + while 1: + ev = pygame.event.wait() + + if ev.type == QUIT: break + + if ev.type == MOUSEMOTION: + pos = pygame.mouse.get_pos() + pygame.event.clear(MOUSEMOTION) + + # [TODO] Do something + + + except KeyboardInterrupt: # Note: this does not work properly + print + + # Someone decided to close VP (Why??) sys.exit() + def update(self, rect = Rect(0,0, 1000, 700)): @@ -58,9 +64,9 @@ # the same time self.blit_lock.acquire() - self.sh['screen'].blit(self.sh['playground'].surf, rect, rect) - self.sh['screen'].blit(self.sh['layout'].surf, rect, rect) - self.sh['screen'].blit(self.sh['windows'].surf, rect, rect) + sh['screen'].blit(sh['playground'].surf, rect, rect) + sh['screen'].blit(sh['layout'].surf, rect, rect) + sh['screen'].blit(sh['windows'].surf, rect, rect) pygame.display.update(rect) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-04-24 21:22:36 UTC (rev 337) +++ trunk/client/functions.py 2010-04-24 22:05:37 UTC (rev 338) @@ -2,6 +2,9 @@ from pygame.locals import * import core +# This will be used to [sh]are all variables, functions and classes across the +# code +sh = {} def real_path(*dir): """ Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-04-24 21:22:36 UTC (rev 337) +++ trunk/client/layout.py 2010-04-24 22:05:37 UTC (rev 338) @@ -1,8 +1,7 @@ from functions import * class Layout(): - def __init__(self, sh): - self.sh = sh + def __init__(self): self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-04-24 21:22:36 UTC (rev 337) +++ trunk/client/playground.py 2010-04-24 22:05:37 UTC (rev 338) @@ -1,8 +1,7 @@ from functions import * class Playground(): - def __init__(self, sh): - self.sh = sh + def __init__(self): self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() Modified: trunk/client/windows.py =================================================================== --- trunk/client/windows.py 2010-04-24 21:22:36 UTC (rev 337) +++ trunk/client/windows.py 2010-04-24 22:05:37 UTC (rev 338) @@ -1,7 +1,6 @@ from functions import * class Windows(): - def __init__(self, sh): - self.sh = sh + def __init__(self): self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |