from sface.config import config
from sface.screens.sfascreen import SfaScreen
+def QVarMapAccess(qv, key):
+ # helper function. qv is a dict wrapped into a QVariant
+ print 10*'='
+ print "DICT:", qv.toMap()
+ if len(qv.toMap().keys()) == 0:
+ print "EMPTY!"
+ import traceback
+ traceback.print_stack()
+ return None
+ else:
+ return qv.toMap()[QString(key)].toString()
+
+
class DomModel(QAbstractItemModel):
def __init__(self, document, parent = 0):
QAbstractItemModel.__init__(self, parent)
elem = ' %s="%s"' % (attr.nodeName(), attr.nodeValue())
qslist.append(elem)
ElemNameAndAtts = '%s%s'% (node.nodeName(), qslist.join(' '))
+ print "1"
return QVariant(
- {QString('nodeType'):QVariant(QString('element')),
- QString('content'):ElemNameAndAtts})
+ {'nodeType':QVariant(QString('element')),
+ 'content':ElemNameAndAtts})
elif node.nodeType() == QDomNode.AttributeNode:
+ print "2"
return QVariant()
elif node.nodeType() == QDomNode.TextNode:
+ print "3"
return QVariant(
- {QString('nodeType'):QVariant(QString('text')),
- QString('content'):node.nodeValue()})
+ {'nodeType':QVariant(QString('text')),
+ 'content':node.nodeValue()})
elif node.nodeType() == QDomNode.CDATASectionNode:
+ print "4"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.EntityReferenceNode:
+ print "5"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.EntityNode:
+ print "6"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.ProcessingInstructionNode:
+ print "7"
return QVariant()
elif node.nodeType() == QDomNode.CommentNode:
+ print "8"
return QVariant(
- {QString('nodeType'):QVariant(QString('comment')),
- QString('content'):node.nodeValue()})
+ {'nodeType':QVariant(QString('comment')),
+ 'content':node.nodeValue()})
elif node.nodeType() == QDomNode.DocumentNode:
+ print "9"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.DocumentTypeNode:
+ print "10"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.DocumentFragmentNode:
+ print "12"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.NotationNode:
+ print "13"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.BaseNode:
+ print "14"
return QString('unsupported node type')
elif node.nodeType() == QDomNode.CharacterDataNode:
+ print "15"
return QString('unsupported node type')
else:
+ print "16"
return QVariant()
else:
+ print "17"
return QVariant()
def flags(self, index):
del self.delegates[nodeType]
def paint(self, painter, option, index):
- QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString()
+ print "ASKING FOR DATA"
dataAsQVarMap = index.model().data(index)
+ print "GOT DATA"
nodeType = str(QVarMapAccess(dataAsQVarMap, 'nodeType'))
delegate = self.delegates.get(nodeType)
- print "WTF IS THIS TYPE:", type(index.model().data(index))
- print "NODE TYPE:", nodeType
#print "DELEGS DICT:", self.delegates
#print "NODETYPE:", nodeType.toString()
if delegate is not None:
else:
#print "ELSE BRANCH"
# not sure this will ever work. this delegate
- # doesn't know about my QObject strategy.
+ # doesn't know about my QMap strategy.
QItemDelegate.paint(self, painter, option, index)
# def sizeHint(self, option, index):
return html
def colorize(color, text):
return '<font color=' + color + '>' + text + '</font>'
- QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString()
dataAsQVarMap = index.model().data(index)
text = str(QVarMapAccess(dataAsQVarMap, 'content'))
if option.state & QStyle.State_Selected:
return '<pre>' + text + '</pre'
def colorize(color, text):
return '<font color=' + color + '>' + text + '</font>'
- QVarMapAccess = lambda qv, key: qv.toMap()[QString(key)].toString()
dataAsQVarMap = index.model().data(index)
text = str(QVarMapAccess(dataAsQVarMap, 'content'))
if option.state & QStyle.State_Selected: