00001 import string
00002 import time
00003
00004
00005
00006 from qt import *
00007
00008 from cdbVisCore import *
00009 from objectclasses import *
00010 import visWindow
00011 import pdb
00012
00013
00014
00015
00016
00017
00018
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
00145
00146
00147 class selectWindow(QWidget,dbUpdate):
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 def __init__(self,main,parent):
00159 QWidget.__init__(self,parent)
00160 self.main = main
00161
00162
00163 self.__path = None
00164 self.selectPathFrame = None
00165
00166
00167 self.sizer = QVBoxLayout(self)
00168 self.border = 5
00169
00170
00171
00172
00173
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
00189
00190 self.treectrl = QListView(self)
00191 self.treectrl.setMinimumSize(QSize(250,300))
00192 self.sizer.addWidget(self.treectrl)
00193
00194 self.__treeitemids = {}
00195
00196
00197 rootdata = TN_SYSTEM_HEADER
00198
00199 self.treectrl.addColumn("Subsystems")
00200 self.treeroot = QListViewItem(self.treectrl,"Subsystems",str(rootdata))
00201
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)
00207 self.connect(self.treectrl,SIGNAL("doubleClicked(QListViewItem*,const QPoint&,int)"),self.OnChoice)
00208 self.connect(self.treectrl,SIGNAL("expanded(QListViewItem*)"), self.OnExpanding)
00209
00210
00211
00212
00213 options = ['All','Spares only','In place only']
00214
00215 self.sizer.addWidget(QLabel(self, "Filter by spare parts"))
00216 self.sparepartsCtrl=QComboBox(False, self)
00217 self.sparepartsCtrl.setEnabled(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
00226
00227
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)
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 self.linktypeCtrl = QComboBox(self, None)
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
00253
00254 self.sizer.addWidget(QLabel(self, "Information"))
00255
00256
00257
00258
00259
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
00268
00269
00270
00271 self.itemDataMap = {}
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
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 def GetItemID(self,value):
00317
00318 try:
00319 if self.__treeitemids[value].__class__ != QListViewItem:
00320
00321
00322
00323 raise KeyError, "We did not find a valid TreeItemID for the current object."
00324
00325 else:
00326 return self.__treeitemids[value]
00327
00328 except KeyError,err:
00329 raise KeyError,err
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 def RemoveItem(self,id,parent):
00343
00344 self.main.RefreshObjectBoxData()
00345
00346 try:
00347 parentid = self.GetItemID(parent)
00348
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
00356
00357
00358
00359
00360
00361
00362 def SetItemToDeleted(self,item):
00363 self.__treeitemids[item] = -1
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 def CollapseAndExpand(self,id,doexpand=True,set_to_minus_one=True):
00379
00380 try:
00381 self.treectrl.CollapseAndReset(id)
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
00388
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
00407
00408
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
00432
00433
00434 def OnCheckRestrict(self,event):
00435
00436 if self.linktyperestrictchk.isChecked():
00437
00438 if self.linktypeCtrl.currentText() != "":
00439 self.main.RestrictLinkType(True)
00440 self.main.SetRestrictedLinkType(self.linktypeCtrl.currentText())
00441 else:
00442 self.main.RestrictLinkType(False)
00443 self.main.SetRestrictedLinkType("")
00444 else:
00445
00446 self.main.RestrictLinkType(False)
00447 self.main.SetRestrictedLinkType("")
00448
00449 res = self.main.GetVisWindow().ViewOnlyLinksOfGivenType()
00450 self.main.GetVisWindow().canvas.update()
00451
00452
00453
00454
00455
00456
00457
00458 def OnRestrictedSparePartChoice(self,event=''):
00459 self.main.SetRestrictedSparePart(self.sparepartsCtrl.currentText())
00460 self.SystemChanged()
00461
00462
00463
00464
00465
00466 def OnRestrictedLinkTypeChoice(self,event):
00467
00468 if not self.linktyperestrictchk.isChecked():
00469 return
00470 self.main.RestrictLinkType(self.linktyperestrictchk.isChecked())
00471 self.main.SetRestrictedLinkType(str(self.linktypeCtrl.currentText()))
00472
00473 res = self.main.GetVisWindow().ViewOnlyLinksOfGivenType()
00474 self.main.GetVisWindow().canvas.update()
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
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
00501
00502
00503
00504 def SystemChanged(self):
00505 try:
00506 self.self.myCollapseAndReset(self.treeroot)
00507 self.UpdateSystems()
00508 self.treeroot.sortChildItem(0,True)
00509 self.treeroot.setOpen(True)
00510
00511 nr = self.treeroot.childCount()
00512
00513 i = 0
00514 cookie = 6543
00515 while i < nr:
00516
00517
00518
00519
00520 if i == 0:
00521 itm,cookie = self.treeroot.firstChild()
00522 else:
00523 itm,cookie = self.treeroot.nextSibling()
00524
00525
00526 if itm.text() == self.main.GetActiveSystem():
00527 itm.setSelected(True)
00528 self.UpdateSystem(itm,False)
00529 itm.sortChildItem(0,True)
00530 itm.setOpen(True)
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
00539
00540
00541
00542
00543
00544
00545 def OnDbUpdate(self, evtReason, cdb):
00546 self.UpdateDb(evtReason, cdb)
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 def UpdateDb(self, evtReason, cdb):
00558 self.setCursor(QCursor(Qt.WaitCursor))
00559 try:
00560 self.main.SetCdb(cdb)
00561
00562 if not cdb:
00563 self.main.ShowError("Connection to the ConfDB was lost!",ERR_INFORMATION)
00564 self.main.ResetActiveObjects()
00565 self.infoCtrl.clear()
00566 self.main.GetVisWindow().Clear()
00567 self.myCollapseAndReset(self.treeroot)
00568
00569 else:
00570 self.main.ShowError("Connection to the ConfDB is now set.",ERR_INFORMATION)
00571 self.UpdateSystems()
00572 self.expandInCode = True
00573 self.treeroot.setOpen(True)
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))
00580
00581 def myListViewMouseEvent(self,button, item):
00582 if(item==None):
00583 return
00584 if (button==1):
00585 self.OnSelect(item)
00586 else:
00587 self.OnChoice(item)
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 );
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 def OnSelect(self):
00606 global pendingItem
00607 item = pendingItem
00608 if item:
00609 type = str(item.text(1))
00610 text = str(item.text(0))
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
00624
00625
00626
00627
00628
00629
00630
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
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
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))
00667 text = str(item.text(0))
00668
00669
00670
00671
00672
00673
00674 self.main.ResetActiveObjects()
00675
00676
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):
00682 self.main.GetVisWindow().SetLevelZoom(0)
00683 return
00684
00685 elif type == str(TN_SYSTEM):
00686
00687 if self.main.GetActiveSystem() != text:
00688 self.main.GetVisWindow().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
00696 return
00697
00698
00699
00700
00701
00702 self.main.GetVisWindow().Clear()
00703
00704 else:
00705 if set_to_minus_one:
00706 self.main.GetVisWindow().SetLevelZoom(-1)
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
00723
00724 elif type == TN_PORT:
00725 pass
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)
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 def UpdateSystems(self,update=False,doexpand=True):
00744 self.setCursor(QCursor(Qt.WaitCursor))
00745 self.infoCtrl.clear()
00746 self.linktypeCtrl.clear()
00747 if doexpand:
00748
00749 self.myCollapseAndReset(self.treeroot)
00750 if not self.main.GetCdb():
00751 self.main.ShowError("Not connected to database!",ERR_INFORMATION)
00752 self.main.SetActiveSystem(None,"select")
00753 else:
00754 my_db = self.main.GetCdb()
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)
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)
00766 progress.setLabelText(str(system.GetName()))
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))
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
00776 progress.setProgress(len(systems))
00777
00778
00779 self.treeroot.sortChildItems(0,True)
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:
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
00795
00796
00797
00798
00799
00800
00801 def UpdateSystem(self,treeitem,update=False,doexpand=True):
00802
00803
00804
00805
00806 activesystem = self.main.GetActiveSystem()
00807 if activesystem != str(treeitem.text(0)):
00808 try:
00809 treeid = self.GetItemID(activesystem)
00810
00811
00812 except KeyError,err:
00813 pass
00814 else:
00815 if doexpand:
00816 pass
00817 self.infoCtrl.clear()
00818 self.linktypeCtrl.clear()
00819
00820 if not self.main.GetCdb():
00821 self.main.ShowError("Not connected to database.",ERR_INFORMATION)
00822 self.main.SetActiveSystem(None,"select")
00823 self.SystemChanged()
00824 else:
00825
00826 self.main.EnableDisableExportText(True)
00827
00828 system = str(treeitem.text(0))
00829 self.main.SetActiveSystem(system,"select")
00830 if system == "MUON":
00831 self.main.GetVisWindow().SetLevelZoom(0)
00832 else:
00833 self.main.GetVisWindow().SetLevelZoom(1)
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)
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)
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)
00848 self.__treeitemids["Spare hw types"] = devtype_itm
00849
00850 self.main.ShowError(str(treeitem.text(0)) + " subsystem selected.",ERR_INFORMATION)
00851
00852 if update:
00853 self.UpdateDeviceTypes(devtype_itm,system)
00854
00855 devtype_itm.sortChildItems(0,True)
00856 if system!="Spare devices":
00857 self.UpdateLinkTypes(linktype_itm,system)
00858 linktype_itm.sortChildItems(0,True)
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872 def UpdateDeviceTypes(self,treeitem,system,doexpand=True):
00873
00874 self.setCursor(QCursor(Qt.WaitCursor))
00875
00876 if doexpand:
00877 self.myCollapseAndReset(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")
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())
00893 types = subsystem.GetDeviceTypes()
00894
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))
00906 self.__treeitemids[type] = tmp_devtype
00907 self.treeroot.sortChildItems(0,True)
00908
00909
00910
00911
00912 self.setCursor(QCursor(Qt.ArrowCursor))
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922 def UpdateLinkTypes(self,treeitem,system,doexpand=True):
00923
00924 self.setCursor(QCursor(Qt.WaitCursor))
00925
00926 if doexpand:
00927 self.myCollapseAndReset(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())
00941 linktypes_raw = subsystem.GetLinkTypes()
00942 self.main.SetLinkTypeTable(subsystem.GetLinkTypeTable())
00943 self.main.SetDeviceTable(subsystem.GetDeviceTable())
00944
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))
00962 self.__treeitemids[type] = tmp_linktype
00963 self.treeroot.sortChildItems(0,True)
00964
00965
00966
00967 self.setCursor(QCursor(Qt.ArrowCursor))
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977 def UpdateDeviceType(self,treeitem,system,doexpand=True):
00978
00979 self.setCursor(QCursor(Qt.WaitCursor))
00980
00981 if doexpand:
00982 self.myCollapseAndReset(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
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
01023
01024
01025
01026
01027 itmdata = str(TN_DEVICE) + "|" + str(system)
01028 for device in devices:
01029 tmp_dev = QListViewItem(treeitem,device,str(itmdata))
01030 self.__treeitemids[device] = tmp_dev
01031 treeitem.sortChildItems(0,True)
01032
01033 else:
01034 self.main.ShowError(devicetype.GetErrorMessage(),ERR_INFORMATION)
01035
01036 self.setCursor(QCursor(Qt.ArrowCursor))
01037
01038
01039
01040
01041
01042
01043
01044
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
01071
01072
01073
01074
01075
01076
01077 def UpdateDevice(self,treeitem,system,doexpand=True):
01078
01079 self.setCursor(QCursor(Qt.WaitCursor))
01080
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)
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)
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
01132 tmp_port = QListViewItem(treeitem,port.GetName(), str(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
01141
01142
01143
01144
01145
01146
01147
01148
01149
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
01174 visobj = self.main.GetVisWindow().FindByName(link.GetName())
01175 if visobj != None:
01176 self.main.GetVisWindow().Select(visobj)
01177
01178 wxEndBusyCursor()
01179
01180
01181
01182
01183
01184
01185
01186
01187
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()
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
01211 self.main.SetActiveDevice(tmpport[0].strip())
01212 if tmpport[3].strip() == "IN":
01213 way = 1
01214 else:
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
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239 def UpdateInfo(self,obj=None):
01240 self.my_data = []
01241
01242 self.infoCtrl.clear()
01243 if obj == None:
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()
01252
01253 if infos and len(infos) > 0:
01254 new_dict = {}
01255 keys = infos.keys()
01256
01257
01258 i = 0
01259 for key in keys:
01260 if key not in DEV_GENERIC:
01261
01262 elt_=QListViewItem(self.infoCtrl,key,str(infos[key]).replace('\n',' '))
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279 self.infoCtrl.setSorting(0,True)
01280
01281 else:
01282 self.main.ShowError(obj.GetErrorMessage(),ERR_ERROR)
01283
01284 self.setCursor(QCursor(Qt.ArrowCursor))
01285
01286
01287
01288
01289
01290 def GetListCtrl(self):
01291 return self.infoCtrl
01292
01293
01294
01295
01296
01297
01298
01299
01300 def GetCdb(self):
01301 return self.main.GetCdb()
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313 def GetPath(self):
01314
01315 return self.__path
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327 def UpdatePath(self, deviceobj=None):
01328
01329 if not self.selectPathFrame:
01330 self.selectPathFrame = PathSelect(self.main.GetCdb(), self.main, self.main.GetVisWindow().OnPathSelected,device=deviceobj)
01331
01332 res = self.selectPathFrame.SetPathDevice(deviceobj)
01333 if res != False:
01334 self.selectPathFrame.show()
01335 else:
01336 self.selectPathFrame.show()
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346 class PathSelect(QDialog):
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360 def __init__(self,cdb, parent = None, callback = None, device=None):
01361 QDialog.__init__(self,parent,"Paths",0,0)
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
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
01390 self.connect(self.listBox,SIGNAL("selected(int)"),self.OnPathChoice)
01391
01392
01393
01394
01395
01396
01397
01398
01399 def OnPathChoice(self, event):
01400
01401 self.SetPath(event+1)
01402
01403
01404
01405
01406
01407 def OnClose(self, event):
01408 self.Destroy()
01409
01410
01411
01412
01413 def clear(self):
01414
01415 self.listBox.clear()
01416 self.__path = None
01417
01418
01419
01420
01421
01422
01423
01424
01425
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
01438
01439 def GetPath(self):
01440
01441 return self.__path
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451 def SetPathDevice(self,deviceobj):
01452
01453 self.__device = deviceobj
01454 deviceInfo = self.__device.GetObjectInfo(True)
01455
01456 if (None == self.__deviceInfo) or (self.__deviceInfo[DEV_NAME] != deviceInfo[DEV_NAME]):
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
01476
01477
01478 self.listBox.insertItem(str(x))
01479
01480
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