From: <ch...@us...> - 2009-05-01 22:22:13
|
Revision: 296 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=296&view=rev Author: chozone Date: 2009-05-01 22:22:11 +0000 (Fri, 01 May 2009) Log Message: ----------- With the following modifications, VP now works on windows: -event handler had to be in main thread, so swapped event loop, and Reponse loop. (is the Response loop still needed?) -notify.py now works with more than one program(not platform-dependent!). Also added support for Snarl. -on windows, clipboard now works, and had to replace all chr(0)'s with '', because... well, it's windows... Modified Paths: -------------- trunk/VP/TODO trunk/VP/VP.py trunk/VP/modules/input.py trunk/VP/notify.py Modified: trunk/VP/TODO =================================================================== --- trunk/VP/TODO 2009-05-01 15:27:26 UTC (rev 295) +++ trunk/VP/TODO 2009-05-01 22:22:11 UTC (rev 296) @@ -11,9 +11,16 @@ Chat * Making the scroll button (assigned to BlueWolf_) + Help +* Creating the help system (like http://dl.getdropbox.com/u/343509/help1.png) + Info(bar) * Creating the Info bar with information like: Current ground, user(?), money... + + Input +* Making special commands in chat +* Making that 'auto chat status' thingy (when you say something like 'brb', it will change your status to 'away') Menu * Creating checkitems (assigned to BlueWolf_) @@ -22,7 +29,7 @@ Playground (see VP-Grounds branche) * Creating the avatars (the images) -* Walls (assigned to chozone) +* Walls (assigned to chozone) on hold, we need jumping, before we can create/test this any further * Smooth walking * Jumping (will be assigned to BlueWolf_, or someone else really wants to do this...?) * Walking/running bit slower when walking diagonally (assigned to chozone) Modified: trunk/VP/VP.py =================================================================== --- trunk/VP/VP.py 2009-05-01 15:27:26 UTC (rev 295) +++ trunk/VP/VP.py 2009-05-01 22:22:11 UTC (rev 296) @@ -61,27 +61,22 @@ conf['misc']['time_after_idle'] = int(conf['misc'].get('time_after_idle', 0)) #in mins, 0 = off, later this 5? -class Events(threading.Thread): +class ResponseLoop(threading.Thread): def __init__(self, share): self.sh = share threading.Thread.__init__(self) def run(self): while 1: - resp = pygame.event.wait() - if resp.type == QUIT: - self.sh['response'].put(('Exit',)) + #Some wacky workaround here. + #Without timeout, the Queue will not respond to KeyboardInterrupts. + #This is a timeout of year. Think that will be enough :-) + resp = share['response'].get(True, 31536000) + print resp + + if resp[0] == 'Exit': + pygame.event.post(pygame.event.Event(QUIT)) return - - elif resp.type == USEREVENT: #Pinger - self.sh['Connection'].ping() - - elif resp.type == ACTIVEEVENT: - if resp.state == 2: #focus - self.sh['focus'] = resp.gain - - else: - self.sh['Interface'].event(resp, lock=True) @@ -116,23 +111,29 @@ share['Sounds'].start() share['Brains'].start() +#Start Response-loop in thread +respLoop = ResponseLoop(share) +respLoop.start() -#Starting our event-catcher -events = Events(share) -events.start() - #Entering our main-loop. Yeah! try: while 1: - #Some wacky workaround here. - #Without timeout, the Queue will not response to KeyboardInterrupts. - #This is a timeout of year. Think that will be enough :-) - resp = response.get(True, 31536000) + resp = pygame.event.wait() - if resp[0] == 'Exit': - share['conf'].write() - exit() + if resp.type == QUIT: + share['conf'].write() + exit() + + elif resp.type == USEREVENT: #Pinger + share['Connection'].ping() + + elif resp.type == ACTIVEEVENT: + if resp.state == 2: #focus + share['focus'] = resp.gain + + else: + share['Interface'].event(resp, lock=True) except KeyboardInterrupt: print Modified: trunk/VP/modules/input.py =================================================================== --- trunk/VP/modules/input.py 2009-05-01 15:27:26 UTC (rev 295) +++ trunk/VP/modules/input.py 2009-05-01 22:22:11 UTC (rev 296) @@ -39,9 +39,12 @@ else: #Just an enter if self.inputText != '': - text = self.inputText.encode('utf-8') - text = text.strip() - self.sh['Brains'].chatSend(text) + if self.inputText == '//exit': + self.sh['response'].put(('Exit',)) + else: + text = self.inputText.encode('utf-8') + text = text.strip() + self.sh['Brains'].chatSend(text) self.inputText = '' self.blit() @@ -56,9 +59,17 @@ else: #Control key pressed (and no backspace....) if ev.key == K_v: #Ctrl+V, paste clipboard - text = pygame.scrap.get('UTF8_STRING') - text = unicode(text) + if sys.platform == 'win32': + text = pygame.scrap.get('text/plain;charset=utf-8') + else: + text = pygame.scrap.get('UTF8_STRING') + + + if text: + text=text.replace(chr(0), '') + text = unicode(text) + #Check if we have to shorten, and maybe shorten #the text so it doesn't raise a 'too large' error. if self.fontObj.size(text)[0] > 16383: Modified: trunk/VP/notify.py =================================================================== --- trunk/VP/notify.py 2009-05-01 15:27:26 UTC (rev 295) +++ trunk/VP/notify.py 2009-05-01 22:22:11 UTC (rev 296) @@ -1,9 +1,36 @@ -import pynotify, re from functions import getRealDir -pynotify.init("Virtual Playground") + +method = None +print 'Looking for notify program...' + +#pynotify +try: + import pynotify +except ImportError: + print 'Not found: pynotify' +else: + import re + pynotify.init("Virtual Playground") + + print 'Found pynotify!' + method = 'pynotify' + +if not method: + #snarl + try: + import PySnarl + except ImportError: + print 'Not found: snarl' + else: + print 'Found snarl!' + method = 'snarl' + +if not method: print 'No notify program found!' + + def popup(caption,msg, img="", timeout=5000, urgency="normal"): - """popup(caption, message, image="", timeout=5000, urgency="normal) + """popup(caption, message, image="", timeout=5000, urgency="normal") Show a popup on screen. @@ -14,28 +41,36 @@ Urgency: low, normal, high """ - #Don't make libnotify crash by alien characters - msg=msg.decode('utf-8') + if method=='snarl': + id = PySnarl.snShowMessage( title = caption, + text = msg, + timeout = timeout/1000, + iconPath = getRealDir('images','popup',img)) - #Clickable urls - msg=re.sub('([^:]+://[^.]+\.[^ ]+)', '<a href="\\1">\\1</a>', msg) + elif method=='pynotify': - #Create it - notif=pynotify.Notification(caption,\ - msg,\ - getRealDir('images','popup',img)) - - #How long should we keep it on the screen? - notif.set_timeout(timeout) - - #Urgency - if urgency=="low": - notif.set_urgency(pynotify.URGENCY_LOW) - elif urgency=="high" or urgency=="critical": - notif.set_urgency(pynotify.URGENCY_CRITICAL) - else: - notif.set_urgency(pynotify.URGENCY_NORMAL) - - #Show it(+error catcher thingy) - if not notif.show(): - print "Failed to show notification" + #Don't make libnotify crash by alien characters + msg=msg.decode('utf-8') + + #Clickable urls + msg=re.sub('([^:]+://[^.]+\.[^ ]+)', '<a href="\\1">\\1</a>', msg) + + #Create it + notif=pynotify.Notification(caption, + msg, + getRealDir('images','popup',img)) + + #How long should we keep it on the screen? + notif.set_timeout(timeout) + + #Urgency + if urgency=="low": + notif.set_urgency(pynotify.URGENCY_LOW) + elif urgency=="high" or urgency=="critical": + notif.set_urgency(pynotify.URGENCY_CRITICAL) + else: + notif.set_urgency(pynotify.URGENCY_NORMAL) + + #Show it(+error catcher thingy) + if not notif.show(): + print "Failed to show notification" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |