Changeset 689

Show
Ignore:
Timestamp:
08/09/07 15:33:08 (13 months ago)
Author:
daelstorm
Message:

Mucous: Split ticker drawing function into seperate cycle & scrolling functions

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/newnet/mucous/pymucous/MucousChatRooms.py

    r680 r689  
    4343                self.numticker = 0 
    4444                self.tickersize = 150 
     45                self.drawing_ticker = False 
    4546                ## @var tickers 
    4647                # dict of rooms containing lists of tickers  
     
    406407                        self.mucous.Help.Log("debug", "ChatRooms.UserJoined: " + str(e)) 
    407408                         
     409        def DrawTickerScroll(self, tickers): 
     410                longstring = "" 
     411                for user in tickers: 
     412                        if self.mucous.config.has_key("ignored") and self.mucous.config["ignored"].has_key(user): 
     413                                continue 
     414                        if not self.tickers[self.current].has_key(user): 
     415                                continue 
     416                        message = self.mucous.dlang(self.tickers[self.current][user])[:self.tickersize] 
     417                        if len(message) == self.tickersize: 
     418                                message += "..." 
     419                        longstring += "[%s] %s " % (user, message) 
     420                if self.shape in ("nostatuslog", "chat-only"): 
     421                        bw = self.windows["border"]["chat"] 
     422                        s = self.dimensions["chat"] 
     423                        padd = -3; posy = 0; posx = 2 
     424                else: 
     425 
     426                        bw = self.windows["border"]["roomstatus"] 
     427                        s = self.dimensions["roomstatus"] 
     428                        padd = 0; posy = 5; posx = 1 
     429 
     430                if self.numticker >= len(longstring): 
     431                        self.numticker = 0 
     432                part = longstring[self.numticker:self.numticker+s["width"]-2+padd] 
     433                while len(part) < s["width"]-2 +padd: 
     434                        part += longstring[:(s["width"]-2+padd - len(part))] 
     435                fill = (s["width"]-2 - len(part) +padd) * " " 
     436                try: 
     437                        fullmessage = "" 
     438                        for m in part: 
     439                                fullmessage += curses.unctrl(m) 
     440                        bw.addstr(posy, posx, "<%s%s>" %(fullmessage[:s["width"]-3], fill)) 
     441                        bw.refresh() 
     442                         
     443                except Exception, error: 
     444                        self.Help.Log("debug", error) 
     445                self.numticker += 1 
     446                #if self.numticker >= len(tickers): 
     447                        #self.numticker = 0 
     448                self.ticker_timer.cancel() 
     449                self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["scrolltime"]), self.DrawTicker) 
     450                self.ticker_timer.start() 
     451         
     452                 
     453        def DrawTickerCycle(self, tickers): 
     454                if self.numticker >= len(tickers): 
     455                        self.numticker = 0 
     456                names = tickers[self.numticker] 
     457                n = len(names) 
     458                try: 
     459                        if self.mucous.PopupMenu.show == True: raise Exception,  "Noticker" 
     460                        if self.shape not in ("nostatuslog", "chat-only"): 
     461                                if "roomstatus" not in self.windows["border"]: 
     462                                        return 
     463                                bw = self.windows["border"]["roomstatus"] 
     464                                s = self.dimensions["roomstatus"] 
     465                                tick = str(self.tickers[self.current][names][:s["width"]-7-n]) 
     466                                fill = (s["width"]-6-len(tick)-len(names)) * " " 
     467                                string = "< [%s] %s%s>" % (names, tick, fill) 
     468                                bw.addstr(5, 1, self.mucous.dlang( string )) 
     469                                bw.refresh() 
     470 
     471                        elif self.shape in ("nostatuslog", "chat-only"): 
     472                                mw = self.windows["border"]["chat"] 
     473                                s = self.dimensions["chat"] 
     474                                tick = str(self.tickers[self.current][names][:s["width"]-25-n]) 
     475                                fill = (s["width"]-25-len(tick)-len(names)) * " " 
     476                                string = "< [%s] %s%s>" %(names, tick, fill) 
     477                                mw.addstr(0, 18, self.mucous.dlang( string )) 
     478                                mw.refresh() 
     479                except Exception, error: 
     480                        self.Help.Log("debug", error) 
     481 
     482 
     483                self.numticker += 1 
     484 
     485                self.ticker_timer.cancel() 
     486                self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["cycletime"]), self.DrawTicker) 
     487                self.ticker_timer.start() 
     488                 
    408489        ## Loop and Draw the tickers in one of two ways (scrolling, cycling) 
    409490        # :: Scrolling shows the entire ticker, while Cycling shows only the part that fits in the viewable area 
    410491        # @param self is ChatRooms (Class) 
    411492        def DrawTicker(self): 
    412                 try: 
    413                         if self.mucous.mode != "chat" or self.current not in self.tickers or self.mucous.Config["tickers"]["tickers_enabled"] != 'yes': 
    414                                 return 
    415  
    416                         ttickers = self.tickers[self.current].keys() 
    417                         if ttickers == []: 
     493                if self.mucous.mode != "chat" or self.current not in self.tickers or self.mucous.Config["tickers"]["tickers_enabled"] != 'yes': 
     494                        self.drawing_ticker = False 
     495                        self.ticker_timer.cancel() 
     496                        return 
     497                if self.drawing_ticker: 
     498                        return 
     499                 
     500                if self.mucous.PopupMenu.show: 
     501                        self.ticker_timer.cancel() 
     502                        self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["scrolltime"]), self.DrawTicker) 
     503                        self.ticker_timer.start() 
     504                        return 
     505                self.drawing_ticker = True 
     506                try: 
     507                        sorted_tickers = self.tickers[self.current].keys() 
     508                        if sorted_tickers == []: 
    418509                                self.ticker_timer.cancel() 
    419510                                try: 
     
    424515                                        pass 
    425516                        else: 
    426                                 ttickers.sort(key=str.lower) 
     517                                sorted_tickers.sort(key=str.lower) 
    427518                                if self.mucous.Config["tickers"]["ticker_scroll"] == "yes": 
    428                                         if self.mucous.PopupMenu.show == True: 
    429                                                 self.ticker_timer.cancel() 
    430                                                 self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["scrolltime"]), self.DrawTicker) 
    431                                                 self.ticker_timer.start() 
    432                                                 return 
    433                                         longstring = "" 
    434                                         for user in ttickers: 
    435                                                 if self.mucous.config.has_key("ignored") and self.mucous.config["ignored"].has_key(user): 
    436                                                         continue 
    437                                                 if not self.tickers[self.current].has_key(user): 
    438                                                         continue 
    439                                                 message = self.mucous.dlang(self.tickers[self.current][user])[:self.tickersize] 
    440                                                 if len(message) == self.tickersize: 
    441                                                         message += "..." 
    442                                                 longstring += "[%s] %s " % (user, message) 
    443                                         if self.shape in ("nostatuslog", "chat-only"): 
    444                                                 bw = self.windows["border"]["chat"] 
    445                                                 s = self.dimensions["chat"] 
    446                                                 padd = -3; posy = 0; posx = 2 
    447                                         else: 
    448                                                   
    449                                                 bw = self.windows["border"]["roomstatus"] 
    450                                                 s = self.dimensions["roomstatus"] 
    451                                                 padd = 0; posy = 5; posx = 1 
    452                                          
    453                                         if self.numticker >= len(longstring): 
    454                                                 self.numticker = 0 
    455                                         part = longstring[self.numticker:self.numticker+s["width"]-2+padd] 
    456                                         while len(part) < s["width"]-2 +padd: 
    457                                                 part += longstring[:(s["width"]-2+padd - len(part))]  
    458                                         fill = (s["width"]-2 - len(part) +padd) * " " 
    459                                          
    460                                         fullmessage = "" 
    461                                         for m in part: 
    462                                                 fullmessage += curses.unctrl(m) 
    463                                         bw.addstr(posy, posx, "<%s%s>" %(fullmessage, fill)) 
    464                                         bw.refresh() 
    465                                         self.numticker += 1 
    466                                         #if self.numticker >= len(ttickers): 
    467                                                 #self.numticker = 0 
    468                                         self.ticker_timer.cancel() 
    469                                         self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["scrolltime"]), self.DrawTicker) 
    470                                         self.ticker_timer.start() 
    471                                         return 
    472                          
    473                                  
    474                                 if self.numticker >= len(ttickers): 
    475                                         self.numticker = 0 
    476                                 names = ttickers[self.numticker] 
    477                                 n = len(names) 
    478                                 try: 
    479                                         if self.mucous.PopupMenu.show == True: raise Exception,  "Noticker" 
    480                                         if self.shape not in ("nostatuslog", "chat-only"): 
    481                                                 if "roomstatus" not in self.windows["border"]: 
    482                                                         return 
    483                                                 bw = self.windows["border"]["roomstatus"] 
    484                                                 s = self.dimensions["roomstatus"] 
    485                                                 tick = str(self.tickers[self.current][names][:s["width"]-7-n]) 
    486                                                 fill = (s["width"]-6-len(tick)-len(names)) * " " 
    487                                                 string = "< [%s] %s%s>" % (names, tick, fill) 
    488                                                 bw.addstr(5, 1, self.mucous.dlang( string )) 
    489                                                 bw.refresh() 
    490                                                  
    491                                         elif self.shape in ("nostatuslog", "chat-only"): 
    492                                                 mw = self.windows["border"]["chat"] 
    493                                                 s = self.dimensions["chat"] 
    494                                                 tick = str(self.tickers[self.current][names][:s["width"]-25-n]) 
    495                                                 fill = (s["width"]-25-len(tick)-len(names)) * " " 
    496                                                 string = "< [%s] %s%s>" %(names, tick, fill) 
    497                                                 mw.addstr(0, 18, self.mucous.dlang( string )) 
    498                                                 mw.refresh() 
    499                                 except: 
    500                                         pass 
    501                                  
    502  
    503                                 self.numticker += 1 
    504  
    505                                 self.ticker_timer.cancel() 
    506                                 self.ticker_timer = threading.Timer(float(self.mucous.Config["tickers"]["cycletime"]), self.DrawTicker) 
    507                                 self.ticker_timer.start() 
    508                                  
    509                                  
     519                                        self.DrawTickerScroll(sorted_tickers) 
     520                                else: 
     521                                        self.DrawTickerCycle(sorted_tickers) 
     522                                curses.doupdate() 
    510523                except Exception,e: 
    511524                        self.mucous.Help.Log("debug", "ChatRooms.DrawTicker: " + str(e)) 
    512                          
     525                self.drawing_ticker = False 
     526                 
    513527        ## Draw the chat window's border 
    514528        # @param self is ChatRooms (Class)