예제 #1
0
파일: profile.py 프로젝트: Dpeta/pesterchum
 def log(self, handle, msg):
     if self.parent.config.time12Format():
         time = strftime("[%I:%M")
     else:
         time = strftime("[%H:%M")
     if self.parent.config.showSeconds():
         time += strftime(":%S] ")
     else:
         time += "] "
     if handle[0] == '#':
         if not self.parent.config.logMemos() & self.parent.config.LOG:
             return
         if not self.parent.config.logMemos() & self.parent.config.STAMP:
             time = ""
     else:
         if not self.parent.config.logPesters() & self.parent.config.LOG:
             return
         if not self.parent.config.logPesters() & self.parent.config.STAMP:
             time = ""
     if self.parent.isBot(handle): return
     #watch out for illegal characters
     handle = re.sub(r'[<>:"/\\|?*]', "_", handle)
     bbcodemsg = time + convertTags(msg, "bbcode")
     html = time + convertTags(msg, "html") + "<br />"
     msg = time + convertTags(msg, "text")
     modes = {"bbcode": bbcodemsg, "html": html, "text": msg}
     if not self.convos.has_key(handle):
         time = datetime.now().strftime("%Y-%m-%d.%H.%M")
         self.convos[handle] = {}
         for (format, t) in modes.iteritems():
             if not os.path.exists(
                     "%s/%s/%s/%s" %
                 (self.logpath, self.handle, handle, format)):
                 os.makedirs("%s/%s/%s/%s" %
                             (self.logpath, self.handle, handle, format))
             try:
                 fp = codecs.open("%s/%s/%s/%s/%s.%s.txt" %
                                  (self.logpath, self.handle, handle,
                                   format, handle, time),
                                  encoding='utf-8',
                                  mode='a')
             except IOError:
                 errmsg = QtGui.QMessageBox(self)
                 errmsg.setText(
                     "Warning: Pesterchum could not open the log file for %s!"
                     % (handle))
                 errmsg.setInformativeText(
                     "Your log for %s will not be saved because something went wrong. We suggest restarting Pesterchum. Sorry :("
                     % (handle))
                 errmsg.show()
                 continue
             self.convos[handle][format] = fp
     for (format, t) in modes.iteritems():
         f = self.convos[handle][format]
         if platform.system() == "Windows":
             f.write(t + "\r\n")
         else:
             f.write(t + "\r\n")
         f.flush()
예제 #2
0
 def log(self, handle, msg):
     if self.parent.config.time12Format():
         time = strftime("[%I:%M")
     else:
         time = strftime("[%H:%M")
     if self.parent.config.showSeconds():
         time += strftime(":%S] ")
     else:
         time += "] "
     if handle[0] == "#":
         if not self.parent.config.logMemos() & self.parent.config.LOG:
             return
         if not self.parent.config.logMemos() & self.parent.config.STAMP:
             time = ""
     else:
         if not self.parent.config.logPesters() & self.parent.config.LOG:
             return
         if not self.parent.config.logPesters() & self.parent.config.STAMP:
             time = ""
     if unicode(handle).upper() == "NICKSERV":
         return
     # watch out for illegal characters
     handle = re.sub(r'[<>:"/\\|?*]', "_", handle)
     bbcodemsg = time + convertTags(msg, "bbcode")
     html = time + convertTags(msg, "html") + "<br />"
     msg = time + convertTags(msg, "text")
     modes = {"bbcode": bbcodemsg, "html": html, "text": msg}
     if not self.convos.has_key(handle):
         time = datetime.now().strftime("%Y-%m-%d.%H.%M")
         self.convos[handle] = {}
         for (format, t) in modes.iteritems():
             if not os.path.exists("%s/%s/%s/%s" % (self.logpath, self.handle, handle, format)):
                 os.makedirs("%s/%s/%s/%s" % (self.logpath, self.handle, handle, format))
             try:
                 fp = codecs.open(
                     "%s/%s/%s/%s/%s.%s.txt" % (self.logpath, self.handle, handle, format, handle, time),
                     encoding="utf-8",
                     mode="a",
                 )
             except IOError:
                 errmsg = QtGui.QMessageBox(self)
                 errmsg.setText("Warning: Pesterchum could not open the log file for %s!" % (handle))
                 errmsg.setInformativeText(
                     "Your log for %s will not be saved because something went wrong. We suggest restarting Pesterchum. Sorry :("
                     % (handle)
                 )
                 errmsg.show()
                 continue
             self.convos[handle][format] = fp
     for (format, t) in modes.iteritems():
         f = self.convos[handle][format]
         if platform.system() == "Windows":
             f.write(t + "\r\n")
         else:
             f.write(t + "\r\n")
         f.flush()
예제 #3
0
    def addMessage(self, msg, chum):
        if type(msg) in [str, unicode]:
            lexmsg = lexMessage(msg)
        else:
            lexmsg = msg
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        chumdb = window.chumdb
        if chum is not me: # SO MUCH WH1T3SP4C3 >:]
            if type(lexmsg[0]) is colorBegin: # get color tag
                colortag = lexmsg[0]
                try:
                    color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
                except ValueError:
                    color = QtGui.QColor("black")
                else:
                    chumdb.setColor(chum.handle, color)
                    parent.updateColor(chum.handle, color)
            else:
                color = chumdb.getColor(chum.handle)
        else:
            color = me.color

        chum.color = color
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        if chum is not me:
            if parent.times.has_key(chum.handle):
                time = parent.times[chum.handle]
                if time.getTime() is None:
                    # MY WAY OR THE HIGHWAY
                    time.addTime(timedelta(0))
            else:
                # new chum! time current
                newtime = timedelta(0)
                time = TimeTracker(newtime)
                parent.times[handle] = time
        else:
            time = parent.time

        if time.isFirstTime():
            grammar = time.getGrammar()
            joinmsg = chum.memojoinmsg(systemColor, time.getTime(), grammar, window.theme["convo/text/joinmemo"])
            self.append(convertTags(joinmsg))
            parent.mainwindow.chatlog.log(parent.channel, joinmsg)
            time.openCurrentTime()

        if type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar())
            window.chatlog.log(parent.channel, memsg)
            self.append(convertTags(memsg))
        else:
            self.append(convertTags(lexmsg))
            window.chatlog.log(parent.channel, lexmsg)
