@@ -4300,13 +4300,14 @@ def OnFileBrowse(self, event):
43004300 print (traceback .format_exc ())
43014301
43024302
4303- def StartProject (self ):
4303+ def StartProject (self , selectItem = True ):
43044304 '''Opens a GSAS-II project file & selects the 1st available data set to
43054305 display (PWDR, HKLF, REFD or SASD)
43064306 '''
43074307
43084308 Id = 0
43094309 phaseId = None
4310+ GroupId = None
43104311 seqId = None
43114312 G2IO .ProjFileOpen (self )
43124313 self .GPXtree .SetItemText (self .root ,'Project: ' + self .GSASprojectfile )
@@ -4326,26 +4327,36 @@ def StartProject(self):
43264327 seqId = item
43274328 elif name == "Phases" :
43284329 phaseId = item
4330+ elif name .startswith ("Groups" ):
4331+ GroupId = item
43294332 elif name == 'Controls' :
43304333 data = self .GPXtree .GetItemPyData (item )
43314334 if data :
43324335 for item in self .Refine : item .Enable (True )
43334336 item , cookie = self .GPXtree .GetNextChild (self .root , cookie )
43344337 if phaseId : # show all phases
43354338 self .GPXtree .Expand (phaseId )
4336- if seqId :
4339+ if GroupId :
4340+ self .GPXtree .Expand (GroupId )
4341+ # select an item
4342+ if seqId and selectItem :
43374343 self .EnablePlot = True
43384344 SelectDataTreeItem (self ,seqId )
43394345 self .GPXtree .SelectItem (seqId ) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4340- elif Id :
4346+ elif GroupId and selectItem :
4347+ self .EnablePlot = True
4348+ self .GPXtree .Expand (GroupId )
4349+ SelectDataTreeItem (self ,GroupId )
4350+ self .GPXtree .SelectItem (GroupId ) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4351+ elif Id and selectItem :
43414352 self .EnablePlot = True
43424353 self .GPXtree .Expand (Id )
43434354 SelectDataTreeItem (self ,Id )
43444355 self .GPXtree .SelectItem (Id ) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4345- elif phaseId :
4356+ elif phaseId and selectItem :
43464357 Id = phaseId
43474358 # open 1st phase
4348- Id , unused = self .GPXtree .GetFirstChild (phaseId )
4359+ Id ,_ = self .GPXtree .GetFirstChild (phaseId )
43494360 SelectDataTreeItem (self ,Id )
43504361 self .GPXtree .SelectItem (Id ) # as before for OSX
43514362 self .CheckNotebook ()
@@ -7924,6 +7935,8 @@ def SearchGroups(event):
79247935 is judged by a common string that matches a template
79257936 supplied by the user
79267937 '''
7938+ ans = G2frame .OnFileSave (None )
7939+ if not ans : return
79277940 Histograms ,Phases = G2frame .GetUsedHistogramsAndPhasesfromTree ()
79287941 for hist in Histograms :
79297942 if hist .startswith ('PWDR ' ):
@@ -7932,6 +7945,8 @@ def SearchGroups(event):
79327945 G2G .G2MessageBox (G2frame ,'No PWDR histograms found to group' ,
79337946 'Cannot group' )
79347947 return
7948+ repeat = True
7949+ srchStr = hist [5 :]
79357950 msg = ('Edit the histogram name below placing a question mark (?) '
79367951 'at the location '
79377952 'of characters that change between groups of '
@@ -7940,40 +7955,71 @@ def SearchGroups(event):
79407955 'vary within a histogram group (e.g. Bank 1). '
79417956 'Be sure to leave enough characters so the string '
79427957 'can be uniquely matched.' )
7943- res = G2G .StringSearchTemplate (G2frame ,'Set match template' ,msg ,hist [5 :])
7944- re_res = re .compile (res .replace ('.' ,r'\.' ).replace ('?' ,'.' ))
7945- setDict = {}
7946- keyList = []
7947- noMatchCount = 0
7948- for hist in Histograms :
7949- if hist .startswith ('PWDR ' ):
7950- m = re_res .search (hist )
7951- if m :
7952- key = hist [m .start ():m .end ()]
7953- setDict [hist ] = key
7954- if key not in keyList : keyList .append (key )
7955- else :
7956- noMatchCount += 1
7957- groupDict = {}
7958- groupCount = {}
7959- for k in keyList :
7960- groupDict [k ] = [hist for hist ,key in setDict .items () if k == key ]
7961- groupCount [k ] = len (groupDict [k ])
7958+ while repeat :
7959+ srchStr = G2G .StringSearchTemplate (G2frame ,'Set match template' ,
7960+ msg ,srchStr )
7961+ if srchStr is None : return # cancel pressed
7962+ reSrch = re .compile (srchStr .replace ('.' ,r'\.' ).replace ('?' ,'.' ))
7963+ setDict = {}
7964+ keyList = []
7965+ noMatchCount = 0
7966+ for hist in Histograms :
7967+ if hist .startswith ('PWDR ' ):
7968+ m = reSrch .search (hist )
7969+ if m :
7970+ key = hist [m .start ():m .end ()]
7971+ setDict [hist ] = key
7972+ if key not in keyList : keyList .append (key )
7973+ else :
7974+ noMatchCount += 1
7975+ groupDict = {}
7976+ groupCount = {}
7977+ for k in keyList :
7978+ groupDict [k ] = [hist for hist ,key in setDict .items () if k == key ]
7979+ groupCount [k ] = len (groupDict [k ])
79627980
7963- msg = f'With template { res !r} found '
7964- if min (groupCount .values ()) == max (groupCount .values ()):
7965- msg += f'{ len (groupDict )} groups with { min (groupCount .values ())} histograms each'
7966- else :
7967- msg += (f'{ len (groupDict )} groups with between { min (groupCount .values ())} '
7968- f' and { min (groupCount .values ())} histograms in each' )
7969- if noMatchCount :
7970- msg += f"\n \n Note that { noMatchCount } PWDR histograms were not included in any groups"
7971- G2G .G2MessageBox (G2frame ,msg ,'Grouping result' )
7972- data ['Groups' ] = {'groupDict' :groupDict ,'notGrouped' :noMatchCount ,
7973- 'template' :res }
7974- wx .CallAfter (UpdateControls ,G2frame ,data )
7981+ msg1 = f'With template { srchStr !r} found '
7982+ if min (groupCount .values ()) == max (groupCount .values ()):
7983+ msg1 += f'{ len (groupDict )} groups with { min (groupCount .values ())} histograms each'
7984+ else :
7985+ msg1 += (f'{ len (groupDict )} groups with between { min (groupCount .values ())} '
7986+ f' and { min (groupCount .values ())} histograms in each' )
7987+ if noMatchCount :
7988+ msg1 += f"\n \n Note that { noMatchCount } PWDR histograms were not included in any groups"
7989+ #G2G.G2MessageBox(G2frame,msg1,'Grouping result')
7990+ res = G2G .ShowScrolledInfo (G2frame ,msg1 ,header = 'Grouping result' ,
7991+ buttonlist = [
7992+ ('OK' , lambda event : event .GetEventObject ().GetParent ().EndModal (wx .ID_OK )),
7993+ ('try again' , lambda event : event .GetEventObject ().GetParent ().EndModal (wx .ID_CANCEL ))
7994+ ],
7995+ height = 150 )
7996+ if res == wx .ID_OK :
7997+ repeat = False
79757998
7976- # start of UpdateControls
7999+ data ['Groups' ] = {'groupDict' :groupDict ,'notGrouped' :noMatchCount ,
8000+ 'template' :srchStr }
8001+ # wx.CallAfter(UpdateControls,G2frame,data)
8002+ ans = G2frame .OnFileSave (None )
8003+ if not ans : return
8004+ G2frame .clearProject () # clear out data tree
8005+ G2frame .StartProject (False )
8006+ #self.EnablePlot = True
8007+ Id = GetGPXtreeItemId (G2frame ,G2frame .root , 'Controls' )
8008+ SelectDataTreeItem (G2frame ,Id )
8009+ G2frame .GPXtree .SelectItem (Id ) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
8010+
8011+ def ClearGroups (event ):
8012+ del data ['Groups' ]
8013+ ans = G2frame .OnFileSave (None )
8014+ if not ans : return
8015+ G2frame .clearProject () # clear out data tree
8016+ G2frame .StartProject (False )
8017+ #self.EnablePlot = True
8018+ Id = GetGPXtreeItemId (G2frame ,G2frame .root , 'Controls' )
8019+ SelectDataTreeItem (G2frame ,Id )
8020+ G2frame .GPXtree .SelectItem (Id ) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
8021+
8022+ #======= start of UpdateControls ===========================================
79778023 if 'SVD' in data ['deriv type' ]:
79788024 G2frame .GetStatusBar ().SetStatusText ('Hessian SVD not recommended for initial refinements; use analytic Hessian or Jacobian' ,1 )
79798025 else :
@@ -8037,6 +8083,11 @@ def SearchGroups(event):
80378083 btn = wx .Button (G2frame .dataWindow , wx .ID_ANY ,'Define groupings' )
80388084 btn .Bind (wx .EVT_BUTTON ,SearchGroups )
80398085 subSizer .Add (btn )
8086+ if groupDict :
8087+ btn = wx .Button (G2frame .dataWindow , wx .ID_ANY ,'Clear groupings' )
8088+ subSizer .Add ((5 ,- 1 ))
8089+ subSizer .Add (btn )
8090+ btn .Bind (wx .EVT_BUTTON ,ClearGroups )
80408091 subSizer .Add ((- 1 ,- 1 ),1 ,wx .EXPAND )
80418092 mainSizer .Add (subSizer ,0 ,wx .EXPAND )
80428093 mainSizer .Add ((- 1 ,8 ))
0 commit comments