-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathManager.py
More file actions
83 lines (60 loc) · 2.44 KB
/
PathManager.py
File metadata and controls
83 lines (60 loc) · 2.44 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from PySide import QtCore, QtGui
from PySide.QtCore import Qt, QModelIndex
from Path import Path
class PathManager(QtCore.QAbstractTableModel):
COLUMN_TITLES = ['Name', 'Initial Sheet', 'Visible']
def __init__(self, path_table):
super(PathManager, self).__init__()
self.path_table = path_table
self.paths = []
self.visibilities = []
self.names = []
##################################################################
# Slots
##################################################################
def removeSelectedPaths(self):
for index in self.path_table.selectedIndexes():
self.removeRow(index.row())
def newPath(self):
self.insertRow(len(self.paths))
##################################################################
# QAbstractItemModel methods
##################################################################
def insertRow(self, row, parent=QModelIndex()):
# Simple tabular view: should be no parental ambiguity
assert parent == QModelIndex()
self.beginInsertRows(parent, row, row)
self.paths.insert(row, Path())
self.visibilities.insert(row)
self.names.insert(row, 'Temporary name')
self.endInsertRows()
return True
def removeRow(self, row, parent=QModelIndex()):
# Simple tabular view: should be no parental ambiguity
assert parent == QModelIndex()
self.beginRemoveRows(parent, row, row)
del self.paths[row:row+1]
del self.visibilities[row:row+1]
del self.names[row:row+1]
self.endRemoveRows()
def rowCount(self, parent):
return len(self.paths)
def columnCount(self, index):
return len(PathManager.COLUMN_TITLES)
def data(self, index, role):
if not index.isValid() or role != Qt.DisplayRole:
return None
path = self.paths[index.row()]
if index.column() == 0:
return self.names[index.row()]
elif index.column() == 1:
return self.paths[index.row()].getInitialSheet()
elif index.column() == 2:
return self.visibilities[index.row()]
else:
return None
def headerData(self, section, orientation, role):
if role != Qt.DisplayRole or orientation == Qt.Vertical:
return None
return PathManager.COLUMN_TITLES[section]
# setData for editability