Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

userAppTree.py

00001 __version__  = "$Revision: 2.4 $"
00002 
00003 from qt import QListView, QPoint, QPopupMenu, QCursor, SIGNAL
00004 
00005 from userAppLeaf import userAppLeaf
00006 
00007 class userAppTree(object):
00008   def __init__(self, view):
00009     self.view = view
00010     self.clearLeaves()
00011     self.leaf_type_module_dict = {}
00012     self.oldItem = None
00013     self.copyFromMenu = None
00014 
00015     self.view.connect(self.view, SIGNAL('rightButtonClicked ( QListViewItem *, const QPoint &, int)'), self.rightMouseClicked)
00016     self.view.connect(self.view, SIGNAL("pressed ( QListViewItem *, const QPoint &, int )"), self.pressedEvent)
00017     
00018 #    self.view.setSelectionMode(QListView.NoSelection)
00019 
00020   def pressedEvent(self, leaf, pos, column):
00021     if leaf is not None:
00022       leaf.pressedEvent(pos, column)
00023 
00024   def rightMouseClicked(self, leaf):
00025     """ Function that is triggered by a right click of the mouse over the tree
00026         This lauches a pop-up menu with actions that can be taken on the
00027         leaf where the cursor is
00028         \param leaf leaf that the mouse is pointing at
00029     """
00030     if leaf is not None:
00031       popup = QPopupMenu(self.view,'Options')
00032       if self.copyFromMenu is not None:
00033         popup.insertItem('Copy selection from', self.copyFromMenu)
00034       actions = leaf.leafActionsTuples()
00035       for (name,method) in actions:
00036         popup.insertItem(name, method)
00037       popup.popup(QCursor.pos())
00038 
00039   def setCopyFromMenu(self, from_list, method):
00040     """ Function that creates the popup menu that is launched when
00041         'Copy from' is highlighted
00042         based on a list describing the names that describes the origins
00043         and on a method that will execute the copying given the origin's index
00044         \param from_list list of name for the possible origins
00045         \param method that execute the copying from the specified origin to this leaf
00046     """
00047     if self.copyFromMenu is None:
00048       self.copyFromMenu = QPopupMenu(self.view, 'Copy from')
00049     else:
00050        self.copyFromMenu.clear()
00051     for k in range(len(from_list)):
00052       name = from_list[k]
00053       id = self.copyFromMenu.insertItem(name, method)
00054       self.copyFromMenu.setItemParameter(id,k)
00055 
00056   def AddLeaf(self,leaf):
00057     """ Function that adds the leaf to a local list of the leafs in this tree
00058         Locally the list is organized according to module types
00059         \param leaf leaf to add to the tree leaves list
00060     """
00061     self.leaf_list.append(leaf)
00062     if leaf.module() in self.leaf_dict.keys():
00063       self.leaf_dict[leaf.module()].append(leaf)
00064     else:
00065       self.leaf_dict[leaf.module()] = [leaf]
00066 
00067   def clearLeaves(self):
00068     self.leaf_list = []
00069     self.leaf_dict = {}
00070     self.view.clear()
00071 
00072   def getAllLeaves(self):
00073     return self.leaf_list
00074 
00075   def getInputNodes(self, of_class_type = None):
00076     """ Function which extracts from all the tree the leafs that are checked,
00077         it builds a list of Gnodes that are considered checked
00078         \return list of Gnodes
00079     """
00080     inputs = []
00081     child = self.view.firstChild()
00082     while child is not None:
00083       if child.isOn() and isinstance(child.node, of_class_type):
00084         inputs.append(child.node)
00085       inputs += child.getInputNodes(of_class_type)
00086       child = child.nextSibling()
00087     return inputs
00088 
00089   def getLeaf(self,leaf):
00090     """ Function that retrieves a leaf in the tree structure
00091         \param leaf leaf to search for
00092         \return leaf matching leaf found in the tree
00093     """
00094     # The tree is designed with only one first generation child
00095     return self.view.firstChild().getLeaf(leaf)
00096 
00097   def copyCheckedNodes(self, from_tree):
00098     """ Function that copies all the checked status of nodes in the from_tree to the nodes in this tree
00099         \param from_tree tree object from which to copy the checked information for the leaves
00100     """
00101     # The tree is designed with only one first generation child
00102     if (self.view.firstChild() is not None) and (from_tree.firstChild() is not None):
00103       self.view.firstChild().copyCheckedNodes(from_tree.firstChild())
00104 
00105 
00106   def loadNodes(self, lat, leaf_class = None):
00107     """ Function that populate the tree by converting nodes in the LAT structure into leaves of leaf_class
00108         \param lat LAT pointer
00109         \param leaf_class class object which will be used to populate the tree
00110     """
00111     ## Clear the hierarchy first
00112     if leaf_class == None:
00113       leaf_class = userAppLeaf
00114 
00115     for leaf in self.leaf_list:
00116       leaf.close()
00117       del(leaf)
00118     self.clearLeaves()
00119     if lat == None:
00120       return
00121 
00122     self.view.setEnabled(1)
00123 
00124     lat_leaf = leaf_class(lat, lat, self.view)
00125     lat_leaf.setOpen(1)
00126     self.AddLeaf(lat_leaf)
00127 
00128     if lat.existsAEM():
00129       aem = lat.AEM
00130       aem_leaf = leaf_class(lat, aem, lat_leaf)
00131       self.AddLeaf(aem_leaf)
00132       for arc in aem.ARC.values():
00133         arc_leaf = leaf_class(lat, arc, aem_leaf)
00134         self.AddLeaf(arc_leaf)
00135         for afe in arc.AFE.values():
00136           self.AddLeaf(leaf_class(lat, afe, arc_leaf))
00137 
00138       if aem.existsAEQ():
00139         self.AddLeaf(leaf_class(lat, aem.AEQ, aem_leaf))
00140 
00141     for pdu in lat.PDU.values():
00142       pdu_leaf = leaf_class(lat, pdu, lat_leaf)
00143       self.AddLeaf(pdu_leaf)
00144       if pdu.existsPEQ():
00145         self.AddLeaf(leaf_class(lat, pdu.PEQ, pdu_leaf))
00146 
00147     if lat.existsCRU():
00148       self.AddLeaf(leaf_class(lat, lat.CRU, lat_leaf))
00149 
00150     if lat.existsEBM():
00151       ebm = lat.EBM
00152       ebm_leaf = leaf_class(lat, ebm, lat_leaf)
00153       self.AddLeaf(ebm_leaf)
00154       if ebm.existsEBMC():
00155         self.AddLeaf(leaf_class(lat, ebm.EBMC, ebm_leaf))
00156       if ebm.existsEBMST():
00157         self.AddLeaf(leaf_class(lat, ebm.EBMST, ebm_leaf))
00158 
00159     if lat.existsGEM():
00160       gem = lat.GEM
00161       gem_leaf = leaf_class(lat, gem, lat_leaf)
00162       self.AddLeaf(gem_leaf)
00163       if gem.existsGEMC():
00164         self.AddLeaf(leaf_class(lat, gem.GEMC, gem_leaf))
00165       if gem.existsGEMMG():
00166         self.AddLeaf(leaf_class(lat, gem.GEMMG, gem_leaf))
00167       if gem.existsGEMST():
00168         self.AddLeaf(leaf_class(lat, gem.GEMST, gem_leaf))
00169       if gem.existsGEMSC():
00170         self.AddLeaf(leaf_class(lat, gem.GEMSC, gem_leaf))
00171       if gem.existsGEMVG():
00172         self.AddLeaf(leaf_class(lat, gem.GEMVG, gem_leaf))
00173       if gem.existsGEMIE():
00174         self.AddLeaf(leaf_class(lat, gem.GEMIE, gem_leaf))
00175       if gem.existsGEMW():
00176         self.AddLeaf(leaf_class(lat, gem.GEMW, gem_leaf))
00177 
00178     for tem in lat.TEM.values():
00179       tem_leaf = leaf_class(lat, tem, lat_leaf)
00180       self.AddLeaf(tem_leaf)
00181       if tem.existsTIC():
00182         self.AddLeaf(leaf_class(lat, tem.TIC, tem_leaf))
00183 
00184       for ccc in tem.CCC.values():
00185         ccc_leaf = leaf_class(lat, ccc, tem_leaf)
00186         self.AddLeaf(ccc_leaf)
00187         for crc in ccc.CRC.values():
00188           crc_leaf = leaf_class(lat, crc, ccc_leaf)
00189           self.AddLeaf(crc_leaf)
00190           for cfe in crc.CFE.values():
00191             self.AddLeaf(leaf_class(lat, cfe, crc_leaf))
00192 
00193       for tcc in tem.TCC.values():
00194         tcc_leaf = leaf_class(lat, tcc, tem_leaf)
00195         self.AddLeaf(tcc_leaf)
00196         for trc in tcc.TRC.values():
00197           trc_leaf = leaf_class(lat, trc, tcc_leaf)
00198           self.AddLeaf(trc_leaf)
00199           for tfe in trc.TFE.values():
00200             self.AddLeaf(leaf_class(lat, tfe, trc_leaf))
00201 
00202   def setStatus(self, leaf, descr):
00203     leaf.setText(self.columns_dict['Status'], descr[1])
00204 
00205   def close(self):
00206     for leaf in self.leaf_list:
00207       leaf.close()

Generated on Fri Jul 21 13:26:34 2006 for LATTE R04-12-00 by doxygen 1.4.3