Ejemplo n.º 1
0
    def loadTheme(self, path):
        loadedTheme = self

        import xml.dom.minidom, os.path, sys, XmlHelper
        xmlDoc=xml.dom.minidom.parse(os.path.abspath(os.path.dirname(sys.argv[0])) + path)
        
        #Get the name of the theme
        nameTag=xmlDoc.getElementsByTagName("name")[0]
        nameTagText=XmlHelper.getText(nameTag.childNodes)
        loadedTheme.name = nameTagText
        
        #Get all the REPLACE Tags
        replaceTags=xmlDoc.getElementsByTagName("replace")
        for replaceTag in replaceTags:
            key = XmlHelper.getAttribute(replaceTag.attributes,"key")
            text = XmlHelper.getAttribute(replaceTag.attributes,"text")
            loadedTheme.replaces.append(dict({"key": self.replaceEscapes(key), "text": self.replaceEscapes(text)}))
            
        #Get the STYLE Tags
        styleTags=xmlDoc.getElementsByTagName("style")
        for styleTag in styleTags:
            name = XmlHelper.getAttribute(styleTag.attributes,"name")
            insert = XmlHelper.getAttribute(styleTag.attributes,"insert")
            ifStatmnt = XmlHelper.getAttribute(styleTag.attributes,"if")
            
            
            loadedTheme.styles.append(dict({'name': self.replaceEscapes(name), "insert": self.replaceEscapes(insert), "if": self.replaceEscapes(ifStatmnt)}))
        return loadedTheme
Ejemplo n.º 2
0
def changeTheme(name):
    #Get this themes('name') path
    import os, xml.dom.minidom, os.path, sys, XmlHelper
    path=""
    for f in os.listdir("../themes"):
        if f.endswith(".xml"):
            themeXmlDoc=xml.dom.minidom.parse("../themes/" + f)
            nameElement = themeXmlDoc.getElementsByTagName("name")[0]
            tName = XmlHelper.getText(nameElement.childNodes)
            if tName.lower() == name.lower():
                path =  "/themes/" + f

    if path == "": return ""


    #Parse the settings.xml file...os.path.abspath(os.path.dirname(sys.argv[0])) get's the scripts directory
    xmlDoc=xml.dom.minidom.parse(os.path.abspath(os.path.dirname(sys.argv[0])) + "/settings.xml")
    try:
        themeElement = xmlDoc.getElementsByTagName("theme")[0]
    except:
        pDebug("theme element was not found in settings.xml, creating one.")
        themeElement = xmlDoc.createElement("theme")
        themeElement.setAttribute("name", name)
        themeElement.setAttribute("path", path)
        xmlDoc.documentElement.appendChild(themeElement)
        
        f = open(os.path.abspath(os.path.dirname(sys.argv[0])) + "/settings.xml","w").write(xmlDoc.toxml())
        return True

    themeElement.setAttribute("name", name)
    themeElement.setAttribute("path", path)
    f = open(os.path.abspath(os.path.dirname(sys.argv[0])) + "/settings.xml","w").write(xmlDoc.toxml())
    return True
Ejemplo n.º 3
0
def loadSettings():
    loadedSettings=settings()
    import xml.dom.minidom, os.path, sys, XmlHelper
    #Parse the settings.xml file...os.path.abspath(os.path.dirname(sys.argv[0])) get's the scripts directory
    xmlDoc=xml.dom.minidom.parse(os.path.abspath(os.path.dirname(sys.argv[0])) + "/settings/settings.xml")
    """1.Get the nicks:"""
    #""1a.Get the nicks tag, and use getText() to get the TEXT_NODE of the nicks tag
    nicksTag=xmlDoc.getElementsByTagName("nicks")[0]
    nicksTagText=XmlHelper.getText(nicksTag.childNodes)
    #""1b.Split it into space( ) and add it to settings.nicks[]
    for i in nicksTagText.split(" "): loadedSettings.nicks.append(i);
    """2.Get the username"""
    usernameTag=xmlDoc.getElementsByTagName("username")[0]
    usernameTagText=XmlHelper.getText(usernameTag.childNodes)
    loadedSettings.username=usernameTagText
    """3.Get the realname"""
    realnameTag=xmlDoc.getElementsByTagName("realname")[0]
    realnameTagText=XmlHelper.getText(usernameTag.childNodes)
    loadedSettings.realname=realnameTagText

    """4.Get the chatTextView colors"""
    chatColorsTag=xmlDoc.getElementsByTagName("chatColors")
    for colorTag in chatColorsTag[0].childNodes:
        if colorTag.nodeType == colorTag.ELEMENT_NODE:
            name = XmlHelper.getAttribute(colorTag.attributes,"name")
            r = int(XmlHelper.getAttribute(colorTag.attributes,"red"))
            g = int(XmlHelper.getAttribute(colorTag.attributes,"green"))
            b = int(XmlHelper.getAttribute(colorTag.attributes,"blue"))

            sColor = gtk.gdk.Color(red=r * 257,green=g * 257,blue=b * 257,pixel=0)
            setChatColorVar(loadedSettings,name,sColor)

    """5.Get the treeviews Colors"""
    treeColorsTag=xmlDoc.getElementsByTagName("treeviewColors")
    for colorTag in treeColorsTag[0].childNodes:
        if colorTag.nodeType == colorTag.ELEMENT_NODE:
            name = XmlHelper.getAttribute(colorTag.attributes,"name")
            r = int(XmlHelper.getAttribute(colorTag.attributes,"red"))
            g = int(XmlHelper.getAttribute(colorTag.attributes,"green"))
            b = int(XmlHelper.getAttribute(colorTag.attributes,"blue"))

            sColor = gtk.gdk.Color(red=r * 257,green=g * 257,blue=b * 257,pixel=0)
            setTreeColorVar(loadedSettings,name,sColor)
    """6.Get the server"""
    serversTag=xmlDoc.getElementsByTagName("servers")[0]
    for serverTag in serversTag.childNodes:
        if serverTag.nodeType == serverTag.ELEMENT_NODE:
            if serverTag.nodeName == "server":
                nServer = sServer()
                nServer.cName = XmlHelper.getAttribute(serverTag.attributes,"name") #Name of the server
                nServer.autoconnect = makeBool(XmlHelper.getAttribute(serverTag.attributes,"autoconnect")) #Determines whether to connect to this server when Nyx starts
                nServer.addresses = [] #Addresses for this server(If the first server is unavailable, Nyx tries connecting to the enxt one)
                #Get the addresses to connect to.
                for addressTag in serverTag.childNodes:
                    if addressTag.nodeType == addressTag.ELEMENT_NODE:
                        #address()
                        address = sServer()
                        address.cAddress = XmlHelper.getText(addressTag.childNodes)
                        address.cPort = int(XmlHelper.getAttribute(addressTag.attributes,"port"))
                        address.cSsl = makeBool(XmlHelper.getAttribute(addressTag.attributes,"ssl"))
                        address.cPass = XmlHelper.getAttribute(addressTag.attributes,"pass")
                        nServer.addresses.append(address)
                loadedSettings.servers.append(nServer)
                
    #Get the themePath
    themeTag=xmlDoc.getElementsByTagName("theme")[0]
    loadedSettings.themePath = XmlHelper.getAttribute(themeTag.attributes,"path")
                
                
    return loadedSettings