예제 #4
0
 def updateMood(self, mood, unblocked=False, old=None):
     syscolor = QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"])
     #~ if mood.name() == "offline" and self.chumopen == True and not unblocked:
     #~ self.mainwindow.ceasesound.play()
     #~ msg = self.chum.pestermsg(self.mainwindow.profile(), syscolor, self.mainwindow.theme["convo/text/ceasepester"])
     #~ self.textArea.append(convertTags(msg))
     #~ self.mainwindow.chatlog.log(self.title(), msg)
     #~ self.chumopen = False
     if old and old.name() != mood.name():
         msg = self.chum.moodmsg(mood, syscolor, self.mainwindow.theme)
         self.textArea.append(convertTags(msg))
         self.mainwindow.chatlog.log(self.title(), msg)
     if self.parent():
         self.parent().updateMood(self.title(), mood, unblocked)
     else:
         if self.chum.blocked(self.mainwindow.config) and not unblocked:
             self.setWindowIcon(
                 QtGui.QIcon(self.mainwindow.
                             theme["main/chums/moods/blocked/icon"]))
             self.optionsMenu.addAction(self.unblockchum)
             self.optionsMenu.removeAction(self.blockAction)
         else:
             self.setWindowIcon(mood.icon(self.mainwindow.theme))
             self.optionsMenu.removeAction(self.unblockchum)
             self.optionsMenu.addAction(self.blockAction)
