Ticket #161: privatechat.py.diff

File privatechat.py.diff, 5.0 kB (added by gallows, 19 months ago)
  • privatechat.py

    old new  
    177177                        f.close() 
    178178                        s = d.split("\n") 
    179179                        for l in s[-8:-1]: 
    180                                 AppendLine(self.ChatScroll, l + "\n", self.tag_hilite, "", username=self.user, usertag=self.tag_username) 
     180                                AppendLine(self.ChatScroll, l + "\n", self.tag_hilite, "", username=self.user, usertag=self.tag_hilite) 
    181181                except IOError, e: 
    182182                        pass 
    183183 
     
    251251                         
    252252 
    253253        def SendMessage(self, text): 
    254  
     254                 
    255255                if text[:4] == "/me ": 
    256256                        line = "* %s %s" % (self.frame.np.config.sections["server"]["login"], text[4:]) 
    257257                        tag = self.tag_me 
     
    262262                        else: 
    263263                                line = text 
    264264                        tag = self.tag_local 
     265 
     266                my_username = self.frame.np.config.sections["server"]["login"] 
     267                if text[:4] == "/me ": 
     268                        AppendLine(self.ChatScroll, self.frame.np.decode(line, self.encoding), tag, "%c", username=my_username, usertag=self.tag_me) 
     269                else: 
     270                        AppendLine(self.ChatScroll, '[' + my_username + "] " + self.frame.np.decode(line, self.encoding), tag, "%c", username=my_username, usertag=self.tag_my_username) 
    265271                         
    266                 AppendLine(self.ChatScroll, self.frame.np.decode(line, self.encoding), tag, "%c", username=self.user, usertag=self.tag_username) 
    267272                if self.Log.get_active(): 
    268                         self.logfile = WriteLog(self.logfile, self.frame.np.config.sections["logging"]["logsdir"], self.user, line) 
     273                        self.logfile = WriteLog(self.logfile, self.frame.np.config.sections["logging"]["logsdir"], self.user, '[' + my_username + "] " + line) 
    269274                 
    270275                if self.PeerPrivateMessages.get_active(): 
    271276                        # not in the soulseek protocol 
     
    273278                else: 
    274279                        self.frame.np.queue.put(slskmessages.MessageUser(self.user, text)) 
    275280        CMDS = ["/alias ", "/unalias ", "/whois ", "/browse ", "/ip ", "/pm ", "/msg ", "/search ", "/usearch ", "/rsearch ", 
    276                 "/bsearch ", "/add ", "/buddy ", "/rem ", "/unbuddy ", "/ban ", "/ignore ", "/unban ", "/unignore ", "/clear", "/quit", "/rescan", "/nsa", "/info", "/ctcpversion"] 
     281                "/bsearch ", "/add ", "/buddy ", "/rem ", "/unbuddy ", "/ban ", "/ignore ", "/unban ", "/unignore ", "/clear", "/quit", "/rescan", "/nsa", "/info", "/ctcpversion", "/join"] 
    277282 
    278283        def OnEnter(self, widget): 
    279284                text = self.frame.np.encode(widget.get_text(), self.encoding) 
     
    375380                                self.SendMessage(np) 
    376381                elif cmd == "/rescan": 
    377382                        self.frame.OnRescan() 
     383                elif cmd in ["/join", "/j"]: 
     384                        self.frame.np.queue.put(slskmessages.JoinRoom(args)) 
    378385                elif cmd and cmd[:1] == "/" and cmd != "/me" and cmd[:2] != "//": 
    379386                        self.frame.logMessage(_("Command %s is not recognized") % text) 
    380387                        return 
     
    417424                        statuscolor = "useroffline" 
    418425         
    419426                self.tag_username = self.makecolour(buffer, statuscolor) 
     427                if self.frame.away: 
     428                        self.tag_my_username = self.makecolour(buffer, "useraway") 
     429                else: 
     430                        self.tag_my_username = self.makecolour(buffer, "useronline") 
     431 
    420432                usernamestyle = self.frame.np.config.sections["ui"]["usernamestyle"] 
    421433                if usernamestyle == "bold": 
    422434                        self.tag_username.set_property("weight",  pango.WEIGHT_BOLD) 
     435                        self.tag_my_username.set_property("weight",  pango.WEIGHT_BOLD) 
    423436                else: 
    424437                        self.tag_username.set_property("weight",  pango.WEIGHT_NORMAL) 
     438                        self.tag_my_username.set_property("weight",  pango.WEIGHT_NORMAL)                        
    425439                if usernamestyle == "italic": 
    426440                        self.tag_username.set_property("style",  pango.STYLE_ITALIC) 
     441                        self.tag_my_username.set_property("style",  pango.STYLE_ITALIC)                  
    427442                else: 
    428443                        self.tag_username.set_property("style",  pango.STYLE_NORMAL) 
     444                        self.tag_my_username.set_property("style",  pango.STYLE_NORMAL)                  
    429445                if usernamestyle == "underline": 
    430446                        self.tag_username.set_property("underline", pango.UNDERLINE_SINGLE) 
     447                        self.tag_my_username.set_property("underline", pango.UNDERLINE_SINGLE)                   
    431448                else: 
    432449                        self.tag_username.set_property("underline", pango.UNDERLINE_NONE) 
     450                        self.tag_my_username.set_property("underline", pango.UNDERLINE_NONE) 
     451                         
    433452                self.frame.SetTextBG(self.ChatScroll) 
    434453                self.frame.SetTextBG(self.ChatLine) 
    435454                 
     
    472491                self.changecolour(self.tag_hilite, "chathilite") 
    473492                color = self.getUserStatusColor(self.status) 
    474493                self.changecolour(self.tag_username, color) 
     494 
    475495                self.frame.SetTextBG(self.ChatScroll) 
    476496                self.frame.SetTextBG(self.ChatLine) 
     497 
     498                if self.frame.away: 
     499                        self.changecolour(self.tag_my_username, "useraway") 
     500                else: 
     501                        self.changecolour(self.tag_my_username, "useronline") 
    477502                 
    478503        def getUserStatusColor(self, status): 
    479504                if status == 1: 
     
    488513                if status == self.status: 
    489514                        return 
    490515                 
    491                  
    492516                self.status = status 
    493517 
    494518                color = self.getUserStatusColor(self.status) 
    495519 
    496520                self.changecolour(self.tag_username, color) 
    497                  
     521 
    498522                #line = "* " + ["User %s is offline", "User %s is away", "User %s is online"][status] % self.user 
    499523                #AppendLine(self.ChatScroll, line, self.tag_hilite, "%c") 
    500524         
     
    530554                        widget.insert_text(completion, ix) 
    531555                        widget.set_position(ix + len(completion)) 
    532556                widget.emit_stop_by_name("key_press_event") 
     557 
    533558                return True 
    534559 
    535560        def OnLogToggled(self, widget):