From: Barış Metin Date: Fri, 10 Sep 2010 17:08:27 +0000 (+0200) Subject: implement itemdelegate to colorize selected nodes X-Git-Tag: sface-0.1-1~64 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=a8f5d8a8a1fc3baf55c85d8af3243944a2dca26c;hp=a276ef99d41c4bf3fedf1f2a4e1729666b6f3e4d implement itemdelegate to colorize selected nodes --- diff --git a/sface.bin b/sface.bin index 44fa432..abc484c 100755 --- a/sface.bin +++ b/sface.bin @@ -3,7 +3,7 @@ #export PATH=$HOME/stree/sfa//trunk/:$PATH PYTHONPATH=/opt/local/lib/python2.5/site-packages/ -PYTHONPATH=/opt/local//Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/:$PYTHONPATH +PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/:$PYTHONPATH PYTHONPATH=$HOME/stree/sfa/trunk:$PYTHONPATH export PYTHONPATH diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py index 4b636bc..32d9849 100644 --- a/sface/screens/mainscreen.py +++ b/sface/screens/mainscreen.py @@ -19,6 +19,29 @@ class NodeView(QTreeView): self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setAttribute(Qt.WA_MacShowFocusRect, 0) +class ItemDelegate(QStyledItemDelegate): + def __init__(self, parent): + QStyledItemDelegate.__init__(self) + + def paint(self, painter, option, index): + data = "%s" % index.data().toString() + + if data.startswith("*"): # already in the sliver + data = " %s " % data[1:] + + rect = option.rect + fm = QFontMetrics(option.font) + w = fm.width(QString(data)) + rect.setWidth(w) + + painter.save() + painter.fillRect(rect, QColor.fromRgb(0, 250, 0)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + painter.restore() + else: # others, fall back to default view + QStyledItemDelegate.paint(self, painter, option, index) + class TreeItem: def __init__(self, data, parent=None): self.parentItem = parent @@ -214,11 +237,11 @@ class SliceWidget(QWidget): available_nodes = filter(lambda x:x not in sliver_nodes, all_nodes) for node in sliver_nodes: - nodeItem = TreeItem([QString(""), QString(node), QString("True")], networkItem) + nodeItem = TreeItem([QString(""), QString("*%s" % node), QString("Implement Checkbox")], networkItem) networkItem.appendChild(nodeItem) for node in available_nodes: - nodeItem = TreeItem([QString(""), QString(node), QString("False")], networkItem) + nodeItem = TreeItem([QString(""), QString(node), QString("Implement Checkbox")], networkItem) networkItem.appendChild(nodeItem) self.nodeModel.rootItem.appendChild(networkItem) @@ -226,6 +249,9 @@ class SliceWidget(QWidget): self.nodeView.expandAll() self.nodeView.resizeColumnToContents(1) + self.delegate = ItemDelegate(self) + self.nodeView.setItemDelegateForColumn(1, self.delegate) + class MainScreen(SfaScreen): def __init__(self, parent):