예제 #5
0
파일: convo.py 프로젝트: Dariox/pesterchum
    def sentMessage(self):
        text = unicode(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        self.history.add(text)
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd and self.applyquirks:
            try:
                lexmsg = quirks.apply(lexmsg)
            except:
                msgbox = QtGui.QMessageBox()
                msgbox.setText("Whoa there! There seems to be a problem.")
                msgbox.setInformativeText("A quirk seems to be having a problem. (Possibly you're trying to capture a non-existant group?)")
                msgbox.exec_()
                return
        lexmsgs = splitMessage(lexmsg)

        for lm in lexmsgs:
            serverMsg = copy(lm)
            self.addMessage(lm, True)
            # if ceased, rebegin
            if hasattr(self, 'chumopen') and not self.chumopen:
                self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
                self.setChumOpen(True)
            text = convertTags(serverMsg, "ctag")
            self.messageSent.emit(text, self.title())
        self.textInput.setText("")
예제 #6
0
    def sentMessage(self):
        text = str(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        oocDetected = oocre.match(text.strip())
        if self.ooc and not oocDetected:
            text = "(( %s ))" % (text)
        self.history.add(text)
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd and self.applyquirks and not (self.ooc or oocDetected):
            try:
                lexmsg = quirks.apply(lexmsg)
            except:
                msgbox = QtWidgets.QMessageBox()
                msgbox.setText("Whoa there! There seems to be a problem.")
                msgbox.setInformativeText("A quirk seems to be having a problem. (Possibly you're trying to capture a non-existant group?)")
                msgbox.exec_()
                return
        lexmsgs = splitMessage(lexmsg)

        for lm in lexmsgs:
            serverMsg = copy(lm)
            self.addMessage(lm, True)
            # if ceased, rebegin
            if hasattr(self, 'chumopen') and not self.chumopen:
                self.mainwindow.newConvoStarted.emit(self.title(), True)
                self.setChumOpen(True)
            text = convertTags(serverMsg, "ctag")
            self.messageSent.emit(text, self.title())
        self.textInput.setText("")
예제 #7
0
    def sentMessage(self):
        text = unicode(self.textInput.text())
        if text == "" or text[0:11] == "PESTERCHUM:":
            return
        self.history.add(text)
        if self.time.getTime() == None:
            self.sendtime()
        grammar = self.time.getGrammar()
        quirks = self.mainwindow.userprofile.quirks
        lexmsg = lexMessage(text)
        if type(lexmsg[0]) is not mecmd:
            if self.applyquirks:
                lexmsg = quirks.apply(lexmsg)
            initials = self.mainwindow.profile().initials()
            colorcmd = self.mainwindow.profile().colorcmd()
            clientMsg = [colorBegin("<c=%s>" % (colorcmd), colorcmd),
                         "%s%s%s: " % (grammar.pcf, initials, grammar.number)] + lexmsg + [colorEnd("</c>")]
            # account for TC's parsing error
            serverMsg = [colorBegin("<c=%s>" % (colorcmd), colorcmd),
                         "%s: " % (initials)] + lexmsg + [colorEnd("</c>"), " "]
        else:
            clientMsg = copy(lexmsg)
            serverMsg = copy(lexmsg)

        self.addMessage(clientMsg, True)
        serverText = convertTags(serverMsg, "ctag")
        self.messageSent.emit(serverText, self.title())

        self.textInput.setText("")
예제 #8
0
 def memsg(self, syscolor, lexmsg, time=None):
     suffix = lexmsg[0].suffix
     msg = convertTags(lexmsg[1:], "text")
     uppersuffix = suffix.upper()
     if time is not None:
         handle = "%s %s" % (time.temporal, self.handle)
         initials = time.pcf+self.initials()+time.number+uppersuffix
     else:
         handle = self.handle
         initials = self.initials()+uppersuffix
     return "<c=%s>-- %s%s <c=%s>[%s]</c> %s --</c>" % (syscolor.name(), handle, suffix, self.colorhtml(), initials, msg)
예제 #9
0
 def loadLog(self, fname):
     fp = codecs.open("%s/%s/%s/%s/%s" % (self.logpath, self.handle, self.chum, self.format, fname), encoding='utf-8', mode='r')
     self.textArea.clear()
     for line in fp:
         cline = line.replace("\r\n", "").replace("[/color]","</c>").replace("[url]","").replace("[/url]","")
         cline = re.sub("\[color=(#.{6})]", r"<c=\1>", cline)
         self.textArea.append(convertTags(cline))
     textCur = self.textArea.textCursor()
     textCur.movePosition(1)
     self.textArea.setTextCursor(textCur)
     self.instructions.setText("Pesterlog with " +self.chum+ " on " + self.fileToTime(str(fname)))
예제 #10
0
 def memsg(self, syscolor, lexmsg, time=None):
     suffix = lexmsg[0].suffix
     msg = convertTags(lexmsg[1:], "text")
     uppersuffix = suffix.upper()
     if time is not None:
         handle = "%s %s" % (time.temporal, self.handle)
         initials = time.pcf+self.initials()+time.number+uppersuffix
     else:
         handle = self.handle
         initials = self.initials()+uppersuffix
     return "<c=%s>-- %s%s <c=%s>[%s]</c> %s --</c>" % (syscolor.name(), handle, suffix, self.colorhtml(), initials, msg)
예제 #11
0
 def updateMood(self, mood, unblocked=False, old=None):
     syscolor = QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"])
     if mood.name() == "offline" and self.chumopen == True and not unblocked:
         self.mainwindow.ceasesound.play()
         msg = self.chum.pestermsg(self.mainwindow.profile(), syscolor, self.mainwindow.theme["convo/text/ceasepester"])
         self.textArea.append(convertTags(msg))
         self.mainwindow.chatlog.log(self.title(), msg)
         self.chumopen = False
     elif old and old.name() != mood.name():
         msg = self.chum.moodmsg(mood, syscolor, self.mainwindow.theme)
         self.textArea.append(convertTags(msg))
         self.mainwindow.chatlog.log(self.title(), msg)
     if self.parent():
         self.parent().updateMood(self.title(), mood, unblocked)
     else:
         if self.chum.blocked(self.mainwindow.config) and not unblocked:
             self.setWindowIcon(QtGui.QIcon(self.mainwindow.theme["main/chums/moods/blocked/icon"]))
             self.optionsMenu.addAction(self.unblockchum)
             self.optionsMenu.removeAction(self.blockAction)
         else:
             self.setWindowIcon(mood.icon(self.mainwindow.theme))
             self.optionsMenu.removeAction(self.unblockchum)
             self.optionsMenu.addAction(self.blockAction)
예제 #12
0
 def sentMessage(self):
     text = unicode(self.textInput.text())
     if text == "" or text[0:11] == "PESTERCHUM:":
         return
     self.history.add(text)
     quirks = self.mainwindow.userprofile.quirks
     lexmsg = lexMessage(text)
     if type(lexmsg[0]) is not mecmd and self.applyquirks:
         lexmsg = quirks.apply(lexmsg)
     serverMsg = copy(lexmsg)
     self.addMessage(lexmsg, True)
     # if ceased, rebegin
     if hasattr(self, 'chumopen') and not self.chumopen:
         self.mainwindow.newConvoStarted.emit(QtCore.QString(self.title()), True)
     text = convertTags(serverMsg, "ctag")
     self.messageSent.emit(text, self.title())
     self.textInput.setText("")
예제 #13
0
    def smashclock(self):
        me = self.mainwindow.profile()
        time = txt2delta(self.timeinput.text())
        removed = self.time.removeTime(time)
        if removed:
            grammar = self.time.getGrammarTime(time)
            systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
            msg = me.memoclosemsg(systemColor, grammar, self.mainwindow.theme["convo/text/closememo"])
            self.textArea.append(convertTags(msg))
            self.mainwindow.chatlog.log(self.channel, msg)

        newtime = self.time.getTime()
        if newtime is None:
            newtime = timedelta(0)
            self.resetSlider(newtime, send=False)
        else:
            self.resetSlider(newtime)
예제 #14
0
 def loadLog(self, fname):
     fp = codecs.open(
         "%s/%s/%s/%s/%s" %
         (self.logpath, self.handle, self.chum, self.format, fname),
         encoding='utf-8',
         mode='r')
     self.textArea.clear()
     for line in fp:
         cline = line.replace("\r\n",
                              "").replace("[/color]", "</c>").replace(
                                  "[url]", "").replace("[/url]", "")
         cline = re.sub("\[color=(#.{6})]", r"<c=\1>", cline)
         self.textArea.append(convertTags(cline))
     textCur = self.textArea.textCursor()
     textCur.movePosition(1)
     self.textArea.setTextCursor(textCur)
     self.instructions.setText("Pesterlog with " + self.chum + " on " +
                               self.fileToTime(unicode(fname)))
예제 #15
0
    def timeUpdate(self, handle, cmd):
        window = self.mainwindow
        chum = PesterProfile(handle)
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        close = None
        # old TC command?
        try:
            secs = int(cmd)
            time = datetime.fromtimestamp(secs)
            timed = time - datetime.now()
            s = (timed.seconds // 60)*60
            timed = timedelta(timed.days, s)
        except ValueError:
            if cmd == "i":
                timed = timedelta(0)
            else:
                if cmd[len(cmd)-1] == 'c':
                    close = timeProtocol(cmd)
                    timed = None
                else:
                    timed = timeProtocol(cmd)

        if self.times.has_key(handle):
            if close is not None:
                if close in self.times[handle]:
                    self.times[handle].setCurrent(close)
                    grammar = self.times[handle].getGrammar()
                    self.times[handle].removeTime(close)
                    msg = chum.memoclosemsg(systemColor, grammar, window.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
            elif timed not in self.times[handle]:
                self.times[handle].addTime(timed)
            else:
                self.times[handle].setCurrent(timed)
        else:
            if timed is not None:
                ttracker = TimeTracker(timed)
                self.times[handle] = ttracker
예제 #16
0
    def addMessage(self, msg, chum):
        if type(msg) in [str, unicode]:
            lexmsg = lexMessage(msg)
        else:
            lexmsg = msg
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        if self.mainwindow.config.animations():
            for m in self.urls:
                if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
                    if m.state() == QtGui.QMovie.NotRunning:
                        m.start()
        chumdb = window.chumdb
        if chum is not me: # SO MUCH WH1T3SP4C3 >:]
            if type(lexmsg[0]) is colorBegin: # get color tag
                colortag = lexmsg[0]
                try:
                    color = QtGui.QColor(*[int(c) for c in colortag.color.split(",")])
                except ValueError:
                    color = QtGui.QColor("black")
                else:
                    chumdb.setColor(chum.handle, color)
                    parent.updateColor(chum.handle, color)
            else:
                color = chumdb.getColor(chum.handle)
        else:
            color = me.color

        chum.color = color
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        if chum is not me:
            if parent.times.has_key(chum.handle):
                time = parent.times[chum.handle]
                if time.getTime() is None:
                    # MY WAY OR THE HIGHWAY
                    time.addTime(timedelta(0))
            else:
                # new chum! time current
                newtime = timedelta(0)
                time = TimeTracker(newtime)
                parent.times[handle] = time
        else:
            time = parent.time

        if time.isFirstTime():
            grammar = time.getGrammar()
            joinmsg = chum.memojoinmsg(systemColor, time.getTime(), grammar, window.theme["convo/text/joinmemo"])
            self.append(convertTags(joinmsg))
            parent.mainwindow.chatlog.log(parent.channel, joinmsg)
            time.openCurrentTime()

        def makeSafe(msg):
            if msg.count("<c") > msg.count("</c>"):
                for i in range(msg.count("<c") - msg.count("</c>")):
                    msg = msg + "</c>"
            return "<span style=\"color:#000000\">" + msg + "</span>"
        if type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg, time=time.getGrammar())
            window.chatlog.log(parent.channel, memsg)
            self.append(convertTags(memsg))
        else:
            self.append(makeSafe(convertTags(lexmsg)))
            window.chatlog.log(parent.channel, lexmsg)
예제 #17
0
    def __init__(self, channel, timestr, mainwindow, parent=None):
        QtGui.QFrame.__init__(self, parent)
        self.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
        self.channel = channel
        self.setObjectName(self.channel)
        self.mainwindow = mainwindow
        self.time = TimeTracker(txt2delta(timestr))
        self.setWindowTitle(channel)
        self.channelLabel = QtGui.QLabel(self)
        self.channelLabel.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding))

        self.textArea = MemoText(self.mainwindow.theme, self)
        self.textInput = MemoInput(self.mainwindow.theme, self)
        self.textInput.setFocus()

        self.userlist = RightClickList(self)
        self.userlist.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding))
        self.userlist.optionsMenu = QtGui.QMenu(self)
        self.addchumAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/addchum"], self)
        self.connect(self.addchumAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('addChumSlot()'))
        self.banuserAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/banuser"], self)
        self.connect(self.banuserAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('banSelectedUser()'))
        self.opAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/opuser"], self)
        self.connect(self.opAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('opSelectedUser()'))
        self.userlist.optionsMenu.addAction(self.addchumAction)
        # ban & op list added if we are op

        self.optionsMenu = QtGui.QMenu(self)
        self.quirksOff = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"], self)
        self.quirksOff.setCheckable(True)
        self.connect(self.quirksOff, QtCore.SIGNAL('toggled(bool)'),
                     self, QtCore.SLOT('toggleQuirks(bool)'))
        self.optionsMenu.addAction(self.quirksOff)

        self.timeslider = TimeSlider(QtCore.Qt.Horizontal, self)
        self.timeinput = TimeInput(self.timeslider, self)
        self.timeinput.setText(timestr)
        self.timeinput.setSlider()
        self.timetravel = QtGui.QPushButton("GO", self)
        self.timeclose = QtGui.QPushButton("CLOSE", self)
        self.timeswitchl = QtGui.QPushButton(self)
        self.timeswitchr = QtGui.QPushButton(self)

        self.connect(self.timetravel, QtCore.SIGNAL('clicked()'),
                     self, QtCore.SLOT('sendtime()'))
        self.connect(self.timeclose, QtCore.SIGNAL('clicked()'),
                     self, QtCore.SLOT('smashclock()'))
        self.connect(self.timeswitchl, QtCore.SIGNAL('clicked()'),
                     self, QtCore.SLOT('prevtime()'))
        self.connect(self.timeswitchr, QtCore.SIGNAL('clicked()'),
                     self, QtCore.SLOT('nexttime()'))

        self.times = {}

        self.initTheme(self.mainwindow.theme)

        # connect
        self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'),
                     self, QtCore.SLOT('sentMessage()'))

        layout_0 = QtGui.QVBoxLayout()
        layout_0.addWidget(self.textArea)
        layout_0.addWidget(self.textInput)

        layout_1 = QtGui.QHBoxLayout()
        layout_1.addLayout(layout_0)
        layout_1.addWidget(self.userlist)

