import os import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtXml import * from sface.xmlwidget import * from sface.config import config from sface.screens.sfascreen import SfaScreen class RSpecView(XmlView): def __init__(self, parent): XmlView.__init__(self, parent) def expandMatchingText(self, txt): self.collapseAll() self.expandToDepth(0) model = self.model() def recursiveExpand(index): parent = index.parent() if parent and parent.isValid(): recursiveExpand(parent) self.expand(index) def search(index): if index.data().toString() == txt: recursiveExpand(index) self.scrollTo(index, self.PositionAtCenter) return rows = model.rowCount(index) for r in range(rows): child_index = index.child(r, 0) search(child_index) root_rows = model.rowCount() for r in range(root_rows): index = model.index(r, 0) search(index) class RSpecWindow(QDialog): def __init__(self, parent=None): QDialog.__init__(self, parent) self.title = 'RSpec Window' self.setWindowTitle(self.title) self.document = None self.model = None self.view = RSpecView(self) layout = QVBoxLayout() layout.addWidget(self.view) self.setLayout(layout) print 'CHILDREN', str(self.children()) self.updateView() def showNode(self, hostname): self.view.expandMatchingText(hostname) def updateView(self): del self.document del self.model self.document = None self.model = None self.document = QDomDocument(self.title) rspec_file = config.getSliceRSpecFile() if not os.path.exists(rspec_file): return self.document.setContent(open(rspec_file,'r').read()) # DomModel.__init__ is gonna purge the doc # from the "xml bla bla bla" node. # so the arg 'document' needs to be not None # for this to happen self.model = DomModel(self.document, self) self.view.setModel(self.model) self.view.expand(self.model.index(0, 0)) #expand first level only