4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
6 from PyQt4.QtXml import *
8 from sface.xmlwidget import *
9 from sface.config import config
10 from sface.screens.sfascreen import SfaScreen
13 class RSpecView(XmlView):
14 def __init__(self, parent):
15 XmlView.__init__(self, parent)
17 def expandMatchingText(self, txt):
24 def recursiveExpand(index):
25 parent = index.parent()
26 if parent and parent.isValid():
27 recursiveExpand(parent)
31 print index.data().toString()
32 if index.data().toString() == txt:
33 recursiveExpand(index)
34 self.scrollTo(index, self.PositionAtCenter)
37 rows = model.rowCount(index)
39 child_index = index.child(r, 0)
42 root_rows = model.rowCount()
43 for r in range(root_rows):
44 index = model.index(r, 0)
47 class RSpecWindow(QDialog):
48 def __init__(self, parent=None):
49 QDialog.__init__(self, parent)
51 self.title = 'RSpec Window'
52 self.setWindowTitle(self.title)
57 self.view = RSpecView(self)
59 layout = QVBoxLayout()
60 layout.addWidget(self.view)
61 self.setLayout(layout)
63 print 'CHILDREN', str(self.children())
66 def showNode(self, hostname):
68 self.view.expandMatchingText(hostname)
77 self.document = QDomDocument(self.title)
79 rspec_file = config.getSliceRSpecFile()
80 if not os.path.exists(rspec_file):
83 self.document.setContent(open(rspec_file,'r').read())
84 # DomModel.__init__ is gonna purge the doc
85 # from the "xml bla bla bla" node.
86 # so the arg 'document' needs to be not None
88 self.model = DomModel(self.document, self)
90 self.view.setModel(self.model)
91 self.view.expand(self.model.index(0, 0)) #expand first level only