CMS 3D CMS Logo

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