From ddd93d0e571edbe1a62f928436ea79818466e940 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 17:47:41 +0100 Subject: splited gui file, extended .hgignore --- module/gui/XMLParser.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 module/gui/XMLParser.py (limited to 'module/gui/XMLParser.py') diff --git a/module/gui/XMLParser.py b/module/gui/XMLParser.py new file mode 100644 index 000000000..0e3b4e59f --- /dev/null +++ b/module/gui/XMLParser.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay +""" + +from PyQt4.QtCore import * +from PyQt4.QtGui import * +from PyQt4.QtXml import * + +import os + +class XMLParser(): + def __init__(self, data, dfile=""): + self.mutex = QMutex() + self.mutex.lock() + self.xml = QDomDocument() + self.file = data + self.dfile = dfile + self.mutex.unlock() + self.loadData() + self.root = self.xml.documentElement() + + def loadData(self): + self.mutex.lock() + f = self.file + if not os.path.exists(f): + f = self.dfile + with open(f, 'r') as fh: + content = fh.read() + self.xml.setContent(content) + self.mutex.unlock() + + def saveData(self): + self.mutex.lock() + content = self.xml.toString() + with open(self.file, 'w') as fh: + fh.write(content) + self.mutex.unlock() + return content + + def parseNode(self, node, ret_type="list"): + if ret_type == "dict": + childNodes = {} + else: + childNodes = [] + child = node.firstChild() + while True: + n = child.toElement() + if n.isNull(): + break + else: + if ret_type == "dict": + childNodes[str(n.tagName())] = n + else: + childNodes.append(n) + child = child.nextSibling() + return childNodes -- cgit v1.2.3 From e17c410d4c0fcd6c9c59368e1472cdc524617dc1 Mon Sep 17 00:00:00 2001 From: mkaay Date: Thu, 17 Dec 2009 21:53:59 +0100 Subject: fixed with statement (python2.5) --- module/gui/XMLParser.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/gui/XMLParser.py') diff --git a/module/gui/XMLParser.py b/module/gui/XMLParser.py index 0e3b4e59f..5e3b7bf65 100644 --- a/module/gui/XMLParser.py +++ b/module/gui/XMLParser.py @@ -15,6 +15,7 @@ @author: mkaay """ +from __future__ import with_statement from PyQt4.QtCore import * from PyQt4.QtGui import * -- cgit v1.2.3