OpenStructure
Loading...
Searching...
No Matches
table.py
Go to the documentation of this file.
1from PyQt5.QtGui import *
2from PyQt5.QtCore import *
3
4from ost import table
5__all__=('Table', )
6
7class TableModel(QAbstractTableModel):
8 def __init__(self, table, parent=None):
9 QAbstractTableModel.__init__(self, parent)
10 self.table=table
11
12 def rowCount(self, index):
13 return len(self.table.rows)
14
15 def headerData(self, section, orientation, role):
16 if role!=Qt.DisplayRole or orientation!=Qt.Horizontal:
17 return QVariant()
18 return self.table.col_names[section]
19
20 def columnCount(self, index):
21 return len(self.table.col_names)
22
23 def sort(self, column, order):
24 o='+'
25 if order!=Qt.AscendingOrder:
26 o='-'
27 self.table.Sort(by=self.table.col_names[column], order=o)
28 self.reset()
29
30 def data(self, index, role):
31 if not index.isValid() or role!=Qt.DisplayRole:
32 return QVariant()
33 row=self.table.rows[index.row()]
34 return QVariant(row[index.column()])
35
36class Table(QTableView):
37 def __init__(self, table):
38 QTableView.__init__(self)
39 self._model=TableModel(table)
40 self.setFrameShape(QFrame.NoFrame)
41 self.setAttribute(Qt.WA_MacSmallSize)
42 self.setShowGrid(False)
43 self.double_click = None
44 self.horizontalHeader().setStretchLastSection(True)
45 self.setContextMenuPolicy(Qt.CustomContextMenu)
46 self.setSelectionBehavior(QAbstractItemView.SelectRows)
47 self.setSizePolicy(QSizePolicy.MinimumExpanding,
48 QSizePolicy.MinimumExpanding)
49 self.setSortingEnabled(True)
50 self.setModel(self._model)
51 QObject.connect(self, SIGNAL('doubleClicked(QModelIndex)'),
53 def OnDoubleClick(self, model_index):
54 print('DOUBLE')
55 if not self.double_click:
56 return
57 row = table.TableRow(self._model.table.rows[model_index.row()],
58 self._model.table)
59 self.double_click(row)
__init__(self, table)
Definition table.py:37
OnDoubleClick(self, model_index)
Definition table.py:53
__init__(self, table, parent=None)
Definition table.py:8
data(self, index, role)
Definition table.py:30
columnCount(self, index)
Definition table.py:20
rowCount(self, index)
Definition table.py:12
sort(self, column, order)
Definition table.py:23
headerData(self, section, orientation, role)
Definition table.py:15