#        layout_1 = QtGui.QGridLayout()
#        layout_1.addWidget(self.timeslider, 0, 1, QtCore.Qt.AlignHCenter)
#        layout_1.addWidget(self.timeinput, 1, 0, 1, 3)
        layout_2 = QtGui.QHBoxLayout()
        layout_2.addWidget(self.timeslider)
        layout_2.addWidget(self.timeinput)
        layout_2.addWidget(self.timetravel)
        layout_2.addWidget(self.timeclose)
        layout_2.addWidget(self.timeswitchl)
        layout_2.addWidget(self.timeswitchr)
        self.layout = QtGui.QVBoxLayout()

        self.layout.addWidget(self.channelLabel)
        self.layout.addLayout(layout_1)
        self.layout.addLayout(layout_2)
        self.layout.setSpacing(0)
        margins = self.mainwindow.theme["memos/margins"]
        self.layout.setContentsMargins(margins["left"], margins["top"],
                                  margins["right"], margins["bottom"])
        
        self.setLayout(self.layout)

        if parent:
            parent.addChat(self)

        p = self.mainwindow.profile()
        timeGrammar = self.time.getGrammar()
        systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
        msg = p.memoopenmsg(systemColor, self.time.getTime(), timeGrammar, self.mainwindow.theme["convo/text/openmemo"], self.channel)
        self.time.openCurrentTime()
        self.textArea.append(convertTags(msg))
        self.mainwindow.chatlog.log(self.channel, msg)

        self.op = False
        self.newmessage = False
        self.history = PesterHistory()
        self.applyquirks = True
