Esempio n. 1
0
    def onTextMessageEvent(self, schid, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored):
        if self.status:
            (error, myid) = ts3.getClientID(schid)
            
            # get plain url from bbcode url
            # https://github.com/DerLuemmel/pyTSon_ts3_linkinfo/blob/master/__init__.py
            message = message.lower()
            if not myid == fromID and ("[url]" in message or "[url=" in message):
                start = message.find("[url]")
                if not start == -1:                   
                    end = message.find("[/url]")
                    message = message[start + 5:end]
                else:
                    start = message.find("[url=")
                    end = message.find("]")
                    message = message[start + 5:end]

                # Open stream and read content type
                stream = urllib.request.urlopen(message)
                contenttype = stream.info().get_content_type()                

                # if contenttype is png, gif, jpeg
                if contenttype in self.contenttypes:
                    
                    # get image data
                    data = stream.read()
                    
                    # label and pixmap
                    image = QLabel("image")   
                    pixmap = QPixmap()
                    
                    # load url data to pixmap
                    pixmap.loadFromData(data)      

                    # set max width to self.imageMaxHeight
                    pixmap = pixmap.scaledToHeight(self.imageMaxHeight, Qt.FastTransformation)
                    
                    # set image to label
                    image.setPixmap(pixmap)  
                    
                    # set margins for better looking
                    image.setStyleSheet("QLabel{margin: 10px;}")
                    
                    # Get chatlayout
                    chatlayout = self.getWidgetByObjectName("MainWindowChatWidget").layout()
                    
                    # Add image to chatlayout
                    chatlayout.addWidget(image)
                    
                    # Deletes image label after self.showTime
                    QTimer.singleShot(self.showTime, lambda : self.removeImage(chatlayout, image)) 
Esempio n. 2
0
    def flag(self, code):
        """
        Returns a QPixmap containing the flag of the given country code if
        exist.
        @param code: the country code
        @type code: str
        @returns: the flag
        @rtype: QPixmap
        """
        fname = "%s.png" % code.lower()
        if fname in self.zip.namelist():
            with self.zip.open(fname) as f:
                ret = QPixmap()
                if ret.loadFromData(f.read()):
                    return ret

        return QPixmap()
Esempio n. 3
0
    def flag(self, code):
        """
        Returns a QPixmap containing the flag of the given country code if
        exist.
        @param code: the country code
        @type code: str
        @returns: the flag
        @rtype: QPixmap
        """
        fname = "%s.png" % code.lower()
        if fname in self.zip.namelist():
            with self.zip.open(fname) as f:
                ret = QPixmap()
                if ret.loadFromData(f.read()):
                    return ret

        return QPixmap()
Esempio n. 4
0
    def emoticon(self, text):
        """
        Returns the icon replacing the emoticon string.
        @param text: the emoticon as string
        @type text: str
        @return: the resulting pixmap
        @rtype: QPixmap
        """
        if text in self.emos:
            empath = os.path.join("emoticons", self.emos[text])
            if self.zip:
                if empath in self.cont.namelist():
                    with self.cont.open(empath) as f:
                        ret = QPixmap()
                        if ret.loadFromData(f.read()):
                            return ret
            else:
                if os.path.isfile(os.path.join(self.path, empath)):
                    return QPixmap(os.path.join(self.path, empath))

        return QPixmap()
Esempio n. 5
0
    def emoticon(self, text):
        """
        Returns the icon replacing the emoticon string.
        @param text: the emoticon as string
        @type text: str
        @return: the resulting pixmap
        @rtype: QPixmap
        """
        if text in self.emos:
            empath = os.path.join("emoticons", self.emos[text])
            if self.zip:
                if empath in self.cont.namelist():
                    with self.cont.open(empath) as f:
                        ret = QPixmap()
                        if ret.loadFromData(f.read()):
                            return ret
            else:
                if os.path.isfile(os.path.join(self.path, empath)):
                    return QPixmap(os.path.join(self.path, empath))

        return QPixmap()
Esempio n. 6
0
    def icon(self, var):
        """
        Returns the icon representing a variable used in the iconpack.
        If the icon cannot be found, the iconpack's fallback mechanisms are
        used. If everything fails, an empty pixmap is returned.
        @param var: the variable name
        @type var: str
        @return: the resulting pixmap
        @rtype: QPixmap
        """
        if self.info == "default":
            path = self._findDefaultFilename(self.defaultName(var))
            if path == "":
                return QPixmap()
        else:
            if not self.settings.has_option("gfxfiles", var):
                return self.fallback(var)
            path = self.settings.get("gfxfiles", var)
            if path == "":
                return self.fallback(var)

        if self.zip:
            if path in self.cont.namelist():
                with self.cont.open(path) as f:
                    ret = QPixmap()
                    if ret.loadFromData(f.read()):
                        return ret
                    else:
                        return QPixmap()
            else:
                return self.fallback(var)
        else:
            if os.path.isfile(os.path.join(self.path, path)):
                return QPixmap(os.path.join(self.path, path))
            else:
                return self.fallback(var)
Esempio n. 7
0
    def icon(self, var):
        """
        Returns the icon representing a variable used in the iconpack.
        If the icon cannot be found, the iconpack's fallback mechanisms are
        used. If everything fails, an empty pixmap is returned.
        @param var: the variable name
        @type var: str
        @return: the resulting pixmap
        @rtype: QPixmap
        """
        if self.info == "default":
            path = self._findDefaultFilename(self.defaultName(var))
            if path == "":
                return QPixmap()
        else:
            if not self.settings.has_option("gfxfiles", var):
                return self.fallback(var)
            path = self.settings.get("gfxfiles", var)
            if path == "":
                return self.fallback(var)

        if self.zip:
            if path in self.cont.namelist():
                with self.cont.open(path) as f:
                    ret = QPixmap()
                    if ret.loadFromData(f.read()):
                        return ret
                    else:
                        return QPixmap()
            else:
                return self.fallback(var)
        else:
            if os.path.isfile(os.path.join(self.path, path)):
                return QPixmap(os.path.join(self.path, path))
            else:
                return self.fallback(var)