ScolaSync  5.1
gestclassetreeview.py
Aller à la documentation de ce fichier.
1 #!/usr/bin/python
2 
3 licence={}
4 licence['en']="""
5  file gestclassetreeview.py
6  this file is part of the project scolasync
7 
8  Copyright (C) 2012 Georges Khaznadar <georgesk@ofset.org>
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version3 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 """
23 
24 import gestClasse
25 from PyQt5.QtWidgets import *
26 from PyQt5.QtCore import *
27 from PyQt5.QtGui import *
28 
30  ##
31  #
32  # Le constructeur
33  # @param parent un parent pour le widget
34  #
35  def __init__(self, parent=None):
36  QTreeView.__init__(self, parent)
37  self.gest=None
38  model=QStandardItemModel()
39  self.setModel(model)
40  self.root = self.model().invisibleRootItem()
41  return
42 
43  ##
44  #
45  # @param fichier le nom d'un fichier, ou un fichier ouvert en lecture, pour
46  # récupérer des données SCONET
47  # @param gestionnaire un gestionnaire pour exploiter les données du fichier
48  # @param renew vrai si on doit tout effacer avant de recommencer
49  #
50  def connecteGestionnaire(self, fichier, gestionnaire=gestClasse.Sconet, renew=False):
51  if renew:
52  m=self.model()
53  m.removeRows(0, m.rowCount())
54  self.root = self.model().invisibleRootItem()
55  self.gest=gestionnaire(fichier)
56  for c in self.gest.collectClasses():
57  rowClasse=[QStandardItem(c)]
58  self.root.appendRow(rowClasse)
59  for e in self.gest.elevesDeClasse(c):
60  name=self.gest.showable_name(e)
61  eleveItem=QStandardItem(name)
62  eleveItem.setCheckable(True)
63  eleveItem.unique_name=self.gest.unique_name(e)
64  rowEleve=[eleveItem]
65  rowClasse[0].appendRow(rowEleve)
66  self.setExpanded(self.model().index(0,0),True)
67  return
68 
69  ##
70  #
71  # @return la liste des items non repliés (donc visibles)
72  #
73  def expandedItems(self):
74  result=[]
75  m=self.model()
76  for r in range(m.rowCount()):
77  cl=m.item(r)
78  if self.isExpanded(cl.index()):
79  for r1 in range(cl.rowCount()):
80  e=cl.child(r1)
81  result.append(e)
82  return result
83 
84  ##
85  #
86  # @return la liste de tous les élèves
87  #
88  def allItems(self):
89  result=[]
90  m=self.model()
91  for r in range(m.rowCount()):
92  cl=m.item(r)
93  for r1 in range(cl.rowCount()):
94  e=cl.child(r1)
95  result.append(e)
96  return result
97 
98  ##
99  #
100  # @return la liste de tous les élèves sélectionnés
101  #
102  def checkedItems(self):
103  result=[]
104  m=self.model()
105  for r in range(m.rowCount()):
106  cl=m.item(r)
107  for r1 in range(cl.rowCount()):
108  e=cl.child(r1)
109  if e.checkState():
110  result.append(e)
111  return result
112