CMS 3D CMS Logo

CodeTableView.py
Go to the documentation of this file.
1 import logging
2 
3 from PyQt4.QtGui import QToolButton
4 from PyQt4.QtCore import Qt,SIGNAL
5 
6 from Vispa.Share.BasicDataAccessor import BasicDataAccessor
7 from Vispa.Views.TableView import TableView
8 
10  """ Table view that lists python configuration code.
11  """
12 
13  LABEL = "Python configuration code"
14 
15  def __init__(self, parent=None):
16  logging.debug(__name__ + ": __init__")
17  TableView.__init__(self,parent)
18  self.setColumns(["Buttons","code"])
19  self.horizontalHeader().hide()
20  self.setSorting(False)
21  self._firstColumn=1
22 
23  self.connect(self, SIGNAL("itemClicked(QTableWidgetItem*)"), self.itemClicked)
24 
25  def _createItem(self, object, properties):
26  """ Create item for an object.
27  """
28  TableView._createItem(self, object, properties)
29  button=QToolButton()
30  button.object=object
31  if self.dataAccessor().label(object)=="Import":
32  button.setText("...")
33  self.connect(button, SIGNAL('clicked(bool)'), self.importButtonClicked)
34  elif self.dataAccessor().label(object)=="Apply tool":
35  button.setText("+")
36  self.connect(button, SIGNAL('clicked(bool)'), self.applyButtonClicked)
37  else:
38  button.setText("X")
39  self.connect(button, SIGNAL('clicked(bool)'), self.removeButtonClicked)
40  self.setCellWidget(self.rowCount()-1, 0, button)
41 
42  def importButtonClicked(self,checked=False):
43  self.emit(SIGNAL("importButtonClicked"),self.sender().object)
44 
45  def applyButtonClicked(self,checked=False):
46  self.emit(SIGNAL("applyButtonClicked"),self.sender().object)
47 
48  def removeButtonClicked(self,checked=False):
49  self.emit(SIGNAL("removeButtonClicked"),self.sender().object)
50 
51  def updateContent(self):
52  result=TableView.updateContent(self)
53  self.horizontalHeader().resizeSection(0,self.cellWidget(0,0).sizeHint().width())
54  return result
55 
56  def keyPressEvent(self,event):
57  TableView.keyPressEvent(self,event)
58  if event.key() in [Qt.Key_Backspace,Qt.Key_Delete]:
59  self.emit(SIGNAL("removeButtonClicked"),self.selection())
60 
61  def itemClicked(self,item):
62  logging.debug(__name__ + ": itemClicked")
63  if not self._updatingFlag:
64  self.setCurrentCell(self.currentRow(),0)
def setColumns(self, columns)
Definition: TableView.py:50
char const * label
def setSorting(self, sort)
Definition: TableView.py:47