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