From: <ch...@us...> - 2009-05-09 15:25:05
|
Revision: 298 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=298&view=rev Author: chozone Date: 2009-05-09 15:25:00 +0000 (Sat, 09 May 2009) Log Message: ----------- Merging latest trunk changes in the grounds-branche. Now it works on windows, and with python 2.6+. Modified Paths: -------------- branches/VP-Grounds/TODO branches/VP-Grounds/VP.py branches/VP-Grounds/interface.py branches/VP-Grounds/lang/en.lang branches/VP-Grounds/lang/nl.lang branches/VP-Grounds/modules/input.py branches/VP-Grounds/modules/playground.py branches/VP-Grounds/modules/settings.py branches/VP-Grounds/notify.py Added Paths: ----------- branches/VP-Grounds/modules/__init__.py branches/VP-Grounds/modules/playgroundObj/ branches/VP-Grounds/modules/playgroundObj/__init__.py branches/VP-Grounds/modules/playgroundObj/avatar-multidir.py branches/VP-Grounds/modules/playgroundObj/avatar-multidir_parts.py branches/VP-Grounds/modules/playgroundObj/avatar-multipart.py branches/VP-Grounds/modules/playgroundObj/avatar-static.py branches/VP-Grounds/modules/playgroundObj/background.py branches/VP-Grounds/modules/playgroundObj/object.py Removed Paths: ------------- branches/VP-Grounds/modules/playground/ branches/VP-Grounds/modules/playgroundObj/__init__.py branches/VP-Grounds/modules/playgroundObj/background.py branches/VP-Grounds/modules/playgroundObj/object.py Property Changed: ---------------- branches/VP-Grounds/ Property changes on: branches/VP-Grounds ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/VP:276-287 + /trunk/VP:276-297 Modified: branches/VP-Grounds/TODO =================================================================== --- branches/VP-Grounds/TODO 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/TODO 2009-05-09 15:25:00 UTC (rev 298) @@ -11,6 +11,9 @@ 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... @@ -20,16 +23,11 @@ * Connecting the items with functions (assigned to BlueWolf_) * Submenus (assigned to BlueWolf_) - Playground + Playground (see VP-Grounds branche) * Creating the avatars (the images) -* Finishing up Static avatar (Z coords) (assigned to chozone) -* Finishing up multidir avatar (Z coords) (assigned to chozone) -* Finishing up multiparts avatar (Z coords) (assigned to chozone) -* Finishing up multidir_parts avatar (Z coords) (assigned to chozone) -* Walls +* Walls (assigned to chozone) on hold, we need jumping, before we can create/test this any further * Smooth walking -* Jumping -* Running (assigned to chozone) +* Jumping (will be assigned to BlueWolf_, or someone else really wants to do this...?) * Walking/running bit slower when walking diagonally (assigned to chozone) * Chat balloons (assigned to K-4U) Modified: branches/VP-Grounds/VP.py =================================================================== --- branches/VP-Grounds/VP.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/VP.py 2009-05-09 15:25:00 UTC (rev 298) @@ -45,9 +45,9 @@ #chat auto-states if not 'chat' in conf: conf['chat'] = {} - conf['chat']['auto_states_enabled'] = conf['chat'].get('auto_states_enabled','False') #Later this True? + conf['chat']['auto_states_enabled'] = conf['chat'].get('auto_states_enabled','True') conf['chat']['auto_states_online'] = conf['chat'].get('auto_states_online','(b|back)\Z') - conf['chat']['auto_states_busy'] = conf['chat'].get('auto_states_busy','(phone|dnd)((\W.*)\Z|\Z)') + conf['chat']['auto_states_busy'] = conf['chat'].get('auto_states_busy','(dnd)((\W.*)\Z|\Z)') conf['chat']['auto_states_away'] = conf['chat'].get('auto_states_away','(brb|afk)((\W.*)\Z|\Z)') #animations @@ -61,27 +61,21 @@ 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) + + 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 +110,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: branches/VP-Grounds/interface.py =================================================================== --- branches/VP-Grounds/interface.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/interface.py 2009-05-09 15:25:00 UTC (rev 298) @@ -19,6 +19,7 @@ #4 - Menu/tooltips self.lock = threading.Lock() + self.updateLock = threading.Lock() #Lock for forceUpdate self.needUpdate = [] @@ -39,9 +40,9 @@ #Load all modules in our memory self.modules = {} for module in os.listdir(getRealDir('modules')): - if module[-3:] == '.py': - realName = os.path.join('modules', module[:-3]) - self.modules[module[:-3]] = __import__(realName).Module + if module[-3:] == '.py' and not module.startswith('__'): + realName = '.'.join(('modules', module[:-3])) + self.modules[module[:-3]] = __import__(realName, fromlist=module[:-3]).Module @@ -81,7 +82,7 @@ for i, module in enumerate(self.openModules[prio]): if type(name) == str: - if module.__module__ == 'modules/' + name: + if module.__module__ == 'modules.' + name: module.close() del self.openModules[prio][i] print 'Interface.closeModule: Close', name, 'at', prio, '-', i @@ -128,7 +129,7 @@ #Search within the given priorities for prio in prioList: for i, module in enumerate(self.openModules[prio]): - if module.__module__ == 'modules/' + name: + if module.__module__ == 'modules.' + name: return True return False @@ -147,7 +148,7 @@ for prio in prioList: for i, module in enumerate(self.openModules[prio]): if type(name) == str: - if module.__module__ == 'modules/' + name: + if module.__module__ == 'modules.' + name: if len(self.openModules[prio])-1 != i: self.openModules[prio].append(self.openModules[prio].pop(i)) self.update(blit = True) @@ -196,6 +197,8 @@ """This will the interface use to actually update the screen""" if self.needUpdate != []: + self.updateLock.acquire() + #print 'Interface.forceUpdate' + str(self.needUpdate) if self.needUpdate == [None]: #Fullscreen update, yeah! @@ -207,6 +210,8 @@ for module in self.openModules[prio]: module.update(self.screen, rect_list) pygame.display.update(rect_list) + + self.updateLock.release() #Change the cursor, if needed if self.cursor != self.cursorNew: @@ -265,7 +270,7 @@ self.lock.acquire() for prio in range(5): for module in self.openModules[prio]: - if name == '' or module.__module__ == 'modules/' + name: + if name == '' or module.__module__ == 'modules.' + name: module.call(*arg) self.forceUpdate() Modified: branches/VP-Grounds/lang/en.lang =================================================================== --- branches/VP-Grounds/lang/en.lang 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/lang/en.lang 2009-05-09 15:25:00 UTC (rev 298) @@ -50,7 +50,7 @@ [[autostatechangedefault]] online = (b|back)\Z -busy = (phone|dnd)((\W.*)\Z|\Z) +busy = (dnd)((\W.*)\Z|\Z) away = (brb|afk)((\W.*)\Z|\Z) Modified: branches/VP-Grounds/lang/nl.lang =================================================================== --- branches/VP-Grounds/lang/nl.lang 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/lang/nl.lang 2009-05-09 15:25:00 UTC (rev 298) @@ -50,7 +50,7 @@ [[autostatechangedefault]] online = (b|back|biw)\Z -busy = (phone|dnd)((\W.*)\Z|\Z) +busy = (dnd)((\W.*)\Z|\Z) away = (brb|afk|bzt)((\W.*)\Z|\Z) Copied: branches/VP-Grounds/modules/__init__.py (from rev 297, trunk/VP/modules/__init__.py) =================================================================== --- branches/VP-Grounds/modules/__init__.py (rev 0) +++ branches/VP-Grounds/modules/__init__.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1 @@ +# Dummy file, not a module. Do NOT remove this file! Modified: branches/VP-Grounds/modules/input.py =================================================================== --- branches/VP-Grounds/modules/input.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/input.py 2009-05-09 15:25:00 UTC (rev 298) @@ -1,5 +1,5 @@ from functions import * -import time +import time, re class Module(): def __init__(self, share, *arg): @@ -39,9 +39,11 @@ else: #Just an enter if self.inputText != '': - text = self.inputText.encode('utf-8') - text = text.strip() - self.sh['Brains'].chatSend(text) + textToSend=self.checkChat() + if textToSend: + text = self.inputText.encode('utf-8') + text = text.strip() + self.sh['Brains'].chatSend(text) self.inputText = '' self.blit() @@ -56,9 +58,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: @@ -130,3 +140,51 @@ interface.update([179,471,370,29]) + + + def checkChat(self): + """ + Handles all commands that are in the chat. + Is called when user presses the enter key in the Input. + The message that will be send to the server is what this function returns. + """ + t=self.inputText + c=t[2:] if len(t)>=2 and t.startswith('//') else '' + + if c == 'exit' or c == 'quit': + self.sh['response'].put(('Exit',)) + elif c == 'time' or c == 'date' or c == 'datetime': + return time.ctime() + elif c.startswith('stat ') or c.startswith('status '): + t=t.replace('//status ', '') + t=t.replace('//stat ', '') + if t == 'online' or t == 'busy' or t == 'away': + user=self.sh['conf']['account']['user'] + curStatus=self.sh['users'][user]['State'] + + if t != curStatus: + self.sh['Brains'].setStatus(t) + else: + return self.inputText + elif c == 'online' or c == 'busy' or c == 'away': + user=self.sh['conf']['account']['user'] + curStatus=self.sh['users'][user]['State'] + if c != curStatus: + self.sh['Brains'].setStatus(c) + else: + #Maybe... it is part of that stupid auto chat status thingy? + conf=self.sh['conf']['chat'] + print conf + if conf['auto_states_enabled']=='True': + user=self.sh['conf']['account']['user'] + curStatus=self.sh['users'][user]['State'] + + stat=None + if re.match(conf['auto_states_online'], t): stat='online' + if re.match(conf['auto_states_busy'], t): stat='busy' + if re.match(conf['auto_states_away'], t): stat='away' + + if stat and stat != curStatus: + self.sh['Brains'].setStatus(stat) + + return self.inputText Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/playground.py 2009-05-09 15:25:00 UTC (rev 298) @@ -26,10 +26,10 @@ #Loading all our objects-modules (kinda like interface.py) self.modObjects = {} - for object in os.listdir(getRealDir('modules','playground')): - if object[-3:] == '.py': - realName = os.path.join('modules', 'playground', object[:-3]) - self.modObjects[object[:-3]] = __import__(realName).Object + for object in os.listdir(getRealDir('modules','playgroundObj')): + if object[-3:] == '.py' and not object.startswith('__'): + realName = '.'.join(('modules', 'playgroundObj', object[:-3])) + self.modObjects[object[:-3]] = __import__(realName, fromlist=object[:-3]).Object self.surf = pygame.Surface((726, 402)) Deleted: branches/VP-Grounds/modules/playgroundObj/__init__.py =================================================================== --- trunk/VP/modules/playgroundObj/__init__.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/playgroundObj/__init__.py 2009-05-09 15:25:00 UTC (rev 298) @@ -1 +0,0 @@ -# Dummy file, not a playground-module. Do NOT remove this file! Copied: branches/VP-Grounds/modules/playgroundObj/__init__.py (from rev 297, trunk/VP/modules/playgroundObj/__init__.py) =================================================================== --- branches/VP-Grounds/modules/playgroundObj/__init__.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/__init__.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1 @@ +# Dummy file, not a playground-module. Do NOT remove this file! Added: branches/VP-Grounds/modules/playgroundObj/avatar-multidir.py =================================================================== --- branches/VP-Grounds/modules/playgroundObj/avatar-multidir.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/avatar-multidir.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,102 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.currentDir=-1 #-1=none, 0=d, 1=l, 2=u, 3=r + + self.imageName=data['Avatar'][1] + self.image=None + self.fullImage=None + + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) + self.zorder = self.rect.top + self.rect.height + self.blitRect = Rect(0,0,0,0) #Internal rect, inside fullImage + + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + self.sh['Downloader'].getImage(self.imageName, self.imageUpdate) + + def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and make playground blit our rect. + """ + + self.rect.size = image[1].size + self.rect.w = self.rect.w/4 + + self.blitRect.size=self.rect.size + + self.fullImage = image[0] + + self.setDir(0) + + self.zorder = self.rect.top + self.rect.height + + self.sh['Playground'].blit(self.rect) + + def update(self, screen, rect): + if not self.image: return + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area. + Will also change our direction if needed. + """ + oldRect=self.rect.__copy__() + + #Change avatar direction + if self.rect.x < pos[1]: self.setDir('r') + elif self.rect.x > pos[1]: self.setDir('l') + elif self.rect.y < pos[2]: self.setDir('d') + elif self.rect.y > pos[2]: self.setDir('u') + + self.rect.x=pos[1] + self.rect.y=pos[2]-pos[3] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) + + def setDir(self, dir, blit=False): + """ + Change avatar direction. + `dir` can be either int(0,1,2,3) or str('d','l','u','r'). + """ + + #Change to correct value, or exit + if type(dir)!=int: + if dir=='d': dir=0 + elif dir=='l': dir=1 + elif dir=='u': dir=2 + elif dir=='r': dir=3 + else: return + + if dir < 0 or dir > 3: return #Valid number? + if dir == self.currentDir: return #Not the same as old direction? + + if not self.fullImage: return #Do we have base image? + + self.currentDir=dir + + #Actually change image + self.blitRect.x = self.blitRect.w * dir + self.image=self.fullImage.subsurface(self.blitRect) + + if blit: + self.sh['Playground'].blit(self.rect) Added: branches/VP-Grounds/modules/playgroundObj/avatar-multidir_parts.py =================================================================== --- branches/VP-Grounds/modules/playgroundObj/avatar-multidir_parts.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/avatar-multidir_parts.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,123 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.currentDir=0 # 0=d, 1=l, 2=u, 3=r + + self.imageList=data['Avatar'][1:] + self.imageNameList=data['Avatar'][1:] + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) + self.zorder = self.rect.top + self.rect.height + + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + + #We have multiple images, so loop through them, to download them all + for image in self.imageList: + self.sh['Downloader'].getImage(image, self.imageUpdate, image) + + def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and when we have all our images, we wil build ourselved. + """ + imageName=arg[0] + image=image + + self.imageList[self.imageNameList.index(imageName)]=image + + #Does our list still contain strings? + #(wich indicates we are still awaiting some downloads) + for img in self.imageList: + if type(img)!=tuple: return + + self.buildAvatar(True) + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area. + Will also change our direction if needed. + """ + oldRect=self.rect.__copy__() + + #Change avatar direction + if self.rect.x < pos[1]: self.setDir('r') + elif self.rect.x > pos[1]: self.setDir('l') + elif self.rect.y < pos[2]: self.setDir('d') + elif self.rect.y > pos[2]: self.setDir('u') + + self.rect.x=pos[1] + self.rect.y=pos[2]-pos[3] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) + + + def buildAvatar(self, blit=False): + oldRect=self.rect.__copy__() #So we can combine it later with our new rect, so we can also update te old area + + #Update Width(w) and height(h) + self.rect.w=max([rect.w/4 for img,rect in self.imageList]) + self.rect.h=0 + for img, rect in self.imageList: self.rect.h+=rect.h + + #And the zorder('cause we have new height) + self.zorder=self.rect.top+self.rect.height + + #Create clean surface for our avatar + self.image=pygame.Surface(self.rect.size, SRCALPHA, 32) + + #Blit all parts on this fresh surface + y=0 + for img,rect in self.imageList: + w=rect.w/4 #width of real image(there are 4 images in this one, for directions) + x=self.rect.w/2-w/2 + + self.image.blit(img, (x,y), (w*self.currentDir,0,w,rect.h)) + y+=rect.h + + if blit: + #Combine rects, and update area. It's time to show ourselves! :D + updateRect=self.rect.union(oldRect) + self.sh['Playground'].blit(updateRect) + + + def setDir(self, dir, blit=False): + """ + Change avatar direction. + `dir` can be either int(0,1,2,3) or str('d','l','u','r'). + """ + + #Change to correct value, or exit + if type(dir)!=int: + if dir=='d': dir=0 + elif dir=='l': dir=1 + elif dir=='u': dir=2 + elif dir=='r': dir=3 + else: return + + if dir < 0 or dir > 3: return #Valid number? + if dir == self.currentDir: return #Not the same as old direction? + + self.currentDir=dir + + #Actually change image + self.buildAvatar(blit) Added: branches/VP-Grounds/modules/playgroundObj/avatar-multipart.py =================================================================== --- branches/VP-Grounds/modules/playgroundObj/avatar-multipart.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/avatar-multipart.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,88 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.imageList=data['Avatar'][1:] + self.imageNameList=data['Avatar'][1:] + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) + self.zorder = self.rect.top + self.rect.height + + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + + #We have multiple images, so loop through them, to download them all + for image in self.imageList: + self.sh['Downloader'].getImage(image, self.imageUpdate, image) + + def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and when we have all our images, we wil build ourselved. + """ + imageName=arg[0] + image=image + + self.imageList[self.imageNameList.index(imageName)]=image + + #Does our list still contain strings? + #(wich indicates we are still awaiting some downloads) + for img in self.imageList: + if type(img)!=tuple: return + + self.buildAvatar() + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area + """ + oldRect=self.rect.__copy__() + + self.rect.x=pos[1] + self.rect.y=pos[2]-pos[3] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) + + + def buildAvatar(self): + oldRect=self.rect.__copy__() #So we can combine it later with our new rect, so we can also update te old area + + #Update Width(w) and height(h) + self.rect.w=max([rect.w for img,rect in self.imageList]) + self.rect.h=0 + for img, rect in self.imageList: self.rect.h+=rect.h + + #And the zorder('cause we have new height) + self.zorder=self.rect.top+self.rect.height + + #Create clean surface for our avatar + self.image=pygame.Surface(self.rect.size, SRCALPHA, 32) + + #Blit all parts on this fresh surface + y=0 + for img,rect in self.imageList: + x=self.rect.w/2-rect.w/2 + self.image.blit(img, (x,y)) + y+=rect.h + + #Combine rects, and update area. It's time to show ourselves! :D + updateRect=self.rect.union(oldRect) + self.sh['Playground'].blit(updateRect) Added: branches/VP-Grounds/modules/playgroundObj/avatar-static.py =================================================================== --- branches/VP-Grounds/modules/playgroundObj/avatar-static.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/avatar-static.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,52 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.imageName=data['Avatar'][1] + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) + self.zorder = self.rect.top + self.rect.height + + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + self.sh['Downloader'].getImage(self.imageName, self.imageUpdate) + + def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and make playground blit our rect. + """ + self.image = image[0] + self.rect.size = image[1].size + self.zorder = self.rect.top + self.rect.height + + self.sh['Playground'].blit(self.rect) + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area + """ + oldRect=self.rect.__copy__() + + self.rect.x=pos[1] + self.rect.y=pos[2]-pos[3] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) Deleted: branches/VP-Grounds/modules/playgroundObj/background.py =================================================================== --- trunk/VP/modules/playgroundObj/background.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/playgroundObj/background.py 2009-05-09 15:25:00 UTC (rev 298) @@ -1,44 +0,0 @@ -from functions import * - -class Object(): - def __init__(self, data, share): - self.downloader = share['downloader'] - self.master = share['master'] - - #Settings defaults - data['background'] = data.get('background', None) - backgroundcolor = data.get('backgroundcolor', (0,0,0)) - data['backgroundcolor'] = [int(c) for c in backgroundcolor] - self.data = data - - self.rect = Rect(0,0,726,402) - self.zorder = -1000 - - if self.data['background'] != None: - self.background = None - - self.downloader.getImage(self.data['background'], self.imageChange) - else: - self.background = pygame.Surface((726,402)) - self.background.fill(self.data['backgroundcolor']) - - def imageChange(self, image, *arg): - #Creating a new surface - self.background = pygame.Surface((726,402)) - self.background.fill(self.data['backgroundcolor']) - - #Trying to tile the image - pos = [0,0] - while pos[1] < 402: - while pos[0] < 726: - self.background.blit(image[0], pos) - pos[0] += image[1].w - pos[1] += image[1].h - pos[0] = 0 - self.master.blit(self.rect) - - def update(self, screen, rect): - if self.rect.colliderect(rect): #Check if the rect collide with ours - rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position - myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect - screen.blit(self.background, myPos, rect) #Blit Copied: branches/VP-Grounds/modules/playgroundObj/background.py (from rev 297, trunk/VP/modules/playgroundObj/background.py) =================================================================== --- branches/VP-Grounds/modules/playgroundObj/background.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/background.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,43 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + #Settings defaults + data['background'] = data.get('background', None) + backgroundcolor = data.get('backgroundcolor', (0,0,0)) + data['backgroundcolor'] = [int(c) for c in backgroundcolor] + self.data = data + + self.rect = Rect(0,0,726,402) + self.zorder = -1000 + + if self.data['background'] != None: + self.background = None + + self.sh['Downloader'].getImage(self.data['background'], self.imageChange) + else: + self.background = pygame.Surface((726,402)) + self.background.fill(self.data['backgroundcolor']) + + def imageChange(self, image, *arg): + #Creating a new surface + self.background = pygame.Surface((726,402)) + self.background.fill(self.data['backgroundcolor']) + + #Trying to tile the image + pos = [0,0] + while pos[1] < 402: + while pos[0] < 726: + self.background.blit(image[0], pos) + pos[0] += image[1].w + pos[1] += image[1].h + pos[0] = 0 + self.sh['Playground'].blit(self.rect) + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.background, myPos, rect) #Blit Deleted: branches/VP-Grounds/modules/playgroundObj/object.py =================================================================== --- trunk/VP/modules/playgroundObj/object.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/playgroundObj/object.py 2009-05-09 15:25:00 UTC (rev 298) @@ -1,50 +0,0 @@ -from functions import * - -class Object(): - def __init__(self, data, share): - self.downloader = share['downloader'] - self.master = share['master'] - - obj = data['objecttype'] - - self.pos = [int(i) for i in data['pos']] - self.size = [int(i) for i in obj['size']] - self.objZorder = int(obj['zorder']) - - #self.image = None - #self.imageName = 'default' - self.imageD = obj['imageD'] - self.imageN = obj['imageN'] - self.imageStyle = 'D' - - self.rect = Rect(self.pos[0], self.pos[1]-self.pos[2], self.size[0], self.size[1]) - self.zorder = self.pos[1] + self.objZorder - - self.changeImage('default') - - - def changeImage(self, name): - self.imageName = name - if self.imageStyle == 'D': - name = self.imageD[name] - else: - name = self.imageN[name] - - self.downloader.getImage(name, self.imageUpdate) - - - def imageUpdate(self, image, *arg): - self.image = list(image) - if list(image[1].size) != self.size: - self.image[0] = pygame.transform.smoothscale(self.image[0], self.size) - - self.master.blit(self.rect) - - - def update(self, screen, rect): - #print rect, self.rect - if self.rect.colliderect(rect): #Check if the rect collide with ours - rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position - myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect - screen.blit(self.image[0], myPos, rect) #Blit - #screen.blit(self.image[0], (0,0)) Copied: branches/VP-Grounds/modules/playgroundObj/object.py (from rev 297, trunk/VP/modules/playgroundObj/object.py) =================================================================== --- branches/VP-Grounds/modules/playgroundObj/object.py (rev 0) +++ branches/VP-Grounds/modules/playgroundObj/object.py 2009-05-09 15:25:00 UTC (rev 298) @@ -0,0 +1,72 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + obj = data['objecttype'] + + self.pos = [int(i) for i in data['pos']] + self.size = [int(i) for i in obj['size']] + self.objZorder = int(obj['zorder']) + + self.walls = data['objecttype']['walls'] + #Convert a dict of walls (in format 'name':['X1','X2','Y1','Y2','Z1','Z2']) + #to a simple list with all int values + self.walls = [[int(i) for i in w] for w in self.walls.values()] + + #Create a copy of our walls, and move these walls, so they + #are real position, instead of internal position + self.realWalls=[] + for wall in self.walls: + wall = wall[:] #Make a copy of this var, so we don't change it in our origional list + wall[0]+=self.pos[0] + wall[1]+=self.pos[0] + wall[2]+=self.pos[1] + wall[3]+=self.pos[1] + self.realWalls.append(wall) + + + + self.imageD = obj['imageD'] + self.imageN = obj['imageN'] + self.imageStyle = 'D' + + self.rect = Rect(self.pos[0], self.pos[1]-self.pos[2], self.size[0], self.size[1]) + self.zorder = self.pos[1] + self.objZorder + + self.changeImage('default') + + + def changeImage(self, name): + self.imageName = name + if self.imageStyle == 'D': + name = self.imageD[name] + else: + name = self.imageN[name] + + self.sh['Downloader'].getImage(name, self.imageUpdate) + + + def imageUpdate(self, image, *arg): + self.image = list(image) + if list(image[1].size) != self.size: + self.image[0] = pygame.transform.smoothscale(self.image[0], self.size) + + n=0 + for wall in self.walls: + rect=Rect(wall[0], wall[2], wall[1]-wall[0], wall[3]-wall[2]) + col=(50+20*n,50+20*n,50+20*n,200) + self.image[0].fill(col,rect) + + n+=1 + + self.sh['Playground'].blit(self.rect) + + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image[0], myPos, rect) #Blit + #screen.blit(self.image[0], (0,0)) Modified: branches/VP-Grounds/modules/settings.py =================================================================== --- branches/VP-Grounds/modules/settings.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/modules/settings.py 2009-05-09 15:25:00 UTC (rev 298) @@ -117,8 +117,7 @@ gui.Label(position = (15,80), parent = self.tab_misc, text = self.lang('misc','autochangestatus'))#section caption #DISABLED self.as_time=gui.CheckBox(position = self.tab_misc.nextPosition(5), parent = self.tab_misc, text = self.lang('misc','afterxmin'), value=conf['misc']['time_after_idle'],enabled=False) - #DISABLED - self.as_chat=gui.CheckBox(position = self.tab_misc.nextPosition(2), parent = self.tab_misc, text = self.lang('misc','chat'), value=conf['chat']['auto_states_enabled'],enabled=False) + self.as_chat=gui.CheckBox(position = self.tab_misc.nextPosition(2), parent = self.tab_misc, text = self.lang('misc','chat'), value=conf['chat']['auto_states_enabled']) #Create a special font style for our button labelStyleCopy = gui.defaultLabelStyle.copy() @@ -280,12 +279,6 @@ when the user click the 'reset chat states' button. Updates all images""" - #standard regexes - #now in lang files - #sonline="(b|back)\Z" - #sbusy="(phone|dnd)((\W.*)\Z|\Z)" - #saway="(brb|afk)((\W.*)\Z|\Z)" - #save in the local dict conf = self.sh['conf'] conf['chat']['auto_states_online'] = self.lang('autostatechangedefault','online') Modified: branches/VP-Grounds/notify.py =================================================================== --- branches/VP-Grounds/notify.py 2009-05-02 15:19:34 UTC (rev 297) +++ branches/VP-Grounds/notify.py 2009-05-09 15:25:00 UTC (rev 298) @@ -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. |