CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventContentView.py
Go to the documentation of this file.
1 import logging
2 
3 from PyQt4.QtGui import *
4 from PyQt4.QtCore import *
5 
6 from Vispa.Views.AbstractView import AbstractView
7 
8 class EventContentView(QTableWidget, AbstractView):
9  """ Holds a table to compare event contents.
10  """
11  def __init__(self, parent=None, name=None):
12  """ Constructor """
13  logging.debug(self.__class__.__name__ + ": __init__()")
14  AbstractView.__init__(self)
15  QTableWidget.__init__(self, parent)
16 
17  self._itemDict = {}
18 
19  self.setSelectionMode(QTableWidget.SingleSelection)
20  self.clear() # Sets headers
21 
22  def clear(self):
23  self._itemDict = {}
24  QTableWidget.clear(self)
25  self.setColumnCount(1)
26  self.setHorizontalHeaderLabels(['no file selected'])
27  self.horizontalHeaderItem(0).setTextAlignment(Qt.AlignLeft)
28  self.verticalHeader().hide()
29  self._rows = 0
30  self.setRowCount(self._rows)
31 
32  def _addRow(self, names, items):
33  """ Adds a row to the EventContentView.
34  """
35  self._rows += 1
36  i=0
37  for name in names:
38  item = LabelItem(name)
39  self.setItem(self._rows - 1, i, item)
40  i+=1
41  for entry, color in items:
42  item = LabelItem(entry, color)
43  self.setItem(self._rows - 1, i, item)
44  if i == 4:
45  self._itemDict[str(self._rows)] = item
46  item.object = name
47  i += 1
48 
49  def updateContent(self):
50  """ Fill the EventContentView using the ContentsDict.
51  """
52  logging.debug('EventContentView: updateContent()')
53  self._eventContentsList = self.dataAccessor().eventContentsList()
54  self.clear()
55  self.setSortingEnabled(False)
56  names = ["Type","Label","Product","Process"]
57  allContent = []
58  for name, content, relative, comment in self._eventContentsList:
59  names += [name]
60  for entry in content:
61  if not self.dataAccessor().inContent(entry,allContent):
62  allContent += [entry]
63  allContent.sort(lambda x, y: cmp(self.dataAccessor().label(x).lower(), self.dataAccessor().label(y).lower()))
64  self.setColumnCount(len(names))
65  self.setHorizontalHeaderLabels(names)
66  for i in range(len(names)):
67  self.horizontalHeaderItem(i).setTextAlignment(Qt.AlignLeft)
68  self.setRowCount(len(allContent))
69  for entry in allContent:
70  items = []
71  column_before=None
72  for name, content, relative, comment in self._eventContentsList:
73  this_column=self.dataAccessor().inContent(entry,content)
74  if this_column:
75  text="Yes"
76  else:
77  text="No"
78  if "_".join(entry) in comment.keys():
79  text+=" ("+comment["_".join(entry)]+")"
80  #if relative:
81  color=Qt.white
82  #else:
83  # color=Qt.gray
84  input="Input: " in name
85  output="Output: " in name
86  if column_before!=None:
87  rel=0
88  if this_column and not column_before:
89  rel=1
90  if not this_column and column_before:
91  rel=-1
92  if input:
93  if rel>0:
94  color=Qt.red
95  elif output:
96  if rel>0:
97  color=Qt.green
98  else:
99  if rel<0:
100  color=Qt.red
101  if rel>0:
102  color=Qt.green
103  if not input:
104  column_before=this_column
105  items += [(text, color)]
106  self._addRow(entry,items)
107  self.sortItems(1)
108  self.setSortingEnabled(True)
109  return True
110 
111  def select(self, item):
112  """ Mark an item in the TableView as selected.
113  """
114  if item != None:
115  self.setCurrentItem(item)
116 
117  def itemByObject(self, object):
118  """ Return an item in the TableView with a certain object.
119  """
120  items = []
121  for positionName, item in self._itemDict.items():
122  if item.object == self.dataAccessor().label(object):
123  items += [(positionName, item)]
124  if len(items) > 0:
125  return sorted(items)[0][1]
126  else:
127  return None
128 
129 class LabelItem(QTableWidgetItem):
130  """ A QTableWidgetItem with a convenient constructor.
131  """
132  def __init__(self, argument, color=Qt.white):
133  tooltip = argument
134  name = argument
135  QTableWidgetItem.__init__(self, name)
136  self.setToolTip(tooltip)
137  self.setFlags(Qt.ItemIsEnabled)
138  self.setBackgroundColor(color)
const std::string & label
Definition: MVAComputer.cc:186
static std::string join(char **cmd)
Definition: RemoteFile.cc:18