Changeset 1505 for branch/logging/log.py
- Timestamp:
- Sep 20, 2014 8:27:59 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/logging/log.py
r1497 r1505 5 5 G2logList = [None] 6 6 'Contains a list of logged actions; first item is ignored' 7 LogInfo = {'Logging':False, 'Tree':None }7 LogInfo = {'Logging':False, 'Tree':None, 'G2frame':None} 8 8 'Contains a dict with values that are needed in the module' 9 9 … … 12 12 # TODO: 13 13 ### Note: no provinance info for histogram instrument parameters: need to remove insVal etc. 14 15 # track histograms and phases with relative indices16 14 17 15 #=========================================================================== … … 33 31 if debug: print 'Logging var change: w/treeRefs',treeRefs,'indexRefs',indexRefs,'new value=',value 34 32 def __str__(self): 33 treeList = self.treeRefs[:] 34 if type(treeList[0]) is tuple: 35 treeList[0] = 'Hist #'+str(treeList[0][1]+1)+' of type '+treeList[0][0] 36 elif len(treeList) > 1 and type(treeList[1]) is int: 37 treeList[1] = 'Phase #'+str(treeList[1]+1) 35 38 return 'Variable change: Key(s)= '+_l2s(self.indexRefs)+' to value='+str(self.value) 36 39 … … 63 66 def __init__(self,itemlist): 64 67 self.treeItemList = itemlist 65 if debug: print 'Logging press on tree: "',itemlist68 if debug: print 'Logging press on tree: ',itemlist 66 69 def __str__(self): 67 return 'Tree item pressed: '+_l2s(self.treeItemList) 70 treeList = self.treeItemList[:] 71 if type(treeList[0]) is tuple: 72 treeList[0] = 'Hist #'+str(treeList[0][1]+1)+' of type '+treeList[0][0] 73 elif len(treeList) > 1 and type(treeList[1]) is int: 74 treeList[1] = 'Phase #'+str(treeList[1]+1) 75 return 'Tree item pressed: '+_l2s(treeList) 68 76 69 77 def _wrapper(func): … … 170 178 def __init__(self,parent=None,*args,**kwargs): 171 179 super(self.__class__,self).__init__(parent=parent,*args,**kwargs) 172 self.G2frame = parent.GetParent()180 LogInfo['G2frame'] = self.G2frame = parent.GetParent() 173 181 self.root = self.AddRoot('Loaded Data: ') 174 182 self.SelectionChanged = None … … 194 202 if self.SelectionChanged: 195 203 textlist = self._getTreeItemsList(event.GetItem()) 196 if LogInfo['Logging']: 204 if LogInfo['Logging'] and event.GetItem() != self.root: 205 textlist[0] = self.GetRelativeHistNum(textlist[0]) 206 if textlist[0] == "Phases" and len(textlist) > 1: 207 textlist[1] = self.GetRelativePhaseNum(textlist[1]) 197 208 G2logList.append(TreeLogEntry(textlist)) 198 209 self.SelectionChanged(event) … … 224 235 self.repaintAction = None 225 236 237 def GetRelativeHistNum(self,histname): 238 '''Returns list with a histogram type and a relative number for that 239 histogram, or the original string if not a histogram 240 ''' 241 histtype = histname.split()[0] 242 if histtype != histtype.upper(): # histograms (only) have a keyword all in caps 243 return histname 244 item, cookie = self.GetFirstChild(self.root) 245 i = 0 246 while item: 247 itemtext = self.GetItemText(item) 248 if itemtext == histname: 249 return histtype,i 250 elif itemtext.split()[0] == histtype: 251 i += 1 252 item, cookie = self.GetNextChild(self.root, cookie) 253 else: 254 raise Exception("Histogram not found: "+histname) 255 256 def ConvertRelativeHistNum(self,histtype,histnum): 257 '''Converts a histogram type and relative histogram number to a 258 histogram name in the current project 259 ''' 260 item, cookie = self.GetFirstChild(self.root) 261 i = 0 262 while item: 263 itemtext = self.GetItemText(item) 264 if itemtext.split()[0] == histtype: 265 if i == histnum: return itemtext 266 i += 1 267 item, cookie = self.GetNextChild(self.root, cookie) 268 else: 269 raise Exception("Histogram #'+str(histnum)+' of type "+histtype+' not found') 270 271 def GetRelativePhaseNum(self,phasename): 272 '''Returns a phase number if the string matches a phase name 273 or else returns the original string 274 ''' 275 item, cookie = self.GetFirstChild(self.root) 276 while item: 277 itemtext = self.GetItemText(item) 278 if itemtext == "Phases": 279 parent = item 280 item, cookie = self.GetFirstChild(parent) 281 i = 0 282 while item: 283 itemtext = self.GetItemText(item) 284 if itemtext == phasename: 285 return i 286 item, cookie = self.GetNextChild(parent, cookie) 287 i += 1 288 else: 289 return phasename # not a phase name 290 item, cookie = self.GetNextChild(self.root, cookie) 291 else: 292 raise Exception("No phases found ") 293 294 def ConvertRelativePhaseNum(self,phasenum): 295 '''Converts relative phase number to a phase name in 296 the current project 297 ''' 298 item, cookie = self.GetFirstChild(self.root) 299 while item: 300 itemtext = self.GetItemText(item) 301 if itemtext == "Phases": 302 parent = item 303 item, cookie = self.GetFirstChild(parent) 304 i = 0 305 while item: 306 if i == phasenum: 307 return self.GetItemText(item) 308 item, cookie = self.GetNextChild(parent, cookie) 309 i += 1 310 else: 311 raise Exception("Phase "+str(phasenum)+" not found") 312 item, cookie = self.GetNextChild(self.root, cookie) 313 else: 314 raise Exception("No phases found ") 315 226 316 def RepaintDataWindow(self): 227 317 item = self.repaintAction … … 251 341 'Perform a Tree press action when read from the log' 252 342 parent = self.root 253 for txt in logitem.treeItemList: 343 for i,txt in enumerate(logitem.treeItemList): 344 if i == 0 and type(txt) is tuple: 345 txt = self.ConvertRelativeHistNum(*txt) 346 elif i == 1 and type(txt) is int and logitem.treeItemList[0] == "Phases": 347 txt = self.ConvertRelativePhaseNum(txt) 254 348 item = G2gd.GetPatternTreeItemId(self.G2frame,parent,txt) 255 349 if not item: … … 280 374 'Perform a Variable Change action, when read from the log' 281 375 parentId = self.root 282 for treeitem in logitem.treeRefs: 376 for i,treeitem in enumerate(logitem.treeRefs): 377 if i == 0 and type(treeitem) is tuple: 378 treeitem = self.ConvertRelativeHistNum(*treeitem) 283 379 item, cookie = self.GetFirstChild(parentId) 284 380 while item: … … 313 409 if not LogInfo['Logging']: return 314 410 if hasattr(result,'treeRefs'): 411 treevars = result.treeRefs[:] 412 treevars[0] = LogInfo['Tree'].GetRelativeHistNum(treevars[0]) 413 if treevars[0] == "Phases" and len(treevars) > 1: 414 treevars[1] = LogInfo['Tree'].GetRelativePhaseNum(treevars[1]) 315 415 lastLog = G2logList[-1] 316 416 fullrefs = result.indexRefs+[key] 317 417 if type(lastLog) is VarLogEntry: 318 if lastLog.treeRefs == result.treeRefs and lastLog.indexRefs == fullrefs:418 if lastLog.treeRefs == treevars and lastLog.indexRefs == fullrefs: 319 419 lastLog.value = result[key] 320 420 if debug: print 'update last log to ',result[key] 321 421 return 322 G2logList.append(VarLogEntry( result.treeRefs,fullrefs,result[key]))422 G2logList.append(VarLogEntry(treevars,fullrefs,result[key])) 323 423 else: 324 424 print key,'Error: var change has no provenance info' … … 424 524 def LogOn(): 425 525 'Turn On logging of actions' 526 if debug: print 'LogOn' 426 527 LogInfo['Logging'] = True 427 528 428 529 def LogOff(): 429 530 'Turn Off logging of actions' 531 if debug: print 'LogOff' 430 532 LogInfo['Logging'] = False 431 533 432 534 def ShowLogStatus(): 433 535 'Return the logging status' … … 436 538 def ReplayLog(event): 437 539 'replay the logged actions (needs to be a wx.widget)' 438 LogOff() # TODO: need to update menu item as well 540 541 LogInfo['G2frame'].OnMacroRecordStatus(None,False) # turn off recording 439 542 LogInfo['Tree'].ClearDataRepaint() 440 543 print 70*'=' 441 544 print 'Performing logged actions:' 442 545 for item in G2logList: 443 if item: 444 print item546 if item: # skip over 1st item in list (None) 547 print 'replaying',item 445 548 LogInfo['Tree'].ReplayLogItem(item) 446 549 wx.Yield() … … 451 554 452 555 556 LogOn() # for debug
Note: See TracChangeset
for help on using the changeset viewer.