@@ -1,258 +1,277 | |||
|
1 | 1 | from PyQt4 import QtCore |
|
2 | 2 | |
|
3 |
HORIZONTAL_HEADERS = (" |
|
|
3 | HORIZONTAL_HEADERS = ("Property","Value " ) | |
|
4 | 4 | |
|
5 | 5 | HORIZONTAL = ("RAMA :",) |
|
6 | 6 | |
|
7 | 7 | class treeModel(QtCore.QAbstractItemModel): |
|
8 | 8 | ''' |
|
9 | 9 | a model to display a few names, ordered by encabezado |
|
10 | 10 | ''' |
|
11 | 11 | name=None |
|
12 | 12 | directorio=None |
|
13 | 13 | workspace=None |
|
14 | 14 | remode=None |
|
15 | 15 | dataformat=None |
|
16 | 16 | date=None |
|
17 | 17 | initTime=None |
|
18 | 18 | endTime=None |
|
19 | 19 | timezone=None |
|
20 | 20 | Summary=None |
|
21 | 21 | |
|
22 | 22 | description=None |
|
23 | 23 | |
|
24 | 24 | def __init__(self ,parent=None): |
|
25 | 25 | super(treeModel, self).__init__(parent) |
|
26 | 26 | self.people = [] |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | def properties_projecto(self,description): |
|
30 | 30 | self.caracteristica="Project_Properties" |
|
31 | 31 | self.principal ="Name" |
|
32 | 32 | self.description =description |
|
33 | 33 | exam_project=person_class(self.caracteristica,self.principal,self.description) |
|
34 | 34 | return exam_project |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | def arbol(self): |
|
39 | 39 | for caracteristica,principal, descripcion in (("Properties","Name",self.name), |
|
40 | 40 | ("Properties","Data Path",self.directorio), |
|
41 | 41 | ("Properties","Workspace",self.workspace), |
|
42 | 42 | ("Parameters", "Read Mode ",self.remode), |
|
43 | 43 | ("Parameters", "DataType ",self.dataformat), |
|
44 | 44 | ("Parameters", "Date ",self.date), |
|
45 | 45 | ("Parameters", "Init Time ",self.initTime), |
|
46 | 46 | ("Parameters", "Final Time ",self.endTime), |
|
47 | 47 | ("Parameters", " Time zone ",self.timezone), |
|
48 | 48 | ("Parameters", "Profiles ","1"), |
|
49 | 49 | ("Description", "Summary ", self.Summary), |
|
50 | 50 | ): |
|
51 | 51 | person = person_class(caracteristica, principal, descripcion) |
|
52 | 52 | self.people.append(person) |
|
53 | 53 | def addProjectproperties(self,person): |
|
54 | 54 | self.people.append(person) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | #def veamos(self): |
|
58 | 58 | # self.update= MainWindow(self) |
|
59 | 59 | # self.update.dataProyectTxt.text() |
|
60 | 60 | # return self.update.dataProyectTxt.text() |
|
61 | 61 | |
|
62 | 62 | def showtree(self): |
|
63 | 63 | self.rootItem = TreeItem(None, "ALL", None) |
|
64 | 64 | self.parents = {0 : self.rootItem} |
|
65 | 65 | self.setupModelData() |
|
66 | 66 | |
|
67 | 67 | def setParams(self,name,directorio,workspace,remode,dataformat,date,initTime,endTime,timezone,Summary): |
|
68 | 68 | self.name=name |
|
69 | 69 | self.workspace=workspace |
|
70 | 70 | self.directorio= directorio |
|
71 | 71 | self.remode=remode |
|
72 | 72 | self.dataformat=dataformat |
|
73 | 73 | self.date=date |
|
74 | 74 | self.initTime=initTime |
|
75 | 75 | self.endTime=endTime |
|
76 | 76 | self.timezone=timezone |
|
77 | 77 | self.Summary=Summary |
|
78 | 78 | |
|
79 | 79 | |
|
80 | for caracteristica,principal, descripcion in (("Properties","Name",self.name), | |
|
81 | ("Properties","Data Path",self.directorio), | |
|
82 | ("Properties","Workspace",self.workspace), | |
|
83 | ("Parameters", "Read Mode ",self.remode), | |
|
84 | ("Parameters", "DataType ",self.dataformat), | |
|
85 | ("Parameters", "Date ",self.date), | |
|
86 | ("Parameters", "Init Time ",self.initTime), | |
|
87 | ("Parameters", "Final Time ",self.endTime), | |
|
88 | ("Parameters", " Time zone ",self.timezone), | |
|
89 | ("Parameters", "Profiles ","1"), | |
|
90 | ("Description", "Summary ", self.Summary), | |
|
91 | ): | |
|
92 | person = person_class(caracteristica, principal, descripcion) | |
|
93 | self.people.append(person) | |
|
94 | self.rootItem = TreeItem(None, "ALL", None) | |
|
95 | self.parents = {0 : self.rootItem} | |
|
96 | self.setupModelData() | |
|
97 | ||
|
98 | ||
|
80 | 99 | def columnCount(self, parent=None): |
|
81 | 100 | if parent and parent.isValid(): |
|
82 | 101 | return parent.internalPointer().columnCount() |
|
83 | 102 | else: |
|
84 | 103 | return len(HORIZONTAL_HEADERS) |
|
85 | 104 | |
|
86 | 105 | def data(self, index, role): |
|
87 | 106 | if not index.isValid(): |
|
88 | 107 | return QtCore.QVariant() |
|
89 | 108 | |
|
90 | 109 | item = index.internalPointer() |
|
91 | 110 | if role == QtCore.Qt.DisplayRole: |
|
92 | 111 | return item.data(index.column()) |
|
93 | 112 | if role == QtCore.Qt.UserRole: |
|
94 | 113 | if item: |
|
95 | 114 | return item.person |
|
96 | 115 | |
|
97 | 116 | return QtCore.QVariant() |
|
98 | 117 | |
|
99 | 118 | def headerData(self, column, orientation, role): |
|
100 | 119 | if (orientation == QtCore.Qt.Horizontal and |
|
101 | 120 | role == QtCore.Qt.DisplayRole): |
|
102 | 121 | try: |
|
103 | 122 | return QtCore.QVariant(HORIZONTAL_HEADERS[column]) |
|
104 | 123 | except IndexError: |
|
105 | 124 | pass |
|
106 | 125 | |
|
107 | 126 | return QtCore.QVariant() |
|
108 | 127 | |
|
109 | 128 | def index(self, row, column, parent): |
|
110 | 129 | if not self.hasIndex(row, column, parent): |
|
111 | 130 | return QtCore.QModelIndex() |
|
112 | 131 | |
|
113 | 132 | if not parent.isValid(): |
|
114 | 133 | parentItem = self.rootItem |
|
115 | 134 | else: |
|
116 | 135 | parentItem = parent.internalPointer() |
|
117 | 136 | |
|
118 | 137 | childItem = parentItem.child(row) |
|
119 | 138 | if childItem: |
|
120 | 139 | return self.createIndex(row, column, childItem) |
|
121 | 140 | else: |
|
122 | 141 | return QtCore.QModelIndex() |
|
123 | 142 | |
|
124 | 143 | def parent(self, index): |
|
125 | 144 | if not index.isValid(): |
|
126 | 145 | return QtCore.QModelIndex() |
|
127 | 146 | |
|
128 | 147 | childItem = index.internalPointer() |
|
129 | 148 | if not childItem: |
|
130 | 149 | return QtCore.QModelIndex() |
|
131 | 150 | |
|
132 | 151 | parentItem = childItem.parent() |
|
133 | 152 | |
|
134 | 153 | if parentItem == self.rootItem: |
|
135 | 154 | return QtCore.QModelIndex() |
|
136 | 155 | |
|
137 | 156 | return self.createIndex(parentItem.row(), 0, parentItem) |
|
138 | 157 | |
|
139 | 158 | def rowCount(self, parent=QtCore.QModelIndex()): |
|
140 | 159 | if parent.column() > 0: |
|
141 | 160 | return 0 |
|
142 | 161 | if not parent.isValid(): |
|
143 | 162 | p_Item = self.rootItem |
|
144 | 163 | else: |
|
145 | 164 | p_Item = parent.internalPointer() |
|
146 | 165 | return p_Item.childCount() |
|
147 | 166 | |
|
148 | 167 | def setupModelData(self): |
|
149 | 168 | for person in self.people: |
|
150 | 169 | if person.descripcion: |
|
151 | 170 | encabezado = person.caracteristica |
|
152 | 171 | |
|
153 | 172 | |
|
154 | 173 | if not self.parents.has_key(encabezado): |
|
155 | 174 | newparent = TreeItem(None, encabezado, self.rootItem) |
|
156 | 175 | self.rootItem.appendChild(newparent) |
|
157 | 176 | |
|
158 | 177 | self.parents[encabezado] = newparent |
|
159 | 178 | |
|
160 | 179 | parentItem = self.parents[encabezado] |
|
161 | 180 | newItem = TreeItem(person, "", parentItem) |
|
162 | 181 | parentItem.appendChild(newItem) |
|
163 | 182 | |
|
164 | 183 | def searchModel(self, person): |
|
165 | 184 | ''' |
|
166 | 185 | get the modelIndex for a given appointment |
|
167 | 186 | ''' |
|
168 | 187 | def searchNode(node): |
|
169 | 188 | ''' |
|
170 | 189 | a function called recursively, looking at all nodes beneath node |
|
171 | 190 | ''' |
|
172 | 191 | for child in node.childItems: |
|
173 | 192 | if person == child.person: |
|
174 | 193 | index = self.createIndex(child.row(), 0, child) |
|
175 | 194 | return index |
|
176 | 195 | |
|
177 | 196 | if child.childCount() > 0: |
|
178 | 197 | result = searchNode(child) |
|
179 | 198 | if result: |
|
180 | 199 | return result |
|
181 | 200 | |
|
182 | 201 | retarg = searchNode(self.parents[0]) |
|
183 | 202 | #print retarg |
|
184 | 203 | return retarg |
|
185 | 204 | |
|
186 | 205 | def find_GivenName(self, principal): |
|
187 | 206 | app = None |
|
188 | 207 | for person in self.people: |
|
189 | 208 | if person.principal == principal: |
|
190 | 209 | app = person |
|
191 | 210 | break |
|
192 | 211 | if app != None: |
|
193 | 212 | index = self.searchModel(app) |
|
194 | 213 | return (True, index) |
|
195 | 214 | return (False, None) |
|
196 | 215 | |
|
197 | 216 | |
|
198 | 217 | |
|
199 | 218 | |
|
200 | 219 | |
|
201 | 220 | |
|
202 | 221 | |
|
203 | 222 | class person_class(object): |
|
204 | 223 | ''' |
|
205 | 224 | a trivial custom data object |
|
206 | 225 | ''' |
|
207 | 226 | def __init__(self, caracteristica, principal, descripcion): |
|
208 | 227 | self.caracteristica = caracteristica |
|
209 | 228 | self.principal = principal |
|
210 | 229 | self.descripcion = descripcion |
|
211 | 230 | |
|
212 | 231 | def __repr__(self): |
|
213 | 232 | return "PERSON - %s %s"% (self.principal, self.caracteristica) |
|
214 | 233 | |
|
215 | 234 | class TreeItem(object): |
|
216 | 235 | ''' |
|
217 | 236 | a python object used to return row/column data, and keep note of |
|
218 | 237 | it's parents and/or children |
|
219 | 238 | ''' |
|
220 | 239 | def __init__(self, person, header, parentItem): |
|
221 | 240 | self.person = person |
|
222 | 241 | self.parentItem = parentItem |
|
223 | 242 | self.header = header |
|
224 | 243 | self.childItems = [] |
|
225 | 244 | |
|
226 | 245 | def appendChild(self, item): |
|
227 | 246 | self.childItems.append(item) |
|
228 | 247 | |
|
229 | 248 | def child(self, row): |
|
230 | 249 | return self.childItems[row] |
|
231 | 250 | |
|
232 | 251 | def childCount(self): |
|
233 | 252 | return len(self.childItems) |
|
234 | 253 | |
|
235 | 254 | def columnCount(self): |
|
236 | 255 | return 2 |
|
237 | 256 | |
|
238 | 257 | def data(self, column): |
|
239 | 258 | if self.person == None: |
|
240 | 259 | if column == 0: |
|
241 | 260 | return QtCore.QVariant(self.header) |
|
242 | 261 | if column == 1: |
|
243 | 262 | return QtCore.QVariant("") |
|
244 | 263 | else: |
|
245 | 264 | if column == 0: |
|
246 | 265 | return QtCore.QVariant(self.person.principal) |
|
247 | 266 | if column == 1: |
|
248 | 267 | return QtCore.QVariant(self.person.descripcion) |
|
249 | 268 | return QtCore.QVariant() |
|
250 | 269 | |
|
251 | 270 | def parent(self): |
|
252 | 271 | return self.parentItem |
|
253 | 272 | |
|
254 | 273 | def row(self): |
|
255 | 274 | if self.parentItem: |
|
256 | 275 | return self.parentItem.childItems.index(self) |
|
257 | 276 | return 0 |
|
258 | 277 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now