class OsaResultsWidget qgui QFrame def __init__ self parent None resul

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class OsaResultsWidget(qgui.QFrame):
def __init__(self, parent=None, results_count=3):
super(OsaResultsWidget, self).__init__(parent)
self.setMinimumSize(qcore.QSize(320,300))
self.results_count = results_count
self.widgets = [PolicyWidget() for _ in xrange(self.results_count)]
self.makeLayout()
def makeLayout(self):
self.setAutoFillBackground(True)
vbox = qgui.QVBoxLayout(self)
for widget in self.widgets:
vbox.addWidget(widget)
spacer = qgui.QSpacerItem(20,40, qgui.QSizePolicy.Minimum, qgui.QSizePolicy.Expanding)
def showResults(self, policies):
if len(policies) > self.results_count:
policies = policies[:self.results_count]
else:
policies = policies + [None for _ in xrange(self.results_count - len(policies))]
for policy, widget in zip(policies, self.widgets):
widget.renderPolicy(policy)
if __name__ == "__main__":
import sys
from osa import search
app = qgui.QApplication(sys.argv)
widget = OsaResultsWidget(results_count=6)
widget.showResults(search.search())
widget.show()
sys.exit(app.exec_())