C:/mesDocs/QT_confDbVis_canvas/selectPanel.py

Go to the documentation of this file.
00001 import string
00002 import time
00003 
00004 # from wxPython.wx import *
00005 # from wxPython.lib.mixins.listctrl import wxColumnSorterMixin
00006 from qt import *
00007 
00008 from cdbVisCore import *
00009 from objectclasses import *
00010 import visWindow
00011 import pdb
00012         
00013 
00014 ##########################################################################
00015 # SelectWindow class
00016 ##########################################################################
00017 
00018 # GUI CONSTANTS
00019 ID_COMMIT_BUTTON = 451
00020 ID_LINKTYPECHOICE = 452
00021 ID_LINKTYPERESTRICT = 453
00022 ID_TREE_CTRL  = 454
00023 
00024 ID_SPAREPARTSCHOICE = 455
00025 
00026 
00027 listviewIcon0_data = \
00028     "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" \
00029     "\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10" \
00030     "\x08\x06\x00\x00\x00\x1f\xf3\xff\x61\x00\x00\x00" \
00031     "\xdd\x49\x44\x41\x54\x78\x9c\xad\x93\x31\x0a\xc2" \
00032     "\x30\x14\x40\x5f\x4b\xd1\x03\xa8\x20\x14\x14\x71" \
00033     "\x71\x70\x73\x72\xeb\xaa\x6e\x05\x4f\xa1\x77\xd0" \
00034     "\xde\x41\x4f\x21\xb8\x89\xab\x93\xe0\x50\x90\x42" \
00035     "\x47\x1d\x04\xa1\x20\xe2\xec\xa2\x4e\x5f\x6a\x9a" \
00036     "\x88\xa8\x6f\x4b\xf2\xdf\x23\x94\x06\x7e\xc4\x32" \
00037     "\x1d\x4c\xe6\x83\x7b\x7a\x3d\xf4\xa7\xda\xd9\xcc" \
00038     "\xa6\x88\x8d\x6a\x8b\x9a\x5b\x05\x20\xde\x6f\x39" \
00039     "\x24\x7b\x6d\xc8\xd2\x89\xed\x66\x17\x80\xe4\x12" \
00040     "\xbf\xc4\x75\x21\x4b\xe4\xb4\x28\xa8\x01\x35\x34" \
00041     "\xf4\xa7\x96\x2d\x9b\xb9\xe2\x86\x30\x19\x69\x85" \
00042     "\x34\xcb\xf5\xfc\x79\x0b\x00\x47\x1d\x90\x48\xab" \
00043     "\x1c\x64\x44\x1d\x99\x80\x1a\x8a\x42\xe3\x08\x00" \
00044     "\xf6\xdb\xd3\x0f\xf8\x5f\xe0\x78\xf8\xae\x65\x03" \
00045     "\xd4\xf3\x5e\x70\x3e\xd9\x44\xa1\xf3\x71\xa8\x9e" \
00046     "\xf7\x02\x48\xfd\x48\xcb\xc5\x6c\x0c\xb0\xbb\xae" \
00047     "\x46\x00\x85\xd2\x0d\xb7\x72\xcb\x7c\x44\x11\x3b" \
00048     "\xbd\xfe\xf8\x25\x60\x0a\x99\x44\xc1\xf8\x98\x24" \
00049     "\x24\xa8\xe2\xdf\x78\x00\x98\xd4\x59\xeb\xa4\x1a" \
00050     "\x1a\x26\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42" \
00051     "\x60\x82"
00052 listviewIcon1_data = \
00053     "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" \
00054     "\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10" \
00055     "\x08\x06\x00\x00\x00\x1f\xf3\xff\x61\x00\x00\x00" \
00056     "\xe0\x49\x44\x41\x54\x78\x9c\xc5\x93\xbd\x0a\xc2" \
00057     "\x30\x14\x85\x4f\xb5\xbe\x85\xbb\x2e\x5d\xea\x24" \
00058     "\x14\x71\xab\x3f\x73\xf3\x16\x7d\x06\xeb\x33\xe4" \
00059     "\x2d\xe2\x5c\x6d\x37\x91\x80\x8b\x76\x71\xb0\xee" \
00060     "\x2e\x52\xc1\xad\x28\x15\xea\x62\x82\x85\x0a\x89" \
00061     "\x8b\x67\xba\x43\xbe\xef\x90\x0b\x17\xf8\x77\x0c" \
00062     "\x31\xf8\xbe\x5f\xea\x80\x94\x52\x03\x00\x4c\x01" \
00063     "\x77\x1d\x07\x7d\x42\x94\xe0\x2d\x63\xf0\x81\x92" \
00064     "\x52\x6a\x34\x74\x5a\xeb\x62\x8a\x21\xe5\x1c\x29" \
00065     "\xe7\xbf\x0b\x7a\x8e\x89\x11\x69\x29\x41\x11\x2b" \
00066     "\xb0\xe7\xcf\xaa\x20\xbf\x17\xb8\x5c\x1f\x4a\x82" \
00067     "\xfc\xde\x80\xd8\xbf\x14\x1c\x77\x06\x8e\xbb\xa6" \
00068     "\x92\xe0\x33\x52\xe0\xb4\x0f\x20\x9d\xb5\x12\xc4" \
00069     "\x4e\x43\xf0\xb3\x55\x15\xe0\x01\xe0\xa6\x58\xfb" \
00070     "\xf1\x53\x29\xe0\x99\x05\x9e\x59\x8a\x86\x1a\x81" \
00071     "\x6d\xdb\x70\x5d\x57\x09\x8a\xe3\x18\x49\x92\x00" \
00072     "\x78\xaf\x72\x15\x2e\x82\x65\xb4\x99\xe9\x34\x4f" \
00073     "\x46\x83\xf9\x78\xea\x05\xf2\x16\x56\xe1\x22\xd0" \
00074     "\x11\x8c\xa7\x9e\xd6\xfb\xaf\x79\x01\x74\x09\x41" \
00075     "\x81\x95\x44\x4b\x30\x00\x00\x00\x00\x49\x45\x4e" \
00076     "\x44\xae\x42\x60\x82"
00077 listviewIcon2_data = \
00078     "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" \
00079     "\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10" \
00080     "\x08\x06\x00\x00\x00\x1f\xf3\xff\x61\x00\x00\x00" \
00081     "\xeb\x49\x44\x41\x54\x78\x9c\xc5\x92\xbf\x8a\x02" \
00082     "\x31\x10\xc6\xbf\x93\x7b\x83\x7b\x89\x45\x52\x2e" \
00083     "\x6c\xb5\x60\x2f\xf8\x00\xc2\x59\x7a\x82\xa5\x8a" \
00084     "\x36\x22\x56\xba\x78\x8d\x9d\x6e\x61\x7f\xcd\xbd" \
00085     "\xc0\x36\xfb\x00\xfb\x44\x99\x4c\x62\xb5\xc1\x6c" \
00086     "\x56\x36\x56\x0e\x04\x32\x7f\xbe\xdf\xcc\x90\x00" \
00087     "\xef\xb6\x8f\x47\x67\x7d\xba\x98\x10\x51\xb6\x9a" \
00088     "\x59\xdd\x67\x33\x79\x5c\xfe\x78\x02\x63\x0c\xb4" \
00089     "\xd6\xd0\x5a\x63\x7b\xbe\x39\x39\x0f\x00\x00\x9b" \
00090     "\xdf\x6b\x6b\xe7\xdd\x7c\xe2\xc5\x5a\x01\x87\xc5" \
00091     "\xd4\x76\xac\x0f\x33\x43\x4a\xd9\x0d\x60\x66\xe4" \
00092     "\x7f\xa5\xf5\xbf\x47\x09\x8a\xa2\x00\x00\xa4\x69" \
00093     "\xea\x01\x7a\xcd\x80\x52\xca\xf1\x89\xc8\x0a\x83" \
00094     "\x26\x20\x22\x8c\x87\xb1\x33\x36\x33\x23\x8e\x63" \
00095     "\x10\x51\x18\xa0\x2c\x4b\xaf\x10\x00\x84\x10\xdd" \
00096     "\x00\x29\x25\x92\x24\x01\x33\xdb\x29\xea\x7b\x73" \
00097     "\xbd\xa7\x80\xaa\xaa\x9c\x58\x14\x45\xf6\x35\x82" \
00098     "\x56\x10\x42\x38\x4f\xa8\x94\x82\x31\xed\x9f\xd4" \
00099     "\x03\xe4\xff\x45\x6b\xe1\x33\x73\x00\x83\xfe\xd7" \
00100     "\x3e\x44\x94\xbd\xd4\xa2\xc3\xee\xfb\xcf\x88\x6e" \
00101     "\x06\x74\xb3\x65\x00\x00\x00\x00\x49\x45\x4e\x44" \
00102     "\xae\x42\x60\x82"
00103 listViewEmptyDevice_data = \
00104     "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" \
00105     "\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10" \
00106     "\x08\x06\x00\x00\x00\x1f\xf3\xff\x61\x00\x00\x00" \
00107     "\x97\x49\x44\x41\x54\x78\x9c\x63\x60\x18\x68\xc0" \
00108     "\x88\xcc\x79\x75\xa9\xf6\x3f\x21\x0d\x62\x7a\xcd" \
00109     "\x28\x7a\xe0\x9c\x57\x97\x6a\xff\xb3\x70\x2a\x30" \
00110     "\xb0\xf1\xe9\xe1\xd4\xfc\xeb\xd3\x25\x86\x3f\xdf" \
00111     "\x1f\xa0\x18\xc2\x82\xac\x00\xa6\x19\xa6\x10\xae" \
00112     "\x08\x6a\x30\x1b\x9f\x1e\x8a\x38\x86\x01\x30\xf0" \
00113     "\xe7\xfb\x03\x86\xd7\x8c\x3e\x8d\x30\xbe\xe8\xf7" \
00114     "\x2d\xf5\xb8\x5c\x86\xd5\x00\x06\x06\x06\x06\x6d" \
00115     "\x5d\xf3\x06\x18\xfb\xd5\xa5\xda\x7a\x5c\xea\xb0" \
00116     "\x1a\xc0\xc2\xa9\x80\x12\xa0\x2c\x9c\x0a\xb8\xf4" \
00117     "\x63\x37\x00\xe6\x5f\x62\x00\x13\x51\xaa\x86\xb7" \
00118     "\x01\x28\x81\xf8\xed\xe5\x26\xf2\x0d\x40\x4e\x38" \
00119     "\x84\x41\x33\xc9\x16\xe1\x04\x00\x9f\x05\x2b\x35" \
00120     "\x07\xd6\xdf\x91\x00\x00\x00\x00\x49\x45\x4e\x44" \
00121     "\xae\x42\x60\x82"
00122 listViewDevice_data = \
00123     "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d" \
00124     "\x49\x48\x44\x52\x00\x00\x00\x10\x00\x00\x00\x10" \
00125     "\x08\x06\x00\x00\x00\x1f\xf3\xff\x61\x00\x00\x00" \
00126     "\x96\x49\x44\x41\x54\x78\x9c\x63\x60\x18\x68\xc0" \
00127     "\x88\xcc\x39\xbd\x21\xe8\x3f\x21\x0d\xa6\x01\xeb" \
00128     "\x50\xf4\xc0\x39\xa7\x37\x04\xfd\xe7\x17\x90\x63" \
00129     "\x10\x16\x51\xc2\xa9\xf9\xed\x9b\x7b\x0c\x1f\x3f" \
00130     "\x3c\x42\x31\x84\x05\x59\x01\x4c\x33\x4c\x21\x0c" \
00131     "\xc0\x0c\x16\x16\x51\x42\x11\xc7\x30\x00\x06\x3e" \
00132     "\x7e\x78\xc4\xf0\x86\x35\xb2\x11\x2e\xf0\x61\x79" \
00133     "\x3d\x2e\x97\x61\x35\x80\x81\x81\x81\xc1\xd3\x3b" \
00134     "\xb4\x01\xc6\x3e\xbd\x21\xa8\x1e\x97\x3a\xac\x06" \
00135     "\xf0\x0b\xc8\xa1\x04\x28\xbf\x80\x1c\x2e\xfd\xd8" \
00136     "\x0d\x80\xf9\x97\x18\xc0\x44\x94\xaa\xe1\x6d\x00" \
00137     "\x4a\x20\xde\xbb\x73\x80\x7c\x03\x50\x12\x0e\x41" \
00138     "\xb0\x8e\x64\x8b\x70\x02\x00\x78\x5f\x2a\xe9\x56" \
00139     "\xf2\x43\xfc\x00\x00\x00\x00\x49\x45\x4e\x44\xae" \
00140     "\x42\x60\x82"
00141 
00142 
00143 ##
00144 #  Class responsible for the tree view and information window and
00145 #     the path window that pops up for a device when set to path view.
00146 #     
00147 class selectWindow(QWidget,dbUpdate): # (wxPanel, dbUpdate, wxColumnSorterMixin):
00148 
00149     ##
00150     #  Constructor
00151     # 
00152     #       Parameters:
00153     #             @parent - the parent window (mainPanel)
00154     #             @id     - the window id set by parent
00155     #             @main   - main program object (mainWindow), 
00156     #                 for communication with instances of other classes
00157     #         
00158     def __init__(self,main,parent):
00159         QWidget.__init__(self,parent)
00160         self.main = main
00161 
00162         # The path Window
00163         self.__path = None      # The currently selected path for a device
00164         self.selectPathFrame = None # The instance of the path window
00165         
00166         # Layout and controls of the select window
00167         self.sizer = QVBoxLayout(self) #QVBox(self)
00168         self.border = 5
00169 
00170         #Tree Ctrl -> set up the first node: Subsystems
00171 #       self.sizer.Add(wxStaticText(self,-1,"LHCb System Treeview:"),0,wxEXPAND | wxALL,self.border)
00172         #label=QLabel("LHCb System Treeview:",self)
00173         #label.setMinimumSize(QSize(250,20))
00174         self.sizer.addWidget(QLabel(self,"LHCb System Treeview:"))
00175         
00176         self.systemIcon = QPixmap()
00177         self.systemIcon.loadFromData(listviewIcon0_data,"PNG")
00178         self.deviceTypesIcon = QPixmap()
00179         self.deviceTypesIcon.loadFromData(listviewIcon1_data,"PNG")
00180         self.linkTypesIcon = QPixmap()
00181         self.linkTypesIcon.loadFromData(listviewIcon2_data,"PNG")
00182         self.listViewEmptyDevice = QPixmap()
00183         self.listViewEmptyDevice.loadFromData(listViewEmptyDevice_data,"PNG")
00184         self.listViewDevice= QPixmap()
00185         self.listViewDevice.loadFromData(listViewDevice_data,"PNG")
00186 
00187         
00188 #       self.treectrl = wxTreeCtrl(self,ID_TREE_CTRL, wxDefaultPosition,wxSize(250,300),style=wxTR_HAS_BUTTONS  | wxTR_HAS_VARIABLE_ROW_HEIGHT | wxTR_SINGLE | wxRAISED_BORDER)
00189 #       self.sizer.Add(self.treectrl,0,wxEXPAND | wxALL,self.border)
00190         self.treectrl = QListView(self)
00191         self.treectrl.setMinimumSize(QSize(250,300))
00192         self.sizer.addWidget(self.treectrl)
00193         
00194         self.__treeitemids = {} # dictionary containing <treenodename : treenodeid>, because if we want to refer to a 
00195                                 # tree node, we have to use the treenode id, therfore all treenodes in the tree view
00196                                 # are added to the dictionary like this as soon as they are added.
00197         rootdata = TN_SYSTEM_HEADER # tree node type for Subsystems; (to f.ex. assign icon to the type)
00198         
00199         self.treectrl.addColumn("Subsystems")
00200         self.treeroot = QListViewItem(self.treectrl,"Subsystems",str(rootdata)) # self.treectrl.AddRoot("Subsystems",-1,-1,wxTreeItemData(rootdata)) # Root: Subsystems, we get the
00201                                                                                            # tree node id in return
00202         self.treeroot.setPixmap(0,self.systemIcon)
00203         self.__treeitemids["Subsystems"] = self.treeroot
00204         self.treectrl.setEnabled(False)
00205         
00206         self.connect(self.treectrl,SIGNAL("mouseButtonClicked(int,QListViewItem*,const QPoint&,int)"),self.OnClick) # EVT_TREE_ITEM_ACTIVATED(self,ID_TREE_CTRL,self.OnChoice) #double click; if not expanded, expand
00207         self.connect(self.treectrl,SIGNAL("doubleClicked(QListViewItem*,const QPoint&,int)"),self.OnChoice) # EVT_TREE_ITEM_ACTIVATED(self,ID_TREE_CTRL,self.OnChoice) #double click; if not expanded, expand
00208         self.connect(self.treectrl,SIGNAL("expanded(QListViewItem*)"), self.OnExpanding) # EVT_TREE_ITEM_EXPANDING(self,ID_TREE_CTRL,self.OnExpanding) #prevent expand, and do it ourselves
00209         #self.connect(self.treectrl,SIGNAL("selectionChanged(QListViewItem*)"), self.slotOnSelect) # EVT_TREE_SEL_CHANGED(self,ID_TREE_CTRL,self.OnSelect) #one click, do not expand  
00210               
00211         # Filter by spare parts/non-spare parts
00212         # Spare parts -> view only spare parts
00213         options = ['All','Spares only','In place only']
00214 #         self.sparepartsCtrl = wxComboBox(self, ID_SPAREPARTSCHOICE, options[0], size = (180, 25), style = wxCB_READONLY | wxCB_SORT, choices = options)
00215         self.sizer.addWidget(QLabel(self, "Filter by spare parts"))
00216         self.sparepartsCtrl=QComboBox(False, self)
00217         self.sparepartsCtrl.setEnabled(True) # self.sparepartsCtrl.Enable(True)
00218         self.sparepartsCtrl.insertItem("All")
00219         self.sparepartsCtrl.insertItem("Spares only")
00220         self.sparepartsCtrl.insertItem("In place only")
00221         self.sparepartsCtrl.setGeometry(0,0,250,25)
00222         self.sizer.addWidget(self.sparepartsCtrl)
00223 
00224         
00225 #         EVT_COMBOBOX(self, ID_SPAREPARTSCHOICE, self.OnRestrictedSparePartChoice)
00226 
00227         # Link Type -> view only links of given link type
00228         self.linktyperestrictchk = QCheckBox(self,"View only links of this linktype:")
00229         self.linktyperestrictchk.setText("View only links of this linktype:")
00230         self.linktyperestrictchk.setGeometry(0,0,250,25)
00231         self.linktyperestrictchk.setChecked(False)
00232         self.linktyperestrictchk.setEnabled(False)
00233         self.connect(self.linktyperestrictchk,SIGNAL("toggled(bool)"),self.OnCheckRestrict)
00234         self.sizer.addWidget(self.linktyperestrictchk)
00235         
00236         self.main.RestrictLinkType(False) #make linktype checkbox take effect
00237         
00238         #EVT_CHECKBOX(self,ID_LINKTYPERESTRICT,self.OnCheckRestrict)
00239         
00240         
00241        
00242 #         EVT_COMBOBOX(self, ID_LINKTYPECHOICE, self.OnRestrictedLinkTypeChoice)
00243 #         self.sizer.Add(self.linktypeCtrl, 0, 
00244 #                        wxEXPAND | wxLEFT | wxTOP | wxRIGHT, self.border)
00245         
00246         self.linktypeCtrl = QComboBox(self, None) #self.linktypeCtrl = wxComboBox(self, ID_LINKTYPECHOICE, "", size = (180, 25), style = wxCB_READONLY | wxCB_SORT)
00247         self.linktypeCtrl.setEnabled(False)
00248         self.linktypeCtrl.insertItem("Default")
00249         self.linktypeCtrl.setGeometry(0,0,200,25)
00250         self.sizer.addWidget(self.linktypeCtrl)
00251         self.connect(self.linktypeCtrl,SIGNAL("activated(int)"),self.OnRestrictedLinkTypeChoice)
00252          # Information window
00253         
00254         self.sizer.addWidget(QLabel(self, "Information"))
00255          #self.sizer.Add(wxStaticText(self, -1, \
00256 #       "Information"), 0, wxEXPAND | wxLEFT | wxTOP, self.border)
00257 #       self.infoCtrl = wxListCtrl(self, ID_DEVINFO, size = (180,150), 
00258 #       style = wxLC_REPORT | wxLC_SINGLE_SEL | \
00259 #       wxLC_HRULES | wxLC_VRULES | wxSIMPLE_BORDER) # Report view, like a list
00260         self.infoCtrl = QListView(self)
00261         self.infoCtrl.addColumn("Attribute")
00262         self.infoCtrl.addColumn("Value")
00263         self.infoCtrl.setAllColumnsShowFocus(True)
00264         self.sizer.addWidget(self.infoCtrl)
00265         
00266         self.connect(self.infoCtrl,SIGNAL("doubleClicked(QListViewItem*,const QPoint&,int)"),self.InfoCtrlDoubleClick)
00267 #       EVT_LIST_ITEM_SELECTED(self,ID_DEVINFO,self.OnDeviceInfoSelected)
00268 #       EVT_LIST_ITEM_ACTIVATED(self,ID_DEVINFO,self.OnDeviceInfoSelected)
00269 
00270         #WALID_OBSELETE? self.my_data = [] # Needed to sort the list ctrl
00271         self.itemDataMap = {} # This is also needed for sorting the list ctrl
00272 
00273         self.prevvalue = ""
00274         self.prevrestrict = False
00275 
00276     def myCollapseAndReset(self, item):
00277         for i in range(item.childCount()):
00278                 tmp_ = item.firstChild()
00279                 item.takeItem(tmp_)
00280                 tmpText_=str(tmp_.text(0))
00281                 if tmpText_ in self.__treeitemids.keys():
00282                         del self.__treeitemids[tmpText_]
00283                         
00284     def CollapseInactiveSystems(self, item):
00285         for i in range(item.childCount()):
00286                 tmp_ = item.firstChild()
00287                 item.takeItem(tmp_)
00288                 tmpText_=str(tmp_.text(0))
00289                 if tmpText_ in self.__treeitemids.keys():
00290                         del self.__treeitemids[tmpText_]
00291                         
00292     def InfoCtrlDoubleClick(self,item,point,col):
00293         if col==0:
00294                 return
00295         if item and str(item.text(0))=="url" and str(item.text(1))!="":
00296                 try:
00297                         webbrowser.open_new(str(item.text(1)))
00298                 except:
00299                         self.main.ShowError("Cannot Open the file",ERR_ERROR,True)
00300         # elif col==1 and item:
00301                 # item.setRenameEnabled(1,True)
00302                 # item.startRename(1)
00303                 # print "rename"
00304 
00305     ##
00306     #  Since we need the tree node/item id to do something with
00307     #   a tree node, this function will return the tree node id in
00308     #   the tree view, if it exists.
00309     # 
00310     #   Parameters:
00311     #   @value - The name of the tree node as seen by the user.
00312     # 
00313     #   !Return - The tree node id as a TreeItemID Object, or a KeyError Exception if
00314     #             an error occurs.
00315     #   
00316     def GetItemID(self,value):
00317         
00318         try:
00319                 if self.__treeitemids[value].__class__ != QListViewItem: #or (self.__treeitemids[value].__class__ == QListViewItem and not self.__treeitemids[value].IsOk())
00320                                 # We check whether we have added the tree node to the tree view, if it is
00321                                 # of the correct type (treeitemidptr) and that the value is valid
00322                                 # If any of these fail, a keyerror is arised.
00323                         raise KeyError, "We did not find a valid TreeItemID for the current object."
00324                 
00325                 else: # We have a valid tree item id, return it
00326                    return self.__treeitemids[value]
00327            
00328         except KeyError,err:
00329                 raise KeyError,err # We just throw the KeyError further up..
00330         
00331     ##
00332     #  Remove a tree node/item from the tree view. Usually because
00333     #   the object has been deleted by the user.
00334     # 
00335     #   Parameters:
00336     #   @id     - the tree node id of the item that we want to delete
00337     #   @parent - the tree node name/string of the parent to the item that
00338     #   we want to delete.
00339     # 
00340     #   !Return - Raise a KeyError exception if some error occured
00341     #   
00342     def RemoveItem(self,id,parent):
00343         
00344         self.main.RefreshObjectBoxData() # We removed some object; need to update combo boxes etc.
00345         
00346         try:
00347                 parentid = self.GetItemID(parent) # tree node id of the parent
00348                 #if self.treectrl.IsExpanded(parentid): # if parent is expanded; we can delete the child
00349                 self.treectrl.Delete(id)
00350                 
00351         except KeyError,err:
00352                 raise KeyError,"We could not delete the object from the tree view: " + str(err)
00353 
00354     ##
00355     #  We set the tree item node entry in the dictionary to -1, which
00356     #   is not a valid treeitemID, because the tree item node has been deleted
00357     #   from the tree view.
00358     # 
00359     #   Parameters:
00360     #   @item - tree item name/string of the deleted object
00361     #   
00362     def SetItemToDeleted(self,item):
00363         self.__treeitemids[item] = -1
00364 
00365     ##
00366     #  Sometimes we need to collapse a tree node, and then expand it again
00367     #   automatically; f.ex. if new nodes have been added as children of the tree
00368     #   node in question, or children have been deleted.
00369     # 
00370     #   We therefore need a new expand to sort the tree node names alphabetically.
00371     # 
00372     #   Parameters:
00373     #   @id - tree node id of the tree node that should be collapsed and expanded.
00374     #   @doexpand - Whether the node should be expanded after the collapse or not.
00375     #   @set_to_minus_one - Whether the level in the visual window should be set to
00376     #   device level (-1) or not.
00377     #   
00378     def CollapseAndExpand(self,id,doexpand=True,set_to_minus_one=True):
00379         
00380         try:
00381                 self.treectrl.CollapseAndReset(id) #Collapse the node and remove all its child nodes
00382                 self.OnChoice(None,False,id,doexpand,set_to_minus_one)
00383         except KeyError,err:
00384                 self.main.ShowError("A TreeView error occured: " + str(err),ERR_ERROR)
00385                 
00386     ##
00387     #  Add an item (DeviceType, Device) to the tree.
00388     #       type : the type of the item : TN_DEVICETYPE, TN_DEVICE
00389     #   
00390     def AddItem(self,item,type):
00391         for system in item.GetSystem().split(","):
00392                 if type == TN_DEVICETYPE:
00393                         itemData = str(TN_DEVICETYPE)+"|"+system
00394                 elif type == TN_DEVICE:
00395                         itemData = str(TN_DEVICE)+"|"+system
00396                 elif type == TN_PORT:
00397                         itemData = str(TN_PORT)+"|"+system
00398                 else:
00399                         return
00400                 try:
00401                         res = self.treectrl.findItem(itemData,1)
00402                         parent = res.parent()
00403                         newItem = QListViewItem(parent,item.GetName(),itemData)
00404                 except:
00405                         print "Item : "+item.GetName()+" was not added to the navigation Tree"
00406                 # mySystem = self.treectrl.find(system,0)
00407                 # if type == TN_DEVICETYPE:
00408                         # newItem = QListView(self.treectrl.find("Device types",1),item.GetName(),
00409     '''def AddItem(self,id,itm,type):
00410         """ Add a tree node to the tree view. Usually because a new object
00411         has been created, or that an object has been renamed.
00412 
00413         Parameters:
00414         @id - tree node ID of the parent to the new node that will be added
00415         @itm -  the tree node name/string to be added
00416         @type - the tree node type that will be added (Device Type, Device, Link etc)
00417         """
00418         
00419         ## self.main.RefreshObjectBoxData() # If we added a new node; we will have to refresh combo boxes with new data
00420 
00421         try:
00422                 if self.treectrl.IsExpanded(id): # We only add a new child node if the parent is expanded
00423                         system = str(self.treectrl.GetPyData(id)).split("|")[1] # get the subsystem for the node
00424                         itmid = self.treectrl.AppendItem(id,itm,data=wxTreeItemData(str(type) + "|" + str(system))) # add
00425                         self.__treeitemids[itm] = itmid # tree item id to dictionary
00426                         self.treectrl.SortChildren(id) # sort the children alphabetically
00427         except KeyError,err:
00428                 self.main.ShowError("A TreeView error occured: " + str(err),ERR_ERROR)
00429         '''
00430     ##
00431     #  When a user clicks on the check box to restrict the view of the links
00432     #   to a given link type.
00433     #   
00434     def OnCheckRestrict(self,event):
00435 
00436         if self.linktyperestrictchk.isChecked(): # Restrict
00437                 #self.linktypeCtrl.Enable(True)
00438                 if self.linktypeCtrl.currentText() != "":
00439                         self.main.RestrictLinkType(True) #make linktype checkbox take effect
00440                         self.main.SetRestrictedLinkType(self.linktypeCtrl.currentText())
00441                 else:
00442                         self.main.RestrictLinkType(False) #make linktype checkbox take effect
00443                         self.main.SetRestrictedLinkType("")
00444         else: # No restriction
00445                 #self.linktypeCtrl.Enable(False)
00446                 self.main.RestrictLinkType(False) #make linktype checkbox take effect
00447                 self.main.SetRestrictedLinkType("")
00448         
00449         res = self.main.GetVisWindow().ViewOnlyLinksOfGivenType()
00450         self.main.GetVisWindow().canvas.update()
00451         # if res == False:
00452                 #self.linktyperestrictchk.setChecked(False)
00453                 # self.main.SetRestrictedLinkType("")
00454                 # self.main.RestrictLinkType(False) #make linktype checkbox take effect
00455                 
00456     ##
00457     #  When user changes spare parts view 
00458     def OnRestrictedSparePartChoice(self,event=''):
00459         self.main.SetRestrictedSparePart(self.sparepartsCtrl.currentText()) #sets the desired view
00460         self.SystemChanged() #collapses tree view and re-opens it after updating contents
00461 
00462     ##
00463     #  When a user changes restriction of the link type in the combo box, to
00464     #   another link type.
00465     #   
00466     def OnRestrictedLinkTypeChoice(self,event):
00467         #self.linktypeCtrl.Enable(True)
00468         if not self.linktyperestrictchk.isChecked():
00469                 return 
00470         self.main.RestrictLinkType(self.linktyperestrictchk.isChecked()) #make linktype checkbox take effect
00471         self.main.SetRestrictedLinkType(str(self.linktypeCtrl.currentText()))
00472         
00473         res = self.main.GetVisWindow().ViewOnlyLinksOfGivenType()
00474         self.main.GetVisWindow().canvas.update()
00475         ## Je ne vois pas trop a quoi ca sert ce qu'il a ici en bas alors je le met pas pour le moment 
00476         # if res == False:
00477                 # self.main.RestrictLinkType() #make linktype checkbox take effect
00478                 # self.main.SetRestrictedLinkType(self.prevvalue)
00479                 # self.linktypeCtrl.SetValue(self.prevvalue)
00480                 
00481         # else:
00482                 # self.prevrestrict = self.main.IsLinkTypeRestricted()
00483                 # self.prevvalue = self.linktypeCtrl.GetValue()
00484 
00485                 
00486     ##
00487     #  If the user selects (single-click) an info row in the
00488     #   list control, a tooltip text will appear. this tooltip text is available
00489     #   because it is not always possible to read the whole string/text in the
00490     #   information window, but the whole information text will be visible in this tooltip window.
00491     #   
00492     def OnDeviceInfoSelected(self,event):
00493 
00494         my_sel_item = event.GetIndex()
00495         my_col_0 = self.infoCtrl.GetItem(my_sel_item,0)
00496         my_col_1 = self.infoCtrl.GetItem(my_sel_item,1)
00497         self.infoCtrl.SetToolTip(wxToolTip(my_col_0.GetText() + " : " + my_col_1.GetText()))
00498         
00499     ##
00500     #  If a subsystem change is detected (the active subsystem is changed)
00501     #   this method will be called. Here we collapse all nodes of the previous chosen
00502     #   subsystem, in fact; everything down to the tree node root item will be collapsed.
00503     #   
00504     def SystemChanged(self):
00505         try:
00506                 self.self.myCollapseAndReset(self.treeroot) #CollapseAndReset(self.treeroot) #collapse to root when new sub system is chosen outside this module, user will have to chose item him/herself
00507                 self.UpdateSystems() # We will try to get an update of subsystems available
00508                 self.treeroot.sortChildItem(0,True) #self.treectrl.SortChildren(self.treeroot) # Sort the subsystems found
00509                 self.treeroot.setOpen(True) # self.treectrl.Expand(self.treeroot) # And expand the root; so that the user sees all the new subsystems
00510 
00511                 nr = self.treeroot.childCount() #self.treectrl.GetChildrenCount(self.treeroot,False) # After adding the children, we count them
00512         
00513                 i = 0
00514                 cookie = 6543
00515                 while i < nr: # We iterate through all the subsystems too look for the active subsystem
00516                 
00517                         # We then get the tree node item (id) and cookie for each tree node; 
00518                         # we have to add a cookie to each tree node, so that we can keep track of
00519                         # the current retrieval of tree elements
00520                         if i == 0:
00521                                 itm,cookie = self.treeroot.firstChild() #self.treectrl.GetFirstChild(self.treeroot)# ,cookie), needed in linux?
00522                         else:
00523                                 itm,cookie = self.treeroot.nextSibling() #self.treectrl.GetNextChild(self.treeroot,cookie)
00524 
00525                         # For the active sub system; we update its children (and expand it)
00526                         if itm.text() == self.main.GetActiveSystem():
00527                                 itm.setSelected(True) # self.treectrl.SelectItem(itm)
00528                                 self.UpdateSystem(itm,False)
00529                                 itm.sortChildItem(0,True) # self.treectrl.SortChildren(itm)
00530                                 itm.setOpen(True) # self.treectrl.Expand(itm)
00531                                 break
00532                         i += 1
00533 
00534         except KeyError,err:
00535                 self.main.ShowError("A tree view error occured: " + str(err),ERR_ERROR)
00536 
00537     ##
00538     #  This method is called from another class as a reaction to that
00539     #   the ConfDB status changed. 
00540     #   React on database state change event          
00541     # 
00542     #   Call UpdateDb to change things to the current state
00543     #   of the ConfDB
00544     #         
00545     def OnDbUpdate(self, evtReason, cdb):
00546         self.UpdateDb(evtReason, cdb)
00547 
00548     ##
00549     #  Update controls on a database state change. This method
00550     #   is usually called by the MainWindow OnDbUpdate
00551     #     
00552     #             evtReason -- not used here, from interface definition
00553     #             cdb -- If not connected to database (cdb == None), delete all the 
00554     #                    contents of the controls.
00555     #                    If connected (was disconnected), update content of the controls.
00556     #         
00557     def UpdateDb(self, evtReason, cdb):
00558         self.setCursor(QCursor(Qt.WaitCursor)) # wxBeginBusyCursor()
00559         try:
00560                 self.main.SetCdb(cdb)
00561 
00562                 if not cdb: # The user may have disconnected, or the database disconnected itself
00563                     self.main.ShowError("Connection to the ConfDB was lost!",ERR_INFORMATION)
00564                     self.main.ResetActiveObjects() # Reset active objects
00565                     self.infoCtrl.clear() #DeleteAllItems() # Reset information window
00566                     self.main.GetVisWindow().Clear() # Reset visual window
00567                     self.myCollapseAndReset(self.treeroot) # self.treectrl.CollapseAndReset(self.treeroot) # Reset tree view
00568                     # Also update miniature window to reset itself
00569                 else: # Connected
00570                     self.main.ShowError("Connection to the ConfDB is now set.",ERR_INFORMATION)
00571                     self.UpdateSystems() # Update the root to get the subsystems as its children
00572                     self.expandInCode = True
00573                     self.treeroot.setOpen(True) # self.treectrl.Expand(self.treeroot) # Expand the root
00574                     self.treectrl.setEnabled(True)      
00575         except KeyError,err:
00576                 self.main.ShowError("A tree view error occured: " + str(err),ERR_ERROR)
00577                 self.setCursor(QCursor(Qt.ArrowCursor))
00578 
00579         self.setCursor(QCursor(Qt.ArrowCursor)) # wxEndBusyCursor()
00580 
00581     def myListViewMouseEvent(self,button, item):
00582         if(item==None):
00583                 return
00584         if (button==1):
00585                 self.OnSelect(item) #one click, do not expand
00586         else:
00587                 self.OnChoice(item) #right click; if not expanded, expand
00588 
00589     def OnClick(self,button,item,point,column):
00590         global timer
00591         global pendingItem
00592         pendingItem = item
00593         timer = QTimer(self);   
00594         self.connect(timer,SIGNAL("timeout()"),self.OnSelect);
00595         timer.start( 100, True ); #100 micro-seconds single-shot timer
00596 
00597     ##
00598     #  A tree node was selected with a single-click.
00599     #   Treat it the same wat as a double-click, wo. expanding
00600     #   it.
00601     # 
00602     #   Parameters:
00603     #   @event - information about the node that was clicked
00604     #   
00605     def OnSelect(self):
00606         global pendingItem
00607         item = pendingItem
00608         if item:
00609                 type = str(item.text(1)) #self.treectrl.GetPyData(item)
00610                 text = str(item.text(0)) #self.treectrl.GetItemText(item)
00611                 if type != str(TN_SYSTEM_HEADER) and type != str(TN_SYSTEM):
00612                         data = type.split("|")
00613                         type = int(data[0])
00614                         system = data[1]
00615                 if type == TN_DEVICETYPE:
00616                         self.UpdateDeviceType(item,system,False)
00617                 elif type == TN_LINKTYPE:
00618                         self.UpdateLinkType(item,system,False)
00619                 elif type == TN_DEVICE:
00620                         self.UpdateDevice(item,system,False)
00621                 elif type == TN_PORT:
00622                         self.UpdatePort(item,system,False)
00623                 #self.OnChoice(event,False,None,False) # OnChoice - our main method for handling tree view clicks
00624 
00625 
00626     ##
00627     #  When a treeItem is expanded we close the other treeItem located at the same level in the tree.
00628     #   
00629     #   Parameters:
00630     #   @event - The node that is expanding
00631     #   
00632     def OnExpanding(self,event):
00633         try:
00634                 item=event.parent().firstChild()
00635         except:
00636                 return
00637         while item:
00638                 if item != event:
00639                         item.setOpen(False)
00640                 item = item.nextSibling()
00641 
00642 
00643     ##
00644     #  This method was called in one of the three situations:
00645     #   1. Single-click: doexpand=False, rest default
00646     #   2. Double-click: all defaults
00647     #   3. On expanding of a tree node, onexpand=True, rest default
00648     # 
00649     #   Parameters:
00650     #   @event - information about the tree node that is chosen
00651     #   @onexpand - whether the node chosen is about to expand or not (OnExpand event)
00652     #   @item     - the tree node item object that is chosen
00653     #   @doexpand - whether the chosen tree item should be expanded or not
00654     #   @set_to_minus_one - whether we should change to device level (-1) in the visual window
00655     #   or not.
00656     #   
00657     def OnChoice(self,item,point=QPoint(0,0),column=0,onexpand=False,doexpand=True,set_to_minus_one=True):
00658 
00659         global timer
00660         global pendingItem
00661         timer.stop()
00662         pendingItem = 0
00663         
00664         if not item or item.isOpen() or (self.main.GetUserMode() == ID_CREATION_MODE and item.firstChild()):
00665                 return
00666         type = str(item.text(1)) #self.treectrl.GetPyData(item)
00667         text = str(item.text(0)) #self.treectrl.GetItemText(item)       
00668         # We get tree item data and tree item text/name of the node we have chosen
00669                 # data = type.split("|")
00670                 # type = int(data[0])
00671                 # system = data[1]
00672                 #print item.text(0)
00673                 #print item.text(1)
00674         self.main.ResetActiveObjects() # Reset all active objects -> only the currently selected object can be active
00675         # This is for undo/redo functionality; whether we have changed device within neighbor or path view mode
00676         # if we have, since last undo/redo, we will not try to add the new undo/redo objects to the window.
00677         if (self.main.GetViewMode() == ID_SUCCESSORS_MODE or self.main.GetViewMode() == ID_PATHS_MODE):
00678                 self.main.SetPrevView(self.main.GetCurrentView())
00679                 self.main.WhenChangeView()
00680 
00681         if type == str(TN_SYSTEM_HEADER): # If we clicked on "Subsystems"
00682                 self.main.GetVisWindow().SetLevelZoom(0) # LHCb system level, show the illustration
00683                 return
00684                 # if onexpand: return True #Already expanding, continue expanding (clicked plus-sign)
00685         elif type == str(TN_SYSTEM):
00686                 ##self.main.setCursor(QCursor(Qt.WaitCursor))
00687                 if self.main.GetActiveSystem() != text: # If we changed subsystem
00688                         self.main.GetVisWindow().Clear() # Changed system, clear!!!
00689                         self.main.SetActiveSystem(text,self)
00690                         self.main.GetVisWindow().canvas.update()
00691                         if text=="Spare devices" and not item.firstChild():
00692                                 tmp = waiter(None,"Loading data from ConfDB")
00693                                 self.UpdateSystem(item,True,True)
00694                                 tmp.accept()
00695                 ##self.main.setCursor(QCursor(Qt.ArrowCursor))
00696                 return
00697                 #self.treectrl.Collapse(self.treeroot)
00698                 #TODO: issue: when we change to a new subsystem, the other open subsystem should
00699                 #be collapsed, but in windows it seems to be difficult to automatically expand nodes
00700                 #in code
00701                 ##self.UpdateSystem(item,True,doexpand) # Add children to chosen subsystem
00702                 self.main.GetVisWindow().Clear() # Clear Visual Window because we changed system (...)
00703                 #self.main.GetVisWindow().SetLevelZoom(0) # Change level zoom?
00704         else: # Any other tree node type
00705                 if set_to_minus_one:
00706                         self.main.GetVisWindow().SetLevelZoom(-1) # Device level
00707                 
00708                 data = type.split("|")
00709                 type = int(data[0])
00710                 system = data[1]
00711 
00712                 if type == TN_LINKTYPE_HEADER:
00713                         self.UpdateLinkTypes(item,system,doexpand)
00714                 elif type == TN_DEVICETYPE_HEADER:
00715                         self.UpdateDeviceTypes(item,system,doexpand)
00716                 elif type == TN_DEVICETYPE:
00717                         self.UpdateDeviceType(item,system,doexpand)
00718                 elif type == TN_LINKTYPE:
00719                         self.UpdateLinkType(item,system,doexpand)
00720                 elif type == TN_DEVICE:
00721                         self.UpdateDevice(item,system,doexpand)
00722                         # if item.firstChild(): item.setPixmap(0,self.listViewDevice)   # Pour ajouter des iconnes au devices
00723                         # else: item.setPixmap(0,self.listViewEmptyDevice)
00724                 elif type == TN_PORT:
00725                         pass #self.UpdatePort(item,system,False)
00726                 else:
00727                         self.main.ShowError("An invalid treeitem was chosen: " + str(type),ERR_ERROR)
00728         return
00729         if not onexpand and doexpand:
00730                 item.setOpen(True) #self.treectrl.Expand(item)
00731 
00732     ############################################################################
00733     # Update Functions
00734     ############################################################################
00735 
00736     ##
00737     #  Update subsystems available in ConfDB.
00738     # 
00739     #   Parameters:
00740     #   @update - whether we should update and add children to the child nodes of this node
00741     #   @doexpand - whether this node should be expanded
00742     #         
00743     def UpdateSystems(self,update=False,doexpand=True):
00744         self.setCursor(QCursor(Qt.WaitCursor)) # wxBeginBusyCursor()
00745         self.infoCtrl.clear() # self.infoCtrl.DeleteAllItems() # Clear information window
00746         self.linktypeCtrl.clear()      # Clear combobox for link type
00747         if doexpand:
00748                 #the following instruction just remove the treeroot from the treectrl but it does not delete the treeroot that's why we have reinitialise the treeroot with the instruction comming after.
00749                 self.myCollapseAndReset(self.treeroot) #self.treectrl.CollapseAndReset(self.treeroot) # Collapse root
00750         if not self.main.GetCdb(): #no connection
00751                 self.main.ShowError("Not connected to database!",ERR_INFORMATION)
00752                 self.main.SetActiveSystem(None,"select") # No Active subsystem
00753         else:
00754                 my_db = self.main.GetCdb() # new db
00755                 if doexpand:
00756                         systems = my_db.GetSubSystems()
00757                         if systems and len(systems) > 0:
00758                                 self.main.SetAvailableSystems(systems)
00759                                 my_subsystems = []
00760                                 progress=QProgressDialog( "Loading data from ConfigDB...", "Abort", len(systems), self, "progress", True) #Progress dialog
00761                                 i = 0
00762                                 for system in systems:
00763                                         if str(system.GetName()) not in do_not_show_systems:
00764                                                 i += 1
00765                                                 progress.setProgress(i) #Progress dialog
00766                                                 progress.setLabelText(str(system.GetName())) #Progress dialog
00767                                                 self.main.app.processEvents()
00768                                                 if progress.wasCanceled():
00769                                                         break
00770                                                 itmdata = TN_SYSTEM 
00771                                                 my_currsystem = QListViewItem(self.treeroot,str(system.GetName()),str(itmdata)) # self.treectrl.AppendItem(self.treeroot,str(system.GetName()),-1,-1,wxTreeItemData(itmdata))
00772                                                 if str(system.GetName()) != "Spare devices":
00773                                                     self.UpdateSystem(my_currsystem,True,True)
00774                                                 my_subsystems.append(my_currsystem)
00775                                                 self.__treeitemids[str(system.GetName())] = my_currsystem #WAL_OBSELETE ??
00776                                 progress.setProgress(len(systems)) #Progress dialog
00777 
00778                                                 #self.treectrl.SortChildren(self.treeroot)
00779                                 self.treeroot.sortChildItems(0,True)  # We will sort one time at the end of the boucle that's will be better
00780                                 if update:
00781                                         for subsystem in my_subsystems:
00782                                                 if subsystem.GetName()!="Spare devices":
00783                                                         self.UpdateSystem(subsystem,True,True)
00784                                 self.treeroot.setEnabled(True)
00785                                 self.main.ShowError(str(len(systems)) + " available subsystems retrieved from ConfDB.",ERR_INFORMATION)
00786 
00787                         else: #No systems available
00788                                 self.main.SetAvailableSystems([])
00789                                 self.main.ShowError("No Subsystems found in the ConfDB." + str(my_db.GetErrorMessage()),ERR_CRITICAL)
00790 
00791         self.setCursor(QCursor(Qt.ArrowCursor))
00792  
00793     ##
00794     #  A subsystem is selected in the tree view. Update it.
00795     # 
00796     #   Parameters:
00797     #   @treeitem - The tree item id of the subsystem chosen
00798     #   @update - whether the child nodes of this node should be update or not
00799     #   @doexpand - whether this node should be expanded or not
00800     #   
00801     def UpdateSystem(self,treeitem,update=False,doexpand=True):
00802         #self.main.app.setOverrideCursor(QCursor(Qt.WaitCursor))
00803 
00804         
00805         #Collapse other subsystem if open
00806         activesystem = self.main.GetActiveSystem()
00807         if activesystem != str(treeitem.text(0)): #self.treectrl.GetItemText(treeitem):
00808                 try:
00809                         treeid = self.GetItemID(activesystem)
00810 
00811                         ##self.myCollapseAndReset(treeid) #self.treectrl.CollapseAndReset(treeid)
00812                 except KeyError,err:
00813                         pass #system not found, ok, nothing to collapse
00814         else:   
00815                 if doexpand:
00816                         pass ##self.myCollapseAndReset(treeitem) #self.treectrl.CollapseAndReset(treeitem)
00817         self.infoCtrl.clear() #self.infoCtrl.DeleteAllItems()
00818         self.linktypeCtrl.clear()
00819 
00820         if not self.main.GetCdb(): #no connection
00821             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
00822             self.main.SetActiveSystem(None,"select") #ok?
00823             self.SystemChanged()
00824         else:
00825             #enable export as text option on File -> menu
00826             self.main.EnableDisableExportText(True)
00827 
00828             system = str(treeitem.text(0)) #self.treectrl.GetItemText(treeitem)
00829             self.main.SetActiveSystem(system,"select")
00830             if system == "MUON":
00831                 self.main.GetVisWindow().SetLevelZoom(0) #cause we have to f.ex. choose which MUON station (1-5) or add the stations as children of MUON in the three
00832             else:
00833                 self.main.GetVisWindow().SetLevelZoom(1) #have to define specific for each system
00834 
00835             if doexpand:
00836                     if system!="Spare devices":
00837                         itmdata = str(TN_DEVICETYPE_HEADER) + "|" + str(system)
00838                         devtype_itm = QListViewItem(treeitem,"Device types",itmdata) #self.treectrl.AppendItem(treeitem,"Device types",-1,-1,wxTreeItemData(itmdata))
00839                         devtype_itm.setPixmap(0,self.deviceTypesIcon)
00840                         self.__treeitemids["Device types"] = devtype_itm
00841                         itmdata = str(TN_LINKTYPE_HEADER) + "|" + str(system)
00842                         linktype_itm = QListViewItem(treeitem,"Link types",itmdata)#self.treectrl.AppendItem(treeitem,"Link types",-1,-1,wxTreeItemData(itmdata))
00843                         linktype_itm.setPixmap(0,self.linkTypesIcon)
00844                         self.__treeitemids["Link types"] = linktype_itm
00845                     else:
00846                         itmdata = str(TN_DEVICETYPE_HEADER) + "|" + str(system)
00847                         devtype_itm = QListViewItem(treeitem,"Spare hw types",itmdata) #self.treectrl.AppendItem(treeitem,"Spare hw types",-1,-1,wxTreeItemData(itmdata))
00848                         self.__treeitemids["Spare hw types"] = devtype_itm
00849 
00850                     self.main.ShowError(str(treeitem.text(0)) + " subsystem selected.",ERR_INFORMATION)
00851                     #WALPROB self.main.RefreshObjectBoxData() #update device types and link type in toolbar
00852                     if update:
00853                         self.UpdateDeviceTypes(devtype_itm,system)
00854                         
00855                         devtype_itm.sortChildItems(0,True) #self.treectrl.SortChildren(devtype_itm)
00856                         if system!="Spare devices":
00857                             self.UpdateLinkTypes(linktype_itm,system)
00858                             linktype_itm.sortChildItems(0,True) #self.treectrl.SortChildren(linktype_itm)
00859                         
00860         #self.main.app.setOverrideCursor(QCursor(Qt.ArrowCursor))
00861         
00862 
00863 
00864     ##
00865     #  Chose DeviceTypes item in treeview, update it.
00866     # 
00867     #   parameters:
00868     #   @treeitem - treeitem id of the selected tree item
00869     #   @system   - in which system we are in (and the selected tree item)
00870     #   @doexpand - whether the DeviceTypes nodes should be expanded or not
00871     #         
00872     def UpdateDeviceTypes(self,treeitem,system,doexpand=True):
00873 
00874         self.setCursor(QCursor(Qt.WaitCursor)) 
00875         
00876         if doexpand:
00877                 self.myCollapseAndReset(treeitem) #self.treectrl.CollapseAndReset(treeitem)
00878 
00879 
00880         if not self.main.GetCdb():
00881             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
00882             self.main.SetActiveSystem(None,"select") #ok?
00883             self.SystemChanged()
00884         elif not self.main.GetActiveSystem():
00885             self.main.ShowError("No subsystem available.",ERR_CRITICAL)
00886         else:
00887             if self.main.GetActiveSystem() != system:
00888                 self.main.SetActiveSystem(system,"select")
00889 
00890             if doexpand:
00891                         if self.main.GetActiveSystem()!='Spare devices':
00892                                 subsystem = SubSystem(self.main.GetCfg(),self.main.GetActiveSystem())   #subsystem object
00893                                 types = subsystem.GetDeviceTypes()              #getdevicestypes from currently selected/active system
00894                                 #set devicetable in main or is it already set?
00895                         else:
00896                                 types=self.main.GetCdb().GetAllSpareHWTypes()
00897                         if types == False:
00898                                 self.main.ShowError(subsystem.GetErrorMessage(),ERR_ERROR)
00899                         else:
00900                                 if len(types) == 0:
00901                                         self.main.ShowError(subsystem.GetErrorMessage(),ERR_INFORMATION)
00902                                 else:
00903                                         itmdata = str(TN_DEVICETYPE) + "|" + str(system)
00904                                         for type in types:
00905                                                 tmp_devtype = QListViewItem(treeitem,str(type),str(itmdata)) #self.treectrl.AppendItem(treeitem,type,-1,-1,wxTreeItemData(itmdata))
00906                                                 self.__treeitemids[type] = tmp_devtype
00907                                         self.treeroot.sortChildItems(0,True) #self.treectrl.SortChildren(treeitem)
00908 
00909                                         #WALPROB self.main.RefreshObjectBoxData() #update link types and device types in toolbar
00910                         
00911 
00912         self.setCursor(QCursor(Qt.ArrowCursor)) #wxEndBusyCursor() 
00913 
00914     ##
00915     #  Chose LinkTypes item in tree view, update it.
00916     # 
00917     #   parameters:
00918     #   @treeitem - tree item id of the selected tree item
00919     #   @system - subsystem of the selected tree item
00920     #   @doexpand - whether the tree item should be expanded or not
00921     #   
00922     def UpdateLinkTypes(self,treeitem,system,doexpand=True):
00923 
00924         self.setCursor(QCursor(Qt.WaitCursor))
00925 
00926         if doexpand:
00927                 self.myCollapseAndReset(treeitem) # self.treectrl.CollapseAndReset(treeitem)
00928 
00929         if not self.main.GetCdb():
00930             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
00931             self.main.SetActiveSystem(None,"select")
00932             self.SystemChanged()
00933         elif not self.main.GetActiveSystem():
00934             self.main.ShowError("No subsystem is available.",ERR_CRITICAL)
00935         else:
00936             if self.main.GetActiveSystem() != system:
00937                 self.main.SetActiveSystem(system,"select")
00938 
00939             if doexpand:
00940                     subsystem = SubSystem(self.main.GetCfg(),self.main.GetActiveSystem())       #subsystem object
00941                     linktypes_raw = subsystem.GetLinkTypes()            #getlinktypes from currently selected/active system
00942                     self.main.SetLinkTypeTable(subsystem.GetLinkTypeTable()) #or is it already set?
00943                     self.main.SetDeviceTable(subsystem.GetDeviceTable())
00944                     #Set for Devicetype later
00945                     if linktypes_raw == False:
00946                         self.main.ShowError(subsystem.GetErrorMessage(),ERR_ERROR)
00947                     else:
00948                         types = linktypes_raw
00949                         self.linktypeCtrl.clear()
00950 
00951                         if len(types) == 0:
00952                                 self.main.ShowError(subsystem.GetErrorMessage(),ERR_INFORMATION)
00953                         else:
00954                                 map(self.linktypeCtrl.insertItem,types)
00955                                 self.linktypeCtrl.setEnabled(True)
00956                                 self.linktyperestrictchk.setEnabled(True)
00957                                 self.linktyperestrictchk.setChecked(False)
00958 
00959                                 itmdata = str(TN_LINKTYPE) + "|" + str(system)
00960                                 for type in types:
00961                                         tmp_linktype = QListViewItem(treeitem,type,str(itmdata)) # self.treectrl.AppendItem(treeitem,type,-1,-1,wxTreeItemData(itmdata))
00962                                         self.__treeitemids[type] = tmp_linktype
00963                                 self.treeroot.sortChildItems(0,True) #self.treectrl.SortChildren(treeitem)
00964 
00965                                 #WALPROB self.main.RefreshObjectBoxData() #update link types and device types in toolbar
00966 
00967         self.setCursor(QCursor(Qt.ArrowCursor)) #wxEndBusyCursor()
00968 
00969     ##
00970     #  Chose a Device Type item in tree view, update it.
00971     # 
00972     #   parameters:
00973     #   @treeitem - tree item id of the selected tree item
00974     #   @system - subsystem of the selected tree item
00975     #   @doexpand - whether the tree item should be expanded or not
00976     #         
00977     def UpdateDeviceType(self,treeitem,system,doexpand=True):
00978 
00979         self.setCursor(QCursor(Qt.WaitCursor))
00980         #print "UpdateDeviceType"
00981         if doexpand:
00982                 self.myCollapseAndReset(treeitem) #self.treectrl.CollapseAndReset(treeitem)
00983 
00984         if not self.main.GetCdb():
00985             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
00986             self.main.SetActiveSystem(None,"select")
00987             self.main.SetActiveDeviceType(None)
00988             self.SystemChanged()
00989         elif not self.main.GetActiveSystem():
00990             self.main.ShowError("No subsystem set to active.",ERR_INFORMATION)
00991         else:
00992             if self.main.GetActiveSystem() != system:
00993                 self.main.SetActiveSystem(system,"select")
00994             self.main.SetActiveDeviceType(str(treeitem.text(0)))
00995             devicetype = DeviceType(self.main.GetActiveSystem(),self.main.GetActiveDeviceType(),False)
00996             self.UpdateInfo(devicetype)  
00997 
00998             if doexpand:
00999                         if self.main.GetActiveSystem() !='Spare devices':
01000                                 devices_list = devicetype.GetDevices()
01001                                 if self.main.GetActiveSystem()=="VELO" :
01002                                         restrict = self.main.GetRestrictedSparePart()
01003                                         #print "je suis dans expand"
01004                                         if restrict == 'Spares only':
01005                                             devices_notinstalled=devicetype.GetDevicesByLocation("SPARE")
01006                                             devices=[x for x in devices_list if x in devices_notinstalled]
01007                                         elif restrict == 'In place only':
01008                                             devices_notinstalled=devicetype.GetDevicesByLocation("SPARE")
01009                                             devices=[x for x in devices_list if x not in devices_notinstalled]
01010                                         else:
01011                                             devices=devices_list
01012                                 else:
01013                                         devices=devices_list    
01014                         else:
01015                                 devices = devicetype.GetSpareDevices()
01016                     
01017                         if devices == False:
01018                                 self.main.ShowError(devicetype.GetErrorMessage(),ERR_ERROR)
01019                         else:
01020                             print "devices: " + str(devices)
01021                         if type(devices)==type([]) and len(devices) != 0:
01022                                 #devices = map(lambda x: x[0],devices)
01023                                 
01024                         
01025                                 #print 'restricted: %s' % restrict
01026                                 
01027                                 itmdata = str(TN_DEVICE) + "|" + str(system)
01028                                 for device in devices:
01029                                     tmp_dev = QListViewItem(treeitem,device,str(itmdata)) # self.treectrl.AppendItem(treeitem,device,-1,-1,wxTreeItemData(itmdata))
01030                                     self.__treeitemids[device] = tmp_dev
01031                                 treeitem.sortChildItems(0,True) # self.treectrl.SortChildren(treeitem)
01032                                 
01033                         else:
01034                                 self.main.ShowError(devicetype.GetErrorMessage(),ERR_INFORMATION)
01035 
01036         self.setCursor(QCursor(Qt.ArrowCursor))
01037 
01038     ##
01039     #  Chose a Link Type item in tree view, update it.
01040     # 
01041     #   parameters:
01042     #   @treeitem - tree item id of the selected tree item
01043     #   @system - subsystem of the selected tree item
01044     #   @doexpand - whether the tree item should be expanded or not
01045     #         
01046     def UpdateLinkType(self,treeitem,system,doexpand=True):
01047 
01048         self.setCursor(QCursor(Qt.WaitCursor))
01049 
01050         if doexpand:
01051                 self.myCollapseAndReset(treeitem)
01052 
01053         if not self.main.GetCdb():
01054             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
01055             self.main.SetActiveSystem(None,"select")
01056             self.main.SetActiveLinkType(None)
01057             self.SystemChanged()
01058         elif not self.main.GetActiveSystem():
01059             self.main.ShowError("No subsystem set to active.",ERR_INFORMATION)
01060         else:
01061             if self.main.GetActiveSystem() != system:
01062                 self.main.SetActiveSystem(system,"select")
01063             self.main.SetActiveLinkType( str(treeitem.text(0)) )
01064             linktype = LinkType(self.main.GetActiveSystem(),self.main.GetActiveLinkType(),False)
01065             self.UpdateInfo(linktype)
01066 
01067         self.setCursor(QCursor(Qt.ArrowCursor))
01068 
01069     ##
01070     #  Chose a Device item in tree view, update it.
01071     # 
01072     #   parameters:
01073     #   @treeitem - tree item id of the selected tree item
01074     #   @system - subsystem of the selected tree item
01075     #   @doexpand - whether the tree item should be expanded or not
01076     #         
01077     def UpdateDevice(self,treeitem,system,doexpand=True):
01078 
01079         self.setCursor(QCursor(Qt.WaitCursor))
01080         ##tmp = waiter(None, "wa sber")
01081         if doexpand:
01082                 self.myCollapseAndReset(treeitem)
01083 
01084         if not self.main.GetCdb():
01085             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
01086             self.main.SetActiveSystem(None,"select")
01087             self.main.SetActiveDeviceType(None)
01088             self.main.SetActiveDevice(None)
01089             self.SystemChanged()
01090         elif not self.main.GetActiveSystem():
01091             self.main.ShowError("No subsystem set to active.",ERR_INFORMATION)
01092         else:
01093             if self.main.GetActiveSystem() != system:
01094                 self.main.SetActiveSystem(system,"select")
01095             self.main.SetActiveDevice(str(treeitem.text(0)))
01096             if self.main.GetActiveSystem() !='Spare devices':
01097                 device = Device(self.main.GetActiveSystem(),self.main.GetActiveDevice(),False)
01098             else :
01099                 device = Spare_Device(self.main.GetActiveDeviceType(),self.main.GetActiveDevice(),False)
01100                 
01101             self.UpdateInfo(device)
01102             if self.main.GetActiveSystem() !='Spare devices':
01103                 if self.main.GetViewMode() == ID_SUCCESSORS_MODE:
01104                     self.main.GetVisWindow().OnDeviceSelected(device)   #sending the object and deviceinfo
01105                 elif self.main.GetViewMode() == ID_PATHS_MODE:
01106                     self.UpdatePath(device)
01107                 elif self.main.GetViewMode() == ID_DYNAMIC_MODE:
01108                     if self.main.GetVisWindow().GetContents() == []:
01109                         self.main.GetVisWindow().OnDeviceSelected(device,False) #Add to center
01110                     else:
01111                         x_offset,y_offset = self.main.GetVisWindow().CalcUnscrolledPosition(10,10)
01112                         self.main.GetVisWindow().CreateNode(x_offset,y_offset,device)
01113                         shape = self.main.GetVisWindow().FindByName(device.GetName())
01114                         if shape:
01115                                 self.main.GetVisWindow().Select(shape)
01116                 elif self.main.GetViewMode() == ID_SUBSYSTEM_MODE:
01117                     self.main.ViewSubSystem(device.GetName())
01118 
01119             if doexpand:
01120                 if self.main.GetActiveSystem() !='Spare devices':
01121                     ports = device.GetPorts()
01122                 else:
01123                     ports = device.GetSparePorts()
01124                 
01125                 if ports == False:
01126                     self.main.ShowError(device.GetErrorMessage(),ERR_ERROR)
01127                 else:
01128                     if len(ports) != 0:
01129                         itmdata = str(TN_PORT) + "|" + str(system)
01130                         for port in ports:
01131                             #print 'getname '+str(port.GetName())
01132                             tmp_port = QListViewItem(treeitem,port.GetName(), str(itmdata)) #self.treectrl.AppendItem(treeitem,port.GetName(),-1,-1,wxTreeItemData(itmdata))
01133                             self.__treeitemids[port] = tmp_port
01134                         treeitem.sortChildItems(0,True)
01135                                 
01136                     else:
01137                             self.main.ShowError(device.GetErrorMessage(),ERR_INFORMATION)
01138 
01139         self.setCursor(QCursor(Qt.ArrowCursor))
01140         ##tmp.accept()
01141 
01142     ##
01143     #  Chose a Link item in tree view, update it. 
01144     #   Not in use at the moment...may be in the future
01145     # 
01146     #   parameters:
01147     #   @treeitem - tree item id of the selected tree item
01148     #   @system - subsystem of the selected tree item
01149     #   @doexpand - whether the tree item should be expanded or not
01150     #         
01151     def UpdateLink(self,treeitem,system,doexpand=True): 
01152 
01153         wxBeginBusyCursor()
01154 
01155         if doexpand:
01156                 self.treectrl.CollapseAndReset(treeitem)
01157 
01158         if not self.main.GetCdb():
01159             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
01160             self.main.SetActiveSystem(None,"select")
01161             self.main.SetActiveLinkType(None)
01162             self.main.SetActiveLink(None)
01163             self.SystemChanged()
01164         elif not self.main.GetActiveSystem():
01165             self.main.ShowError("No subsystem set to active.",ERR_INFORMATION)
01166         else:
01167             if self.main.GetActiveSystem() != system:
01168                 self.main.SetActiveSystem(system,"select")
01169             self.main.SetActiveLink(self.treectrl.GetItemText(treeitem))
01170             link = Link(self.main.GetActiveSystem(),self.main.GetActiveLink(),False,False)
01171             self.UpdateInfo(link)
01172 
01173             #add more options for selection etc for links if wanted later on
01174             visobj = self.main.GetVisWindow().FindByName(link.GetName())
01175             if visobj != None:
01176                 self.main.GetVisWindow().Select(visobj)
01177 
01178         wxEndBusyCursor()
01179 
01180     ##
01181     #  Chose a Link item in tree view, update it. 
01182     #   Not in use at the moment...may be in the future
01183     # 
01184     #   parameters:
01185     #   @treeitem - tree item id of the selected tree item
01186     #   @system - subsystem of the selected tree item
01187     #   @doexpand - whether the tree item should be expanded or not
01188     #         
01189     def UpdatePort(self,treeitem,system,doexpand=True):
01190 
01191         self.setCursor(QCursor(Qt.WaitCursor))
01192 
01193         if doexpand:
01194                 self.myCollapseAndReset(treeitem) #?!
01195 
01196         if not self.main.GetCdb():
01197             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
01198             self.main.SetActiveDevice(None)
01199             self.main.SetActivePort(None)
01200             self.SystemChanged() #active system may have changed...
01201         elif not self.main.GetActiveSystem():
01202             self.main.ShowError("No subsystem set to active.",ERR_INFORMATION)
01203         else:
01204             if self.main.GetActiveSystem() != system:
01205                 self.main.SetActiveSystem(system,"select")
01206 
01207             self.main.SetActivePort(str(treeitem.text(0)))
01208 
01209             tmpport = str(treeitem.text(0)).split(":")
01210             #print 'spare port ' + str(tmpport[2].strip())
01211             self.main.SetActiveDevice(tmpport[0].strip())
01212             if tmpport[3].strip() == "IN":
01213                 way = 1
01214             else: #OUT
01215                 way = 2
01216             
01217             if self.main.GetActiveSystem()!='Spare devices':
01218                 port = Port(self.main.GetActiveSystem(),tmpport[1].strip(),tmpport[2].strip(),way,tmpport[0].strip(),False)
01219             else:
01220                 port = Spare_Port(tmpport[1].strip(),tmpport[2].strip(),way,tmpport[0].strip(),False)
01221 
01222             self.UpdateInfo(port)
01223 
01224         self.setCursor(QCursor(Qt.ArrowCursor)) 
01225 
01226     ##
01227     #  Send an data object of one of the types that are
01228     #   created in objectclasses.py (DeviceType,LinkType,Device,
01229     #   Link or Port at the moment), and display the information
01230     #   about the data object in the information window.
01231     # 
01232     #   Parameters:
01233     #   @obj - the data object which has to have a method called
01234     #   GetObjectInfo() which returns a dictionary of {attribute:value}
01235     #   pairs.
01236     # 
01237     #   !return - False if unsuccessful
01238     #         
01239     def UpdateInfo(self,obj=None):
01240         self.my_data = []
01241 
01242         self.infoCtrl.clear()
01243         if obj == None: #If no object was sent (to clear the information window)
01244                 return False    
01245 
01246         self.setCursor(QCursor(Qt.WaitCursor))
01247         if not self.main.GetCdb():
01248             self.main.ShowError("Not connected to database.",ERR_INFORMATION)
01249             self.SystemChanged()
01250         else:
01251             infos = obj.GetObjectInfo() # Get the dictionary with information
01252             #print "in update info" +str(obj.GetName())
01253             if infos and len(infos) > 0:
01254                 new_dict = {}
01255                 keys = infos.keys()
01256                 #rgbcolor_=infos["rgbcolor"]
01257                 #infos["rgbcolor"]="(" + str(rgbcolor_.red()) + ", " + str(rgbcolor_.green()) + ", " + str(rgbcolor_.blue()) + ")"
01258                 i = 0
01259                 for key in keys:
01260                     if key not in DEV_GENERIC:  #do not show some fields like device type, systemname etc. 
01261                                                 # given in the list DEV_GENERIC in cdbviscore
01262                         elt_=QListViewItem(self.infoCtrl,key,str(infos[key]).replace('\n','   '))#self.infoCtrl.InsertStringItem(i, key)
01263                         #self.infoCtrl.SetStringItem(i, 0, key)
01264                         #self.infoCtrl.SetStringItem(i, 1, str(infos[key]))
01265                         #print "key" +str(key)
01266                         #print "key" +str(infos[key])
01267                         #self.my_data.append(str(key))
01268                         #WAL_OBSELETE new_dict[i] = (key,str(infos[key]))
01269                         #WAL_OBSELETE self.infoCtrl.SetItemData(i, i) # to be able to sort the column
01270                         #WAL_OBSELETE i += 1
01271 
01272                 #WAL_OBSELETE self.itemDataMap = new_dict # needed to be able to sort the list control alphabetically (the attribute names)
01273                 #WAL_OBSELETE self.infoCtrl.SetColumnWidth(0, wxLIST_AUTOSIZE)
01274         
01275                 #WAL_OBSELETE my_width = self.GetSizeTuple()[0]-self.infoCtrl.GetColumnWidth(0)-10
01276                 #WAL_OBSELETE if self.infoCtrl.GetCountPerPage() < self.infoCtrl.GetItemCount():
01277                         #WAL_OBSELETE my_width -= 3
01278                 #WAL_OBSELETE self.infoCtrl.SetColumnWidth(1,my_width)
01279                 self.infoCtrl.setSorting(0,True) # self.SortListItems(col=0,ascending=1)
01280                 
01281             else:
01282                 self.main.ShowError(obj.GetErrorMessage(),ERR_ERROR)
01283 
01284         self.setCursor(QCursor(Qt.ArrowCursor))
01285       
01286     ##
01287     #  One of the requirements for using the sorting mechanism
01288     #   of the ColMixer thingy, this method is needed.
01289     #   
01290     def GetListCtrl(self):
01291         return self.infoCtrl
01292      
01293     ##
01294     #  Return handle on configuration database module
01295     # 
01296     #         !return - The method does not return the confifuration database itself, but an
01297     #         instance of a confdb class. Before connecting (and after 
01298     #         disconnecting) None return None.
01299     #         
01300     def GetCdb(self):
01301         return self.main.GetCdb()
01302 
01303 #################################################################################################################
01304 # PATH VIEW STUFF
01305 ##############################################################################################################
01306             
01307     ##
01308     #  Return the path index currently chosen in the 
01309     #   path window dialog.
01310     #   
01311     #   !return - path index (integer)
01312     #   
01313     def GetPath(self):
01314         
01315         return self.__path
01316 
01317     ##
01318     #  Update the path selection control.
01319     # 
01320     #             This method uses the PathSelect class to show the paths passing
01321     #             the selected device.
01322     # 
01323     #   parameters:
01324     #   @deviceobj - the device object that we will show the path window for,
01325     #   and get paths from.
01326     #         
01327     def UpdatePath(self, deviceobj=None):
01328         
01329         if not self.selectPathFrame: #If path window not visible, create it
01330                 self.selectPathFrame = PathSelect(self.main.GetCdb(), self.main, self.main.GetVisWindow().OnPathSelected,device=deviceobj)
01331 
01332         res = self.selectPathFrame.SetPathDevice(deviceobj) # Set device object; in case it was changed
01333         if res != False:
01334                 self.selectPathFrame.show() # Show the path window
01335         else:
01336                 self.selectPathFrame.show()
01337  
01338 ###########################################################################
01339 # PathSelect class                                                      ###
01340 ###########################################################################
01341 
01342 ##
01343 #  PathSelect class pops up as a little window inside CdbVis, so that 
01344 #             the user can choose a path passing a device to it.
01345 #     
01346 class PathSelect(QDialog):
01347 
01348     ##
01349     #  Constructor.
01350     # 
01351     #           Parameters:
01352     #                 @parent - the parent window (usually MainWindow)
01353     #                 @cdb    - the confDB instance that should be used (reference)
01354     #                 @pos    - position of the path window
01355     #                 @style  - window style
01356     #                 @callback - callable object method that should
01357     #                               be called if a path is selected. 
01358     #                             callback must have 3 parameters: (self, dictionary deviceInfo, integer pathNr)
01359     #         
01360     def __init__(self,cdb, parent = None, callback = None, device=None):
01361         QDialog.__init__(self,parent,"Paths",0,0)  # Args = parent, name, modal, flags
01362 
01363         self.setMinimumSize(QSize(200,0))
01364         self.setFocusPolicy(QDialog.TabFocus)
01365         self.setModal(0)
01366 
01367         PathsLayout = QGridLayout(self,1,1,2,6,"PathsLayout")
01368 
01369         self.listBox = QListBox(self,"listBox")
01370         self.listBox.setFrameShadow(QListBox.Sunken)
01371         self.listBox.setLineWidth(1)
01372         self.listBox.setMargin(0)
01373         self.listBox.setVScrollBarMode(QListBox.Auto)
01374 
01375         PathsLayout.addWidget(self.listBox,0,0)
01376 
01377         self.resize(QSize(200,376).expandedTo(self.minimumSizeHint()))
01378         self.clearWState(Qt.WState_Polished)
01379 
01380         # End GUI stuffs
01381         self.__cdb = cdb
01382         self.__callback = callback
01383         self.__deviceInfo = None
01384         self.__path = None
01385         self.__device = device
01386 
01387         self.main = parent
01388 
01389         # Events
01390         self.connect(self.listBox,SIGNAL("selected(int)"),self.OnPathChoice)
01391         #self.connect(self,SIGNAL("lastWindowClosed()"),self.OnClose)
01392 
01393 
01394 
01395 
01396     ##
01397     #  User chose a path from the path window.
01398     #       
01399     def OnPathChoice(self, event):
01400             
01401             self.SetPath(event+1)
01402 
01403 
01404     ##
01405     #  Path window is closing.
01406     #       
01407     def OnClose(self, event):
01408             self.Destroy()
01409 
01410     ##
01411     #  Clear the list of paths in the control and reset path selection.
01412     #       
01413     def clear(self):
01414             
01415             self.listBox.clear()
01416             self.__path = None
01417 
01418     ##
01419     #  Choose a specific path in the list
01420     # 
01421     #                 @pathNr - the number of the path to select (integer); 
01422     #                           NOT the index in the path list!
01423     #                 #update (optional, default: True)
01424     #                           if True the given callback function is called
01425     #                   (detailed description given in the constructor)
01426     #             
01427     def SetPath(self, pathNr, update = True):
01428 
01429             if self.__path != pathNr:
01430                 self.__path = pathNr
01431                 self.listBox.clearSelection()
01432                 self.listBox.setSelected(pathNr-1,True)
01433                 if update and self.__callback:
01434                         self.__callback(self.__device, pathNr)
01435 
01436     ##
01437     #  Return the index of the path selected.
01438     #       
01439     def GetPath(self):
01440             
01441             return self.__path
01442             
01443     ##
01444     #  Set the device for which paths should be shown in path window.
01445     # 
01446     #                 This method calls GetPathIDs method for the device object chosen
01447     # 
01448     #           Parameters:
01449     #                 @deviceobj - the device data object which we will get the paths for
01450     #             
01451     def SetPathDevice(self,deviceobj):
01452             
01453             self.__device = deviceobj #set as current path view device
01454             deviceInfo = self.__device.GetObjectInfo(True)
01455             
01456             if (None == self.__deviceInfo)  or (self.__deviceInfo[DEV_NAME] != deviceInfo[DEV_NAME]): #name -> id
01457                 self.__deviceInfo = deviceInfo
01458                 
01459                 self.main.ShowError("Please wait while paths are being processed...",ERR_INFORMATION)
01460                 paths = self.__device.GetPaths()
01461 
01462                 if paths == False:
01463                         self.main.ShowError(self.__device.GetErrorMessage() + " ,device: " + str(self.__device.GetName()),ERR_ERROR)
01464                         return False
01465                 elif paths == []:
01466                         self.main.ShowError("No paths found: " + str(self.__device.GetErrorMessage()),ERR_INFORMATION)
01467                         return False
01468                 
01469                 self.main.ShowError("Paths were successfully retrieved for the given device.",ERR_INFORMATION)
01470 
01471                 oldpath = self.GetPath()
01472                 self.clear()
01473 
01474                 for x in paths:
01475                         #print "X: " + str(x)
01476                         #print "X: " + str(x)
01477                         #self.listBox.Append(str(x) + ": " + str(len(paths[x])))
01478                         self.listBox.insertItem(str(x))
01479 
01480                 #self.SetPath(oldpath, False)
01481 
01482 '''
01483     ##
01484     #  PathSelect class pops up as a little window inside CdbVis, so that 
01485     #             the user can choose a path passing a device to it.
01486     #         
01487     class PathSelect(QDialog): #wxMiniFrame):
01488     
01489         def __init__(self, parent, cdb, pos = wxPoint(720,410), 
01490                      style = wxDEFAULT_FRAME_STYLE, callback = None,device=None):
01491             """ Constructor.
01492 
01493 
01494                 Parameters:
01495                 @parent - the parent window (usually MainWindow)
01496                 @cdb    - the confDB instance that should be used (reference)
01497                 @pos    - position of the path window
01498                 @style  - window style
01499                 @callback - callable object method that should
01500                             be called if a path is selected. 
01501                             callback must have 3 parameters: (self, dictionary deviceInfo, integer pathNr)
01502             """
01503             wxMiniFrame.__init__(self, parent, -1, "Paths", pos, 
01504                                  wxSize(250, 300), style)
01505             self.__cdb = cdb
01506             self.__callback = callback
01507             self.__deviceInfo = None
01508             self.__path = None
01509             self.__device = device
01510 
01511             self.main = parent
01512             
01513             # Layout and controls of the select window
01514             self.sizer = wxBoxSizer(wxVERTICAL)
01515             self.border = 5
01516        
01517             # System
01518             self.deviceText = wxStaticText(self, -1, "")
01519             self.sizer.Add(self.deviceText, 0, 
01520                            wxEXPAND | wxLEFT | wxRIGHT | wxTOP, self.border)
01521         
01522             self.listBox = wxListBox(self, ID_PATHCHOICE, 
01523                                      style = wxLB_NEEDED_SB) 
01524             self.listBox.Enable(True)
01525             EVT_LISTBOX(self, ID_PATHCHOICE, self.OnPathChoice)
01526             self.sizer.Add(self.listBox, 1, 
01527                            wxEXPAND | wxLEFT | wxTOP | wxRIGHT, self.border)
01528 
01529             button = wxButton(self, -1, "Close")
01530             EVT_BUTTON(self, button.GetId(), self.OnCloseButton)
01531             self.sizer.Add(button, 0, wxLEFT | wxBOTTOM | wxRIGHT, self.border)
01532 
01533             EVT_CLOSE(self, self.OnClose)
01534 
01535             self.SetSizer(self.sizer)
01536 
01537 
01538         ##
01539         #  User chose a path from the path window.
01540         #           
01541         def OnPathChoice(self, event):
01542             
01543             self.SetPath(int(event.GetSelection()+1))
01544 
01545         ##
01546         #  User closed the path view window, using the close button.
01547         #           
01548         def OnCloseButton(self, event):
01549             
01550             self.Close(True)
01551 
01552         ##
01553         #  Path window is closing.
01554         #           
01555         def OnClose(self, event):
01556             
01557             self.Destroy()
01558 
01559         ##
01560         #  Clear the list of paths in the control and reset path selection.
01561         #           
01562         def Clear(self):
01563             
01564             self.listBox.Clear()
01565             self.__path = None
01566 
01567         ##
01568         #  Choose a specific path in the list
01569         # 
01570         #                 @pathNr - the number of the path to select (integer); 
01571         #                           NOT the index in the path list!
01572         #                 #update (optional, default: True)
01573         #                       if True the given callback function is called
01574         #                       (detailed description given in the constructor)
01575         #             
01576         def SetPath(self, pathNr, update = True):
01577 
01578             if self.__path != pathNr:
01579                 self.__path = pathNr
01580                 self.listBox.Select(pathNr-1)
01581                 if update and self.__callback:
01582                         self.__callback(self.__device, pathNr)
01583 
01584         ##
01585         #  Return the index of the path selected.
01586         #           
01587         def GetPath(self):
01588             
01589             return self.__path
01590             
01591         ##
01592         #  Set the device for which paths should be shown in path window.
01593         # 
01594         #                 This method calls GetPathIDs method for the device object chosen
01595         # 
01596         #               Parameters:
01597         #                 @deviceobj - the device data object which we will get the paths for
01598         #             
01599         def SetPathDevice(self,deviceobj):
01600             
01601             self.__device = deviceobj #set as current path view device
01602             deviceInfo = self.__device.GetObjectInfo(True)
01603 
01604             if (None == self.__deviceInfo)  or (self.__deviceInfo[DEV_NAME] != deviceInfo[DEV_NAME]): #name -> id
01605                 self.__deviceInfo = deviceInfo
01606                 
01607                 self.main.ShowError("Please wait while paths are being processed...",ERR_INFORMATION)
01608                 paths = self.__device.GetPaths()
01609 
01610                 if paths == False:
01611                         self.main.ShowError(self.__device.GetErrorMessage() + " ,device: " + str(self.__device.GetName()),ERR_ERROR)
01612                         return False
01613                 elif paths == []:
01614                         self.main.ShowError("No paths found: " + str(self.__device.GetErrorMessage()),ERR_INFORMATION)
01615                         return False
01616                 
01617                 self.main.ShowError("Paths were successfully retrieved for the given device.",ERR_INFORMATION)
01618 
01619                 oldpath = self.GetPath()
01620                 self.Clear()
01621 
01622                 for x in paths:
01623                         #print "X: " + str(x)
01624                         #print "X: " + str(x)
01625                         #self.listBox.Append(str(x) + ": " + str(len(paths[x])))
01626                         self.listBox.Append(str(x))
01627 
01628                 #self.SetPath(oldpath, False)
01629 '''
01630 
01631 

Generated on Fri Aug 31 11:11:16 2007 for CDBVis by  doxygen 1.5.3