예제 #18
0
    def addMessage(self, lexmsg, chum):
        if len(lexmsg) == 0:
            return
        color = chum.colorcmd()
        systemColor = QtGui.QColor(self.parent().mainwindow.theme["convo/systemMsgColor"])
        initials = chum.initials()
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        if lexmsg[0] == "PESTERCHUM:BEGIN":
            parent.setChumOpen(True)
            pmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:CEASE":
            parent.setChumOpen(False)
            pmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/ceasepester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCK":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/blocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:UNBLOCK":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/unblocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCKED":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/blockedmsg'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:IDLE":
            imsg = chum.idlemsg(systemColor, window.theme['convo/text/idle'])
            window.chatlog.log(chum.handle, imsg)
            self.append(convertTags(imsg))
        elif type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg)
            if chum is me:
                window.chatlog.log(parent.chum.handle, memsg)
            else:
                window.chatlog.log(chum.handle, memsg)
            self.append(convertTags(memsg))
        else:
            if not parent.chumopen and chum is not me:
                beginmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
                parent.setChumOpen(True)
                window.chatlog.log(chum.handle, beginmsg)
                self.append(convertTags(beginmsg))

            lexmsg[0:0] = [colorBegin("<c=%s>" % (color), color), 
                           "%s: " % (initials)]
            lexmsg.append(colorEnd("</c>"))
            self.append(convertTags(lexmsg))
            if chum is me:
                window.chatlog.log(parent.chum.handle, lexmsg)
            else:
                if window.idleaction.isChecked() and parent.chumopen:
                    idlethreshhold = 60
                    if (not hasattr(self, 'lastmsg')) or \
                            datetime.now() - self.lastmsg > timedelta(0,idlethreshhold):
                        verb = window.theme["convo/text/idle"]
                        idlemsg = me.idlemsg(systemColor, verb)
                        parent.textArea.append(convertTags(idlemsg))
                        window.chatlog.log(parent.title(), idlemsg)
                        parent.messageSent.emit("PESTERCHUM:IDLE", parent.title())
                self.lastmsg = datetime.now()
                window.chatlog.log(chum.handle, lexmsg)
