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 # voodoo alert: baris was using index.data()
31 # and apparently it worked. But after me
32 # messing around, only index.model().data(index)
33 # seems to give non-empty QVariant as output.
34 if index.model().data(index).toString() == txt:
35 recursiveExpand(index)
36 self.scrollTo(index, self.PositionAtCenter)
39 rows = model.rowCount(index)
41 child_index = index.child(r, 0)
44 root_rows = model.rowCount()
45 for r in range(root_rows):
46 index = model.index(r, 0)
49 class RSpecWindow(QDialog):
50 def __init__(self, parent=None):
51 QDialog.__init__(self, parent)
53 self.title = 'RSpec Window'
54 self.setWindowTitle(self.title)
59 self.view = RSpecView(self)
61 layout = QVBoxLayout()
62 layout.addWidget(self.view)
63 self.setLayout(layout)
67 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