Changeset 3333 for trunk/GSASIIimgGUI.py
- Timestamp:
- Apr 2, 2018 11:17:03 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIimgGUI.py
r3326 r3333 411 411 'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList', 412 412 'binType','SampleShape','PolaVal','SampleAbs','dark image','background image', 413 ]413 'twoth'] 414 414 for key in keys: 415 415 if key not in data: #uncalibrated! … … 465 465 WriteControls(filename,data) 466 466 467 def OnLoadControls(event):467 def LoadControls(Slines,data): 468 468 cntlList = ['wavelength','distance','tilt','invert_x','invert_y','type','Oblique', 469 469 'fullIntegrate','outChannels','outAzimuths','LRazimuth','IOtth','azmthOff','DetDepth', 470 470 'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList','setdist', 471 'PolaVal','SampleAbs','dark image','background image'] 471 'PolaVal','SampleAbs','dark image','background image','twoth'] 472 save = {} 473 for S in Slines: 474 if S[0] == '#': 475 continue 476 [key,val] = S.strip().split(':',1) 477 if key in ['type','calibrant','binType','SampleShape',]: #strings 478 save[key] = val 479 elif key in ['varyList',]: 480 save[key] = eval(val) #dictionary 481 elif key in ['rotation']: 482 save[key] = float(val) 483 elif key in ['center',]: 484 if ',' in val: 485 save[key] = eval(val) 486 else: 487 vals = val.strip('[] ').split() 488 save[key] = [float(vals[0]),float(vals[1])] 489 elif key in cntlList: 490 save[key] = eval(val) 491 data.update(save) 492 # next line removed. Previous updates tree contents. The next 493 # makes a copy of data, puts it into tree and "disconnects" data 494 # from tree contents (later changes to data are lost!) 495 #G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.Image, 'Image Controls'),copy.deepcopy(data)) 496 497 498 def OnLoadControls(event): 472 499 pth = G2G.GetImportPath(G2frame) 473 500 if not pth: pth = '.' … … 478 505 filename = dlg.GetPath() 479 506 File = open(filename,'r') 480 save = {} 481 S = File.readline() 482 while S: 483 if S[0] == '#': 484 S = File.readline() 485 continue 486 [key,val] = S.strip().split(':',1) 487 if key in ['type','calibrant','binType','SampleShape',]: #strings 488 save[key] = val 489 elif key in ['varyList',]: 490 save[key] = eval(val) #dictionary 491 elif key in ['rotation']: 492 save[key] = float(val) 493 elif key in ['center',]: 494 if ',' in val: 495 save[key] = eval(val) 496 else: 497 vals = val.strip('[] ').split() 498 save[key] = [float(vals[0]),float(vals[1])] 499 elif key in cntlList: 500 save[key] = eval(val) 501 S = File.readline() 502 data.update(save) 503 # next line removed. Previous updates tree contents. The next 504 # makes a copy of data, puts it into tree and "disconnects" data 505 # from tree contents (later changes to data are lost!) 506 #G2frame.GPXtree.SetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.Image, 'Image Controls'),copy.deepcopy(data)) 507 Slines = File.readlines() 507 508 File.close() 509 LoadControls(Slines,data) 508 510 finally: 509 511 dlg.Destroy() … … 512 514 G2plt.PlotExposedImage(G2frame,event=event) 513 515 wx.CallLater(100,UpdateImageControls,G2frame,data,masks) 516 517 def OnLoadMultiControls(event): #TODO: how read in multiple image controls & match them by 'twoth' tag? 518 pth = G2G.GetImportPath(G2frame) 519 if not pth: pth = '.' 520 controlsDict = {} 521 dlg = wx.FileDialog(G2frame, 'Choose image control files', pth, '', 522 'image control files (*.imctrl)|*.imctrl',wx.FD_OPEN|wx.FD_MULTIPLE) 523 try: 524 if dlg.ShowModal() == wx.ID_OK: 525 filelist = dlg.GetPaths() 526 if len(filelist) == 0: return 527 for filename in filelist: 528 File = open(filename,'r') 529 Slines = File.readlines() 530 for S in Slines: 531 if S.find('twoth') == 0: 532 indx = S.split(':')[1][:-1] #remove '\n'! 533 controlsDict[indx] = Slines 534 File.close() 535 finally: 536 dlg.Destroy() 537 if not len(controlsDict): 538 return 539 Names = G2gd.GetGPXtreeDataNames(G2frame,['IMG ',]) 540 dlg = G2G.G2MultiChoiceDialog(G2frame,'Select images','Select images for updating controls:', 541 Names) 542 try: 543 if dlg.ShowModal() == wx.ID_OK: 544 images = dlg.GetSelections() 545 if not len(images): 546 return 547 for image in images: 548 Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,Names[image]) 549 imctrls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,Id,'Image Controls')) 550 Slines = controlsDict[imctrls['twoth']] 551 LoadControls(Slines,imctrls) 552 finally: 553 dlg.Destroy() 514 554 515 555 def OnTransferAngles(event): … … 1237 1277 G2frame.Bind(wx.EVT_MENU, OnSaveMultiControls, id=G2G.wxID_SAVESELECTEDCONTROLS) 1238 1278 G2frame.Bind(wx.EVT_MENU, OnLoadControls, id=G2G.wxID_IMLOADCONTROLS) 1279 G2frame.Bind(wx.EVT_MENU, OnLoadMultiControls, id=G2G.wxID_LOADELECTEDCONTROLS) 1239 1280 G2frame.Bind(wx.EVT_MENU, OnTransferAngles, id=G2G.wxID_IMXFERCONTROLS) 1240 1281 G2frame.Bind(wx.EVT_MENU, OnResetDist, id=G2G.wxID_IMRESETDIST)
Note: See TracChangeset
for help on using the changeset viewer.