예제 #19
0
    def userPresentChange(self, handle, channel, update):
        h = unicode(handle)
        c = unicode(channel)
        update = unicode(update)
        if update[0:4] == "kick": # yeah, i'm lazy.
            l = update.split(":")
            update = l[0]
            op = l[1]
        if update == "nick":
            l = h.split(":")
            oldnick = l[0]
            newnick = l[1]
            h = oldnick
        if (update in ["join","left", "kick", "+o"]) \
                and channel != self.channel:
            return
        chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
        systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
        # print exit
        if update == "quit" or update == "left" or update == "nick":
            for c in chums:
                chum = PesterProfile(h)
                self.userlist.takeItem(self.userlist.row(c))
                if not self.times.has_key(h):
                    self.times[h] = TimeTracker(timedelta(0))
                while self.times[h].getTime() is not None:
                    t = self.times[h]
                    grammar = t.getGrammar()
                    msg = chum.memoclosemsg(systemColor, grammar, self.mainwindow.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                    self.times[h].removeTime(t.getTime())
                if update == "nick":
                    self.addUser(newnick)
        elif update == "kick":
            if len(chums) == 0:
                return
            c = chums[0]
            chum = PesterProfile(h)
            if h == self.mainwindow.profile().handle:
                chum = self.mainwindow.profile()
                ttracker = self.time
                curtime = self.time.getTime()
            elif self.times.has_key(h):
                ttracker = self.times[h]
            else:
                ttracker = TimeTracker(timedelta(0))
            while ttracker.getTime() is not None:
                grammar = ttracker.getGrammar()
                opchum = PesterProfile(op)
                if self.times.has_key(op):
                    opgrammar = self.times[op].getGrammar()
                elif op == self.mainwindow.profile().handle:
                    opgrammar = self.time.getGrammar()
                else:
                    opgrammar = TimeGrammar("CURRENT", "C", "RIGHT NOW")
                msg = chum.memobanmsg(opchum, opgrammar, systemColor, grammar)
                self.textArea.append(convertTags(msg))
                self.mainwindow.chatlog.log(self.channel, msg)
                ttracker.removeTime(ttracker.getTime())

            if chum is self.mainwindow.profile():
                # are you next?
                msgbox = QtGui.QMessageBox()
                msgbox.setText(self.mainwindow.theme["convo/text/kickedmemo"])
                msgbox.setInformativeText("press 0k to rec0nnect or cancel to absc0nd")
                msgbox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
                ret = msgbox.exec_()
                if ret == QtGui.QMessageBox.Ok:
                    self.userlist.clear()
                    self.time = TimeTracker(curtime)
                    self.resetSlider(curtime)
                    self.mainwindow.joinChannel.emit(self.channel)
                    me = self.mainwindow.profile()
                    self.time.openCurrentTime()
                    msg = me.memoopenmsg(systemColor, self.time.getTime(), self.time.getGrammar(), self.mainwindow.theme["convo/text/openmemo"], self.channel)
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                elif ret == QtGui.QMessageBox.Cancel:
                    if self.parent():
                        i = self.parent().tabIndices[self.channel]
                        self.parent().tabClose(i)
                    else:
                        self.close()
            else:
                # i warned you about those stairs bro
                self.userlist.takeItem(self.userlist.row(c))
        elif update == "join":
            self.addUser(h)
            time = self.time.getTime()
            serverText = "PESTERCHUM:TIME>"+delta2txt(time, "server")
            self.messageSent.emit(serverText, self.title())
        elif update == "+o":
            chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
            for c in chums:
                icon = PesterIcon(self.mainwindow.theme["memos/op/icon"])
                c.setIcon(icon)
                if unicode(c.text()) == self.mainwindow.profile().handle:
                    self.userlist.optionsMenu.addAction(self.opAction)
                    self.userlist.optionsMenu.addAction(self.banuserAction)
예제 #20
0
파일: convo.py 프로젝트: Dariox/pesterchum
    def __init__(self, chum, initiated, mainwindow, parent=None):
        QtGui.QFrame.__init__(self, parent)
        self.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
        self.setObjectName(chum.handle)
        self.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.chum = chum
        self.mainwindow = mainwindow
        theme = self.mainwindow.theme
        self.resize(*theme["convo/size"])
        self.setStyleSheet("QFrame#%s { %s }" % (chum.handle, theme["convo/style"]))
        self.setWindowIcon(self.icon())
        self.setWindowTitle(self.title())

        t = Template(self.mainwindow.theme["convo/chumlabel/text"])

        self.chumLabel = QtGui.QLabel(t.safe_substitute(handle=chum.handle), self)
        self.chumLabel.setStyleSheet(self.mainwindow.theme["convo/chumlabel/style"])
        self.chumLabel.setAlignment(self.aligndict["h"][self.mainwindow.theme["convo/chumlabel/align/h"]] | self.aligndict["v"][self.mainwindow.theme["convo/chumlabel/align/v"]])
        self.chumLabel.setMaximumHeight(self.mainwindow.theme["convo/chumlabel/maxheight"])
        self.chumLabel.setMinimumHeight(self.mainwindow.theme["convo/chumlabel/minheight"])
        self.chumLabel.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding))
        self.textArea = PesterText(self.mainwindow.theme, self)
        self.textInput = PesterInput(self.mainwindow.theme, self)
        self.textInput.setFocus()

        self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'),
                     self, QtCore.SLOT('sentMessage()'))

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.chumLabel)
        self.layout.addWidget(self.textArea)
        self.layout.addWidget(self.textInput)
        self.layout.setSpacing(0)
        margins = self.mainwindow.theme["convo/margins"]
        self.layout.setContentsMargins(margins["left"], margins["top"],
                                      margins["right"], margins["bottom"])

        self.setLayout(self.layout)

        self.optionsMenu = QtGui.QMenu(self)
        self.optionsMenu.setStyleSheet(self.mainwindow.theme["main/defaultwindow/style"])
        self.addChumAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/addchum"], self)
        self.connect(self.addChumAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('addThisChum()'))
        self.blockAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/blockchum"], self)
        self.connect(self.blockAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('blockThisChum()'))
        self.quirksOff = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"], self)
        self.quirksOff.setCheckable(True)
        self.connect(self.quirksOff, QtCore.SIGNAL('toggled(bool)'),
                     self, QtCore.SLOT('toggleQuirks(bool)'))
        self.unblockchum = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/unblockchum"], self)
        self.connect(self.unblockchum, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('unblockChumSlot()'))
        self.reportchum = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/report"], self)
        self.connect(self.reportchum, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('reportThisChum()'))
        self.logchum = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/viewlog"], self)
        self.connect(self.logchum, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('openChumLogs()'))

        self.optionsMenu.addAction(self.quirksOff)
        self.optionsMenu.addAction(self.logchum)
        self.optionsMenu.addAction(self.addChumAction)
        self.optionsMenu.addAction(self.blockAction)
        self.optionsMenu.addAction(self.reportchum)

        self.chumopen = False
        self.applyquirks = True

        if parent:
            parent.addChat(self)
        if initiated:
            msg = self.mainwindow.profile().pestermsg(self.chum, QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/beganpester"])
            self.setChumOpen(True)
            self.textArea.append(convertTags(msg))
            self.mainwindow.chatlog.log(self.title(), msg)
        self.newmessage = False
        self.history = PesterHistory()
예제 #21
0
파일: convo.py 프로젝트: Dariox/pesterchum
 def myUpdateMood(self, mood):
     chum = self.mainwindow.profile()
     syscolor = QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"])
     msg = chum.moodmsg(mood, syscolor, self.mainwindow.theme)
     self.textArea.append(convertTags(msg))
     self.mainwindow.chatlog.log(self.title(), msg)
예제 #22
0
파일: convo.py 프로젝트: Dariox/pesterchum
    def addMessage(self, lexmsg, chum):
        if len(lexmsg) == 0:
            return
        color = chum.colorcmd()
        systemColor = QtGui.QColor(self.parent().mainwindow.theme["convo/systemMsgColor"])
        initials = chum.initials()
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        if self.mainwindow.config.animations():
            for m in self.urls:
                if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
                    if m.state() == QtGui.QMovie.NotRunning:
                        m.start()
        if self.parent().mainwindow.config.showTimeStamps():
            if self.parent().mainwindow.config.time12Format():
                time = strftime("[%I:%M")
            else:
                time = strftime("[%H:%M")
            if self.parent().mainwindow.config.showSeconds():
                time += strftime(":%S] ")
            else:
                time += "] "
        else:
            time = ""
        if lexmsg[0] == "PESTERCHUM:BEGIN":
            parent.setChumOpen(True)
            pmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:CEASE":
            parent.setChumOpen(False)
            pmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/ceasepester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCK":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/blocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:UNBLOCK":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/unblocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCKED":
            pmsg = chum.pestermsg(me, systemColor, window.theme['convo/text/blockedmsg'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:IDLE":
            imsg = chum.idlemsg(systemColor, window.theme['convo/text/idle'])
            window.chatlog.log(chum.handle, imsg)
            self.append(convertTags(imsg))
        elif type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg)
            if chum is me:
                window.chatlog.log(parent.chum.handle, memsg)
            else:
                window.chatlog.log(chum.handle, memsg)
            self.append(time + convertTags(memsg))
        else:
            if not parent.chumopen and chum is not me:
                beginmsg = chum.pestermsg(me, systemColor, window.theme["convo/text/beganpester"])
                parent.setChumOpen(True)
                window.chatlog.log(chum.handle, beginmsg)
                self.append(convertTags(beginmsg))

            lexmsg[0:0] = [colorBegin("<c=%s>" % (color), color),
                           "%s: " % (initials)]
            lexmsg.append(colorEnd("</c>"))
            self.append("<span style=\"color:#000000\">" + time + convertTags(lexmsg) + "</span>")
            if chum is me:
                window.chatlog.log(parent.chum.handle, lexmsg)
            else:
                if window.idleaction.isChecked() and parent.chumopen:
                    idlethreshhold = 60
                    if (not hasattr(self, 'lastmsg')) or \
                            datetime.now() - self.lastmsg > timedelta(0,idlethreshhold):
                        verb = window.theme["convo/text/idle"]
                        idlemsg = me.idlemsg(systemColor, verb)
                        parent.textArea.append(convertTags(idlemsg))
                        window.chatlog.log(parent.title(), idlemsg)
                        parent.messageSent.emit("PESTERCHUM:IDLE", parent.title())
                self.lastmsg = datetime.now()
                window.chatlog.log(chum.handle, lexmsg)
예제 #23
0
    def __init__(self, chum, initiated, mainwindow, parent=None):
        QtGui.QFrame.__init__(self, parent)
        self.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
        self.setObjectName(chum.handle)
        self.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.chum = chum
        self.mainwindow = mainwindow
        theme = self.mainwindow.theme
        self.resize(*theme["convo/size"])
        self.setStyleSheet("QFrame#%s { %s }" % (chum.handle, theme["convo/style"]))
        self.setWindowIcon(self.icon())
        self.setWindowTitle(self.title())

        t = Template(self.mainwindow.theme["convo/chumlabel/text"])
        
        self.chumLabel = QtGui.QLabel(t.safe_substitute(handle=chum.handle), self)
        self.chumLabel.setStyleSheet(self.mainwindow.theme["convo/chumlabel/style"])
        self.chumLabel.setAlignment(self.aligndict["h"][self.mainwindow.theme["convo/chumlabel/align/h"]] | self.aligndict["v"][self.mainwindow.theme["convo/chumlabel/align/v"]])
        self.chumLabel.setMaximumHeight(self.mainwindow.theme["convo/chumlabel/maxheight"])
        self.chumLabel.setMinimumHeight(self.mainwindow.theme["convo/chumlabel/minheight"])
        self.chumLabel.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding))
        self.textArea = PesterText(self.mainwindow.theme, self)
        self.textInput = PesterInput(self.mainwindow.theme, self)
        self.textInput.setFocus()

        self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'),
                     self, QtCore.SLOT('sentMessage()'))

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.chumLabel)
        self.layout.addWidget(self.textArea)
        self.layout.addWidget(self.textInput)
        self.layout.setSpacing(0)
        margins = self.mainwindow.theme["convo/margins"]
        self.layout.setContentsMargins(margins["left"], margins["top"],
                                      margins["right"], margins["bottom"])
        
        self.setLayout(self.layout)

        self.optionsMenu = QtGui.QMenu(self)
        self.optionsMenu.setStyleSheet(self.mainwindow.theme["main/defaultwindow/style"])
        self.addChumAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/addchum"], self)
        self.connect(self.addChumAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('addThisChum()'))
        self.blockAction = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/blockchum"], self)
        self.connect(self.blockAction, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('blockThisChum()'))
        self.quirksOff = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"], self)
        self.quirksOff.setCheckable(True)
        self.connect(self.quirksOff, QtCore.SIGNAL('toggled(bool)'),
                     self, QtCore.SLOT('toggleQuirks(bool)'))
        self.unblockchum = QtGui.QAction(self.mainwindow.theme["main/menus/rclickchumlist/unblockchum"], self)
        self.connect(self.unblockchum, QtCore.SIGNAL('triggered()'),
                     self, QtCore.SLOT('unblockChumSlot()'))

        self.optionsMenu.addAction(self.quirksOff)
        self.optionsMenu.addAction(self.addChumAction)
        self.optionsMenu.addAction(self.blockAction)

        self.chumopen = False
        self.applyquirks = True

        if parent:
            parent.addChat(self)
        if initiated:
            msg = self.mainwindow.profile().pestermsg(self.chum, QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]), self.mainwindow.theme["convo/text/beganpester"])
            self.setChumOpen(True)
            self.textArea.append(convertTags(msg))
            self.mainwindow.chatlog.log(self.title(), msg)
        self.newmessage = False
        self.history = PesterHistory()
