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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# -*- coding: utf-8 -*
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class API():
def __init__(self, model):
self.model=model
self.app = QApplication(sys.argv)
self.tree = QTreeWidget()
HEADERS = ("TITI", "TOTO", "column 3")
self.tree.setColumnCount(len(HEADERS))
self.tree.setHeaderLabels(HEADERS)
headerItem = QTreeWidgetItem()
item = QTreeWidgetItem()
Qparent = QTreeWidgetItem(self.tree)
Qparent.setText(0, "Root")
self.parse(Qparent,self.model)
self.tree.clicked.connect(self.onClick)
self.tree.show()
sys.exit(self.app.exec_())
def parse(self,Qparent,branche):
for elm in branche.child:
Qchild = MyQTreeWidgetItem(parent=Qparent,model=branche)
Qchild.setFlags(Qchild.flags() | Qt.ItemIsUserCheckable | Qt.ItemIsEditable)
Qchild.setText(0, "{}".format(elm.txt).decode("utf-8"))
Qchild.setText(1, "fifi {}".format(elm.responsable))
if elm.statut == True:
Qchild.setCheckState(0, Qt.Checked)
else:
Qchild.setCheckState(0, Qt.Unchecked)
if elm.child != []:
# print elm.child
self.parse(Qchild,elm)
def onClick(self, index):
if self.app.mouseButtons() & Qt.RightButton :
print self.tree.currentItem().model.txt
class MyQTreeWidgetItem(QTreeWidgetItem):
def __init__(self, parent,model):
QTreeWidgetItem.__init__(self,parent)
self.model = model
def setData(self,*args,**kwds):
role=args[2]
index=args[0]
data=args[1]
super(MyQTreeWidgetItem,self).setData(*args,**kwds)
print self.checkState(0)
if self.checkState(0) == 0:
self.setCheckState(0, Qt.Unchecked)
print "coche", self.text(0)
else:
self.setCheckState(0, Qt.Checked)
print "decoche", self.text(0)
# def setData(self, index, data, role):
# print index, data,role
# # if not index.isValid():
# # return False
#
# if index.column() in self.booleanSet and role == Qt.CheckStateRole:
# value = QVariant(True) if data.toInt()[0] == Qt.Checked else QVariant(False)
# return QSortFilterProxyModel.setData(self, index, value, Qt.EditRole)
# else:
# return QSortFilterProxyModel.setData(self, index, data, role)
class Todolist():
idclass = 1
def __init__(self,parent=None, txt="", statut=False, responsable=""):
self.id = Todolist.idclass + 1
Todolist.idclass = self.id
self.statut = statut
self.txt = txt
self.responsable = responsable
self.child=[]
self.parent=parent
if parent != None:
parent.add_Action(self)
# CRUD methode
# todo....
def get_Parent(self):
return self.parent
def add_Action(self,action):
self.child.append(action)
def __str__(self):
print "{}\t{}\t{}".format(self.statut, self.txt, self.responsable)
if self.child != []:
for x in self.child:
print x
return ""
if __name__ == '__main__':
myTdl=Todolist()
Tdl_11=Todolist(myTdl,"Qualité", False, "moi")
Tdl_12=Todolist(myTdl,"faire plein de chose 2", False, "1122")
Tdl_13=Todolist(myTdl,"faire plein de chose 3", True, "1242")
Tdl_31=Todolist(Tdl_11,"faire plein de chose 4", False, "1")
Tdl_32 = Todolist(Tdl_11, "faire pl4", False, "i")
Tdl_33 = Todolist(Tdl_11, "#######", False, "i")
Tdl_15=Todolist(myTdl, "faire plein de chose 6", False, "58")
API(myTdl) |
Partager