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):
23 def recursiveExpand(index):
24 parent = index.parent()
25 if parent and parent.isValid():
26 recursiveExpand(parent)
30 if index.data().toString() == txt:
31 recursiveExpand(index)
32 self.scrollTo(index, self.PositionAtCenter)
35 rows = model.rowCount(index)
37 child_index = index.child(r, 0)
40 root_rows = model.rowCount()
41 for r in range(root_rows):
42 index = model.index(r, 0)
45 class RSpecWindow(QDialog):
46 def __init__(self, parent=None):
47 QDialog.__init__(self, parent)
49 self.title = 'RSpec Window'
50 self.setWindowTitle(self.title)
55 self.view = RSpecView(self)
57 layout = QVBoxLayout()
58 layout.addWidget(self.view)
59 self.setLayout(layout)
61 print 'CHILDREN', str(self.children())
64 def showNode(self, hostname):
65 self.view.expandMatchingText(hostname)
74 self.document = QDomDocument(self.title)
76 rspec_file = config.getSliceRSpecFile()
77 if not os.path.exists(rspec_file):
80 self.document.setContent(open(rspec_file,'r').read())
81 # DomModel.__init__ is gonna purge the doc
82 # from the "xml bla bla bla" node.
83 # so the arg 'document' needs to be not None
85 self.model = DomModel(self.document, self)
87 self.view.setModel(self.model)
88 self.view.expand(self.model.index(0, 0)) #expand first level only