예제 #24
0
 def myUpdateMood(self, mood):
     chum = self.mainwindow.profile()
     syscolor = QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"])
     msg = chum.moodmsg(mood, syscolor, self.mainwindow.theme)
     self.textArea.append(convertTags(msg))
     self.mainwindow.chatlog.log(self.title(), msg)
예제 #25
0
    def __init__(self, chum, initiated, mainwindow, parent=None):
        super(PesterConvo, self).__init__(parent)
        self.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
        self.setObjectName(chum.handle)
        self.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.chum = chum
        self.mainwindow = mainwindow
        theme = self.mainwindow.theme
        self.resize(*theme["convo/size"])
        self.setStyleSheet("QFrame#%s { %s }" %
                           (chum.handle, theme["convo/style"]))
        self.setWindowIcon(self.icon())
        self.setWindowTitle(self.title())

        t = Template(self.mainwindow.theme["convo/chumlabel/text"])

        self.chumLabel = QtGui.QLabel(t.safe_substitute(handle=chum.handle),
                                      self)
        self.chumLabel.setStyleSheet(
            self.mainwindow.theme["convo/chumlabel/style"])
        self.chumLabel.setAlignment(
            self.aligndict["h"][
                self.mainwindow.theme["convo/chumlabel/align/h"]]
            | self.aligndict["v"][
                self.mainwindow.theme["convo/chumlabel/align/v"]])
        self.chumLabel.setMaximumHeight(
            self.mainwindow.theme["convo/chumlabel/maxheight"])
        self.chumLabel.setMinimumHeight(
            self.mainwindow.theme["convo/chumlabel/minheight"])
        self.chumLabel.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
                              QtGui.QSizePolicy.MinimumExpanding))
        self.textArea = PesterText(self.mainwindow.theme, self)
        self.textInput = PesterInput(self.mainwindow.theme, self)
        self.textInput.setFocus()

        self.connect(self.textInput, QtCore.SIGNAL('returnPressed()'), self,
                     QtCore.SLOT('sentMessage()'))

        self.layout = QtGui.QVBoxLayout()
        self.layout.addWidget(self.chumLabel)
        self.layout.addWidget(self.textArea)
        self.layout.addWidget(self.textInput)
        self.layout.setSpacing(0)
        margins = self.mainwindow.theme["convo/margins"]
        self.layout.setContentsMargins(margins["left"], margins["top"],
                                       margins["right"], margins["bottom"])

        self.setLayout(self.layout)

        self.optionsMenu = QtGui.QMenu(self)
        self.optionsMenu.setStyleSheet(
            self.mainwindow.theme["main/defaultwindow/style"])
        self.addChumAction = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/addchum"], self)
        self.connect(self.addChumAction, QtCore.SIGNAL('triggered()'), self,
                     QtCore.SLOT('addThisChum()'))
        self.blockAction = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/blockchum"], self)
        self.connect(self.blockAction, QtCore.SIGNAL('triggered()'), self,
                     QtCore.SLOT('blockThisChum()'))
        self.quirksOff = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/quirksoff"], self)
        self.quirksOff.setCheckable(True)
        self.connect(self.quirksOff, QtCore.SIGNAL('toggled(bool)'), self,
                     QtCore.SLOT('toggleQuirks(bool)'))
        self.oocToggle = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/ooc"], self)
        self.oocToggle.setCheckable(True)
        self.connect(self.oocToggle, QtCore.SIGNAL('toggled(bool)'), self,
                     QtCore.SLOT('toggleOOC(bool)'))
        self.unblockchum = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/unblockchum"],
            self)
        self.connect(self.unblockchum, QtCore.SIGNAL('triggered()'), self,
                     QtCore.SLOT('unblockChumSlot()'))
        self.reportchum = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/report"], self)
        self.connect(self.reportchum, QtCore.SIGNAL('triggered()'), self,
                     QtCore.SLOT('reportThisChum()'))
        self.logchum = QtGui.QAction(
            self.mainwindow.theme["main/menus/rclickchumlist/viewlog"], self)
        self.connect(self.logchum, QtCore.SIGNAL('triggered()'), self,
                     QtCore.SLOT('openChumLogs()'))

        # For this, we'll want to use setChecked to toggle these so they match
        # the user's setting. Alternately (better), use a tristate checkbox, so
        # that they start semi-checked?
        # Easiest solution: Implement a 'Mute' option that overrides all
        # notifications for that window, save for mentions.
        # TODO: Look into setting up theme support here.
        self._beepToggle = QtGui.QAction("Beep on Message", self)
        self._beepToggle.setCheckable(True)
        self.connect(self._beepToggle, QtCore.SIGNAL('toggled(bool)'), self,
                     QtCore.SLOT('toggleBeep(bool)'))

        self._flashToggle = QtGui.QAction("Flash on Message", self)
        self._flashToggle.setCheckable(True)
        self.connect(self._flashToggle, QtCore.SIGNAL('toggled(bool)'), self,
                     QtCore.SLOT('toggleFlash(bool)'))

        self._muteToggle = QtGui.QAction("Mute Notifications", self)
        self._muteToggle.setCheckable(True)
        self.connect(self._muteToggle, QtCore.SIGNAL('toggled(bool)'), self,
                     QtCore.SLOT('toggleMute(bool)'))

        self.optionsMenu.addAction(self.quirksOff)
        self.optionsMenu.addAction(self.oocToggle)

        self.optionsMenu.addAction(self._beepToggle)
        self.optionsMenu.addAction(self._flashToggle)
        self.optionsMenu.addAction(self._muteToggle)

        self.optionsMenu.addAction(self.logchum)
        self.optionsMenu.addAction(self.addChumAction)
        self.optionsMenu.addAction(self.blockAction)
        self.optionsMenu.addAction(self.reportchum)

        self.chumopen = False
        self.applyquirks = True
        self.ooc = False

        self.always_beep = False
        self.always_flash = False
        self.notifications_muted = False

        if parent:
            parent.addChat(self)
        if initiated:
            msg = self.mainwindow.profile().pestermsg(
                self.chum,
                QtGui.QColor(self.mainwindow.theme["convo/systemMsgColor"]),
                self.mainwindow.theme["convo/text/beganpester"])
            self.setChumOpen(True)
            self.textArea.append(convertTags(msg))
            self.mainwindow.chatlog.log(self.title(), msg)
        self.newmessage = False
        self.history = PesterHistory()
예제 #26
0
    def addMessage(self, lexmsg, chum):
        if len(lexmsg) == 0:
            return
        color = chum.colorcmd()
        systemColor = QtGui.QColor(
            self.parent().mainwindow.theme["convo/systemMsgColor"])
        initials = chum.initials()
        parent = self.parent()
        window = parent.mainwindow
        me = window.profile()
        if self.mainwindow.config.animations():
            for m in self.urls:
                if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
                    if m.state() == QtGui.QMovie.NotRunning:
                        m.start()
        if self.parent().mainwindow.config.showTimeStamps():
            if self.parent().mainwindow.config.time12Format():
                time = strftime("[%I:%M")
            else:
                time = strftime("[%H:%M")
            if self.parent().mainwindow.config.showSeconds():
                time += strftime(":%S] ")
            else:
                time += "] "
        else:
            time = ""
        if lexmsg[0] == "PESTERCHUM:BEGIN":
            parent.setChumOpen(True)
            pmsg = chum.pestermsg(me, systemColor,
                                  window.theme["convo/text/beganpester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:CEASE":
            parent.setChumOpen(False)
            pmsg = chum.pestermsg(me, systemColor,
                                  window.theme["convo/text/ceasepester"])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCK":
            pmsg = chum.pestermsg(me, systemColor,
                                  window.theme['convo/text/blocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:UNBLOCK":
            pmsg = chum.pestermsg(me, systemColor,
                                  window.theme['convo/text/unblocked'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:BLOCKED":
            pmsg = chum.pestermsg(me, systemColor,
                                  window.theme['convo/text/blockedmsg'])
            window.chatlog.log(chum.handle, pmsg)
            self.append(convertTags(pmsg))
        elif lexmsg[0] == "PESTERCHUM:IDLE":
            imsg = chum.idlemsg(systemColor, window.theme['convo/text/idle'])
            window.chatlog.log(chum.handle, imsg)
            self.append(convertTags(imsg))
        elif type(lexmsg[0]) is mecmd:
            memsg = chum.memsg(systemColor, lexmsg)
            if chum is me:
                window.chatlog.log(parent.chum.handle, memsg)
            else:
                window.chatlog.log(chum.handle, memsg)
            self.append(time + convertTags(memsg))
        else:
            if not parent.chumopen and chum is not me:
                beginmsg = chum.pestermsg(
                    me, systemColor, window.theme["convo/text/beganpester"])
                parent.setChumOpen(True)
                window.chatlog.log(chum.handle, beginmsg)
                self.append(convertTags(beginmsg))

            lexmsg[0:0] = [
                colorBegin("<c=%s>" % (color), color),
                "%s: " % (initials)
            ]
            lexmsg.append(colorEnd("</c>"))
            self.append("<span style=\"color:#000000\">" + time +
                        convertTags(lexmsg) + "</span>")
            #self.append('<img src="/Users/lexi/pesterchum-lex/smilies/tab.gif" />'
            #            + '<img src="/Users/lexi/pesterchum/smilies/tab.gif" />'
            #            + '<img src="/Applications/Pesterchum.app/Contents/Resources/smilies/tab.gif" />'
            #            + '<img src="smilies/tab.gif" />');
            if chum is me:
                window.chatlog.log(parent.chum.handle, lexmsg)
            else:
                if ((window.idler.auto or window.idler.manual)
                        and parent.chumopen and not parent.isBot(chum.handle)):
                    idlethreshhold = 60
                    if (not hasattr(self, 'lastmsg')) or \
                            datetime.now() - self.lastmsg > timedelta(0,idlethreshhold):
                        verb = window.theme["convo/text/idle"]
                        idlemsg = me.idlemsg(systemColor, verb)
                        parent.textArea.append(convertTags(idlemsg))
                        window.chatlog.log(chum.handle, idlemsg)
                        parent.messageSent.emit("PESTERCHUM:IDLE",
                                                parent.title())
                self.lastmsg = datetime.now()
                window.chatlog.log(chum.handle, lexmsg)