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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 30 10:42:54 2012
@author: JeanPat
"""
import sys
import lxml.etree as et
from copy import deepcopy
from PyQt4 import QtGui, QtCore
def GetChidrenName(etree):
"""return the names (str) of the children of an Database etree.Element"""
childrenlist=[]
print "GetChildren ... type(etree)",type(etree[0])
children=etree.getchildren()
print children[0].get("name")
for c in children:
childrenlist.append(c.get("name"))
return childrenlist
class CascadeMenu(QtGui.QWidget):
"""Four combobox to explore a tree content"""
def __init__(self,etree):
super(CascadeMenu, self).__init__()
self.db = etree#DataBase:The whole directory tree
self.lbl = QtGui.QLabel("CytoM", self)
#==============================================================================
# Connection en cascade des QCombobox
#==============================================================================
##Connection combo1 vers combo2
self.combo1 = QtGui.QComboBox(self)#projects list
self.label_combo1 = QtGui.QLabel("Project",self)
#self.combo1.addWidget(self.label_combo1)
self.connect(self.combo1, QtCore.SIGNAL('currentIndexChanged(QString)'),\
self.changeindexcombo1)
##Connection combo2 vers combo3
self.combo2 = QtGui.QComboBox(self)#slides list
self.label_combo2 = QtGui.QLabel("Slide",self)
self.connect(self.combo2, QtCore.SIGNAL('currentIndexChanged(QString)'),\
self.changeindexcombo2)
##Connection combo3 vers combo4
self.combo3 = QtGui.QComboBox(self)#fields list
self.label_combo3 = QtGui.QLabel("Field",self)
self.connect(self.combo3, QtCore.SIGNAL('currentIndexChanged(QString)'),\
self.changeindexcombo3)
##Connection combo4 vers combo5; appel de chargement d'un fluo
self.combo4 = QtGui.QComboBox(self)#Fluorochromes list
self.label_combo4 = QtGui.QLabel("Fluo",self)
self.connect(self.combo4, QtCore.SIGNAL('currentIndexChanged(QString)'),\
self.changeindexcombo4)
##Connection combo5 vers : appel d'une image
self.combo5 = QtGui.QComboBox(self)#Fluorochromes list
self.label_combo5 = QtGui.QLabel("Image",self)
self.connect(self.combo5, QtCore.SIGNAL('currentIndexChanged(QString)'),\
self.changeindexcombo5)
# positionnement des widgets dans la fenêtre
posit = QtGui.QGridLayout()
posit.addWidget(self.label_combo1, 0, 0)
posit.addWidget(self.label_combo2, 0, 1)
posit.addWidget(self.label_combo3, 0, 2)
posit.addWidget(self.label_combo4, 0, 3)
posit.addWidget(self.label_combo5, 0, 4)
posit.addWidget(self.combo1, 1, 0)
posit.addWidget(self.combo2, 1, 1)
posit.addWidget(self.combo3, 1, 2)
posit.addWidget(self.combo4, 1, 3)
posit.addWidget(self.combo5, 1, 4)
posit.addWidget(self.lbl, 2, 0)
self.setLayout(posit)
self.setWindowTitle('Cascade Menus')
self.show()
#==============================================================================
# Fill combo1 with projects list
#==============================================================================
#Combo1: first level in the tree
self.combo1.addItems(GetChidrenName(self.db))#project level-first element
self.node1=self.db.getchildren()
#==============================================================================
# Fill combo2 with slides belonging to a project
#==============================================================================
self.node2=None #slide level
self.node2=self.node1[0].getchildren()
#fill from combo1 active item as parent
#
parent=self.node1[self.combo1.currentIndex()]
childrenlist=GetChidrenName(parent)
print "init combo2 :childrenlist",childrenlist
self.combo2.addItems(QtCore.QStringList(childrenlist))
#==============================================================================
# Fill combo3 with fields (metaphases) of a given slide
#==============================================================================
self.node3=None #field level
self.node3=self.node2[0].getchildren()
parent=self.node2[self.combo2.currentIndex()]
childrenlist=GetChidrenName(parent)
print "init combo3 :childrenlist",childrenlist
self.combo3.addItems(QtCore.QStringList(childrenlist))
#==============================================================================
# Fill combo4 with Fluo ("color"DAPI,...) of a field
#==============================================================================
self.node4=None #fluo level
self.node4=self.node3[0].getchildren()
print "init node4",self.node4
parent=self.node3[self.combo3.currentIndex()]
childrenlist=GetChidrenName(parent)
self.combo4.addItems(QtCore.QStringList(childrenlist))
#==============================================================================
# Fill combo5 with image(s) of a fluorochrome
#==============================================================================
self.node5=None #fluo level
self.node5=self.node4[0].getchildren()
parent=self.node4[self.combo4.currentIndex()]
childrenlist=GetChidrenName(parent)
self.combo5.addItems(QtCore.QStringList(childrenlist))
#==============================================================================
# test
#==============================================================================
print "node1",type(self.node1),self.node1
def GetChidrenName(etree):
"""return the names (str) of the children of an Database etree.Element"""
childrenlist=[]
children=etree.getchildren()#list of etree chidren
for c in children:
childrenlist.append(c.get("name"))
return childrenlist
def changeindexcombo1(self):
"""méthode exécutée en cas de changement d'affichage du combo1
"""
text=str(self.combo1.currentText())+"/"+str(self.combo2.currentText())
self.lbl.setText(text)
self.combo2.clear()
#quel le parent?
#recup l'item actif de combo1
print "combo1 cur Index",self.combo1.currentIndex()
#identifier le node correspondant,
## suppossons que ce soit==self.combo1.currentIndex()
##parent est un etree.Element, son nom devrait être l'item courant de combo1
parent=self.node1[self.combo1.currentIndex()]
#demander ses enfants,
##demander le nom des enfants
childrenlist=GetChidrenName(parent)
self.combo2.addItems(QtCore.QStringList(childrenlist))
def changeindexcombo2(self):
"""méthode exécutée en cas de changement d'affichage du combo2
"""
text=str(self.combo1.currentText())+"/"+str(self.combo2.currentText())
self.lbl.setText(text)
self.combo3.clear()
#quel le parent?
#recup l'item actif de combo1
print "combo2 cur Index",self.combo2.currentIndex()
#identifier le node correspondant,
## suppossons que ce soit==self.combo1.currentIndex()
##parent est un etree.Element, son nom devrait être l'item courant de combo1
parent=self.node2[self.combo2.currentIndex()]
#demander ses enfants,
##demander le nom des enfants
childrenlist=GetChidrenName(parent)
self.combo3.addItems(QtCore.QStringList(childrenlist))
def changeindexcombo3(self):
"""méthode exécutée en cas de changement d'affichage du combo3
"""
text=str(self.combo1.currentText())+"/"+\
str(self.combo2.currentText())+"/"+\
str(self.combo3.currentText())+"/"+\
str(self.combo4.currentText())
self.lbl.setText(text)
self.combo4.clear()
#quel le parent?
#recup l'item actif de combo1
print "combo3 cur Index",self.combo3.currentIndex()
#identifier le node correspondant,
## suppossons que ce soit==self.combo1.currentIndex()
##parent est un etree.Element, son nom devrait être l'item courant de combo1
parent=self.node3[self.combo3.currentIndex()]
#demander ses enfants,
##demander le nom des enfants
childrenlist=GetChidrenName(parent)
self.combo4.addItems(QtCore.QStringList(childrenlist))
def changeindexcombo4(self):
"""méthode exécutée en cas de changement d'affichage du combo4
"""
text=str(self.combo1.currentText())+"/"+\
str(self.combo2.currentText())+"/"+\
str(self.combo3.currentText())+"/"+\
self.lbl.setText(text)
self.combo5.clear()
#quel le parent?
#recup l'item actif de combo1
print "combo4 cur Index",self.combo4.currentIndex()
#identifier le node correspondant,
## suppossons que ce soit==self.combo1.currentIndex()
##parent est un etree.Element, son nom devrait être l'item courant de combo1
parent=self.node4[self.combo4.currentIndex()]
#demander ses enfants,
##demander le nom des enfants
childrenlist=GetChidrenName(parent)
self.combo5.addItems(QtCore.QStringList(childrenlist))
def changeindexcombo5(self):
text=str(self.combo1.currentText())+"/"+\
str(self.combo2.currentText())+"/"+\
str(self.combo3.currentText())+"/"+\
self.lbl.setText(text)
#self.combo5.clear()
#quel le parent?
#recup l'item actif de combo4
print "combo4 cur Index",self.combo4.currentIndex()
#identifier le node correspondant,
## suppossons que ce soit==self.combo1.currentIndex()
##parent est un etree.Element, son nom devrait être l'item courant de combo1
parent=self.node4[self.combo4.currentIndex()]
#demander ses enfants,
##demander le nom des enfants
childrenlist=GetChidrenName(parent)
self.combo5.addItems(QtCore.QStringList(childrenlist))
def main():
#==============================================================================
# Build a xml tree
#==============================================================================
R=et.Element('racine')
a=et.Element('project',name='applied')
R.append(a)
v=et.Element('project',name='vysis')
R.append(v)
s1=et.Element('slide',name='s1')
s2=et.Element('slide',name='s2')
a.append(s1)
a.append(s2)
sprime1=et.Element('slide',name='slide0')
v.append(sprime1)
a.set("path","/path/to/project")
v.set("path","/path/to/project")
f1=et.Element('field',name='metaphase 1')
f2=et.Element('field',name='metaphase 2')
f3=et.Element('field',name='nuclei 1')
sprime1.append(deepcopy(f3))
sprime1.append(deepcopy(f2))
fluo0=et.Element('fluo',name='IP')
fluo1=et.Element('fluo',name='DAPI')
fluo2=et.Element('fluo',name='Cy3')
fluo3=et.Element('fluo',name='FITC')
im1=et.Element('image',name='1',ext='.TIF')
fluo1.append(deepcopy(im1))
fluo2.append(deepcopy(im1))
f1.append(deepcopy(fluo1))
f1.append(deepcopy(fluo2))
s1.append(deepcopy(f1))
s1.append(deepcopy(f2))
s2.append(deepcopy(f1))
print(et.tostring(R,pretty_print=True))
#==============================================================================
#
#==============================================================================
app = QtGui.QApplication(sys.argv)
ex = CascadeMenu(R)
sys.exit(app.exec_())
if __name__ == '__main__':
main() |
Partager