- Timestamp:
- Apr 24, 2020 11:06:35 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r4399 r4410 1194 1194 return None 1195 1195 1196 ######################################################################1197 # base classes for reading various types of data files1198 # not used directly, only by subclassing1199 ######################################################################1200 def BlockSelector(ChoiceList, ParentFrame=None,title='Select a block',1201 size=None, header='Block Selector',useCancel=True):1202 ''' Provide a wx dialog to select a block if the file contains more1203 than one set of data and one must be selected1204 '''1205 if useCancel:1206 dlg = wx.SingleChoiceDialog(1207 ParentFrame,title, header,ChoiceList)1208 else:1209 dlg = wx.SingleChoiceDialog(1210 ParentFrame,title, header,ChoiceList,1211 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE)1212 if size: dlg.SetSize(size)1213 dlg.CenterOnParent()1214 if dlg.ShowModal() == wx.ID_OK:1215 sel = dlg.GetSelection()1216 return sel1217 else:1218 return None1219 dlg.Destroy()1220 1221 def MultipleBlockSelector(ChoiceList, ParentFrame=None,1222 title='Select a block',size=None, header='Block Selector'):1223 '''Provide a wx dialog to select a block of data if the1224 file contains more than one set of data and one must be1225 selected.1226 1227 :returns: a list of the selected blocks1228 '''1229 dlg = wx.MultiChoiceDialog(ParentFrame,title, header,ChoiceList+['Select all'],1230 wx.CHOICEDLG_STYLE)1231 dlg.CenterOnScreen()1232 if size: dlg.SetSize(size)1233 if dlg.ShowModal() == wx.ID_OK:1234 sel = dlg.GetSelections()1235 else:1236 return []1237 dlg.Destroy()1238 selected = []1239 if len(ChoiceList) in sel:1240 return range(len(ChoiceList))1241 else:1242 return sel1243 return selected1244 1245 def MultipleChoicesSelector(choicelist, headinglist, ParentFrame=None, **kwargs):1246 '''A modal dialog that offers a series of choices, each with a title and a wx.Choice1247 widget. Typical input:1248 1249 * choicelist=[ ('a','b','c'), ('test1','test2'),('no choice',)]1250 1251 * headinglist = [ 'select a, b or c', 'select 1 of 2', 'No option here']1252 1253 optional keyword parameters are: head (window title) and title1254 returns a list of selected indicies for each choice (or None)1255 '''1256 result = None1257 dlg = MultipleChoicesDialog(choicelist,headinglist,1258 parent=ParentFrame, **kwargs)1259 dlg.CenterOnParent()1260 if dlg.ShowModal() == wx.ID_OK:1261 result = dlg.chosen1262 dlg.Destroy()1263 return result1264 1265 def PhaseSelector(ChoiceList, ParentFrame=None,1266 title='Select a phase', size=None,header='Phase Selector'):1267 ''' Provide a wx dialog to select a phase if the file contains more1268 than one phase1269 '''1270 return BlockSelector(ChoiceList,ParentFrame,title,1271 size,header)1272 1273 ######################################################################1274 1196 def striphist(var,insChar=''): 1275 1197 'strip a histogram number from a var name' … … 1279 1201 sv[1] = insChar 1280 1202 return ':'.join(sv) 1203 1204 ###################################################################### 1205 # base classes for reading various types of data files 1206 # not used directly, only by subclassing 1207 ###################################################################### 1281 1208 class ExportBaseclass(object): 1282 1209 '''Defines a base class for the exporting of GSAS-II results. -
trunk/GSASIIctrlGUI.py
r4388 r4410 88 88 :func:`askSaveFile` Get a file name from user 89 89 :func:`askSaveDirectory` Get a directory name from user 90 :func:`BlockSelector` Select a single block for instrument parameters 91 :func:`MultipleBlockSelector` Select one or more blocks of data, used for 92 CIF powder histogram imports only 93 :func:`MultipleChoicesSelector` Dialog for displaying fairly complex choices, used for 94 CIF powder histogram imports only 95 :func:`PhaseSelector` Select a phase from a list (used for phase importers) 96 90 97 ================================ ================================================================= 91 98 … … 1905 1912 dlg.Destroy() 1906 1913 1907 ################################################################ Single choice Dialog with filter options 1914 ############################################################### 1915 # Single choice Dialog with filter options 1908 1916 class G2SingleChoiceDialog(wx.Dialog): 1909 1917 '''A dialog similar to wx.SingleChoiceDialog except that a filter can be … … 2090 2098 self.EndModal(wx.ID_CANCEL) 2091 2099 2092 ################################################################### ,#############2100 ################################################################################ 2093 2101 def G2MessageBox(parent,msg,title='Error'): 2094 2102 '''Simple code to display a error or warning message … … 2831 2839 dlg.Destroy() 2832 2840 2833 ######################################################### Column-order selection dialog 2841 ######################################################## 2842 # Column-order selection dialog 2834 2843 def GetItemOrder(parent,keylist,vallookup,posdict): 2835 2844 '''Creates a dialog where items can be ordered into columns … … 4693 4702 return s.encode('ascii','replace') 4694 4703 4704 ###################################################################### 4705 # wx classes for reading various types of data files 4706 ###################################################################### 4707 def BlockSelector(ChoiceList, ParentFrame=None,title='Select a block', 4708 size=None, header='Block Selector',useCancel=True): 4709 ''' Provide a wx dialog to select a single block where one must 4710 be selected. Used for selecting for banks for instrument 4711 parameters if the file contains more than one set. 4712 ''' 4713 if useCancel: 4714 dlg = wx.SingleChoiceDialog( 4715 ParentFrame,title, header,ChoiceList) 4716 else: 4717 dlg = wx.SingleChoiceDialog( 4718 ParentFrame,title, header,ChoiceList, 4719 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE) 4720 if size: dlg.SetMinSize(size) 4721 dlg.CenterOnParent() 4722 dlg.SendSizeEvent() 4723 if dlg.ShowModal() == wx.ID_OK: 4724 sel = dlg.GetSelection() 4725 return sel 4726 else: 4727 return None 4728 dlg.Destroy() 4729 4730 def MultipleBlockSelector(ChoiceList, ParentFrame=None, 4731 title='Select a block',size=None, header='Block Selector'): 4732 '''Provide a wx dialog to select a block of data if the 4733 file contains more than one set of data and one must be 4734 selected. Used in :mod:`G2pwd_CIF` only. 4735 4736 :returns: a list of the selected blocks 4737 ''' 4738 dlg = wx.MultiChoiceDialog(ParentFrame,title, header,ChoiceList+['Select all'], 4739 wx.CHOICEDLG_STYLE) 4740 if size: dlg.SetMinSize(size) 4741 dlg.CenterOnScreen() 4742 dlg.SendSizeEvent() 4743 if dlg.ShowModal() == wx.ID_OK: 4744 sel = dlg.GetSelections() 4745 else: 4746 return [] 4747 dlg.Destroy() 4748 selected = [] 4749 if len(ChoiceList) in sel: 4750 return range(len(ChoiceList)) 4751 else: 4752 return sel 4753 return selected 4754 4755 def MultipleChoicesSelector(choicelist, headinglist, ParentFrame=None, **kwargs): 4756 '''A modal dialog that offers a series of choices, each with a title and a wx.Choice 4757 widget. Used in :mod:`G2pwd_CIF` only. 4758 4759 Typical input: 4760 4761 * choicelist=[ ('a','b','c'), ('test1','test2'),('no choice',)] 4762 4763 * headinglist = [ 'select a, b or c', 'select 1 of 2', 'No option here'] 4764 4765 optional keyword parameters are: head (window title) and title 4766 returns a list of selected indicies for each choice (or None) 4767 ''' 4768 result = None 4769 dlg = MultipleChoicesDialog(choicelist,headinglist, 4770 parent=ParentFrame, **kwargs) 4771 dlg.CenterOnParent() 4772 if dlg.ShowModal() == wx.ID_OK: 4773 result = dlg.chosen 4774 dlg.Destroy() 4775 return result 4776 4777 def PhaseSelector(ChoiceList, ParentFrame=None, 4778 title='Select a phase', size=None,header='Phase Selector'): 4779 ''' Provide a wx dialog to select a phase, used in importers if a file 4780 contains more than one phase 4781 ''' 4782 return BlockSelector(ChoiceList,ParentFrame,title, 4783 size,header) 4784 4695 4785 ################################################################################ 4696 4786 # configuration routines (for editing config.py) -
trunk/GSASIIdataGUI.py
r4406 r4410 1489 1489 for i in range(1,1+ibanks): 1490 1490 choices.append('Bank '+str(i)) 1491 bank = 1 + G2 IO.BlockSelector(1491 bank = 1 + G2G.BlockSelector( 1492 1492 choices, self, 1493 1493 title=u'Select an instrument parameter bank for '+ … … 1538 1538 for l in dI.defaultIparm_lbl: 1539 1539 choices.append('Defaults for '+l) 1540 res = G2 IO.BlockSelector(choices,ParentFrame=self,title=head,1540 res = G2G.BlockSelector(choices,ParentFrame=self,title=head, 1541 1541 header='Select default inst parms',useCancel=True) 1542 1542 if res is None: return None … … 3793 3793 3794 3794 def OnDeletePhase(self,event): 3795 'Delete a phase from the tree. Called by Data/Delete Phase menu' 3796 #Hmm, also need to delete this phase from Reflection Lists for each PWDR histogram 3795 '''Delete one or more phases from the tree. Called by Data/Delete Phase menu. 3796 Also delete this phase from Reflection Lists for each PWDR histogram; 3797 removes the phase from restraints and deletes any constraints 3798 with variables from the phase. 3799 If any deleted phase is marked as Used in a histogram, a more rigorous 3800 "deep clean" is done and histogram refinement results are cleared, as well as 3801 the covariance information and all plots are deleted 3802 ''' 3803 selItem = self.GPXtree.GetSelection() 3797 3804 if self.dataWindow: 3798 3805 self.dataWindow.ClearData() … … 3800 3807 DelList = [] 3801 3808 DelItemList = [] 3809 consDeleted = 0 3810 usedPhase = False 3802 3811 if GetGPXtreeItemId(self,self.root,'Phases'): 3803 3812 sub = GetGPXtreeItemId(self,self.root,'Phases') … … 3808 3817 else: 3809 3818 subr = 0 3810 if sub: 3811 item, cookie = self.GPXtree.GetFirstChild(sub) 3812 while item: 3813 TextList.append(self.GPXtree.GetItemText(item)) 3814 item, cookie = self.GPXtree.GetNextChild(sub, cookie) 3815 dlg = wx.MultiChoiceDialog(self, 'Which phase to delete?', 'Delete phase', TextList, wx.CHOICEDLG_STYLE) 3816 try: 3817 if dlg.ShowModal() == wx.ID_OK: 3818 result = dlg.GetSelections() 3819 for i in result: DelList.append([i,TextList[i]]) 3820 item, cookie = self.GPXtree.GetFirstChild(sub) 3821 i = 0 3822 while item: 3823 if [i,self.GPXtree.GetItemText(item)] in DelList: DelItemList.append(item) 3824 item, cookie = self.GPXtree.GetNextChild(sub, cookie) 3825 i += 1 3826 for item in DelItemList: 3827 name = self.GPXtree.GetItemText(item) 3828 self.GPXtree.Delete(item) 3829 self.G2plotNB.Delete(name) 3830 item, cookie = self.GPXtree.GetFirstChild(self.root) 3831 while item: 3832 name = self.GPXtree.GetItemText(item) 3833 if 'PWDR' in name: 3834 Id = GetGPXtreeItemId(self,item, 'Reflection Lists') 3835 refList = self.GPXtree.GetItemPyData(Id) 3836 if len(refList): 3837 for i,item in DelList: 3838 if item in refList: 3839 del(refList[item]) 3840 elif 'HKLF' in name: 3841 data = self.GPXtree.GetItemPyData(item) 3842 data[0] = {} 3843 3844 item, cookie = self.GPXtree.GetNextChild(self.root, cookie) 3845 finally: 3846 dlg.Destroy() 3819 if GetGPXtreeItemId(self,self.root,'Constraints'): 3820 id = GetGPXtreeItemId(self,self.root,'Constraints') 3821 constr = self.GPXtree.GetItemPyData(id) 3822 else: 3823 constr = {} 3824 3825 item, cookie = self.GPXtree.GetFirstChild(sub) 3826 while item: 3827 TextList.append(self.GPXtree.GetItemText(item)) 3828 item, cookie = self.GPXtree.GetNextChild(sub, cookie) 3829 dlg = wx.MultiChoiceDialog(self, 'Which phase to delete?', 'Delete phase', TextList, wx.CHOICEDLG_STYLE) 3830 try: 3831 if dlg.ShowModal() == wx.ID_OK: 3832 result = dlg.GetSelections() 3833 for i in result: DelList.append([i,TextList[i]]) 3834 item, cookie = self.GPXtree.GetFirstChild(sub) 3835 i = 0 3836 while item: 3837 if [i,self.GPXtree.GetItemText(item)] in DelList: DelItemList.append(item) 3838 item, cookie = self.GPXtree.GetNextChild(sub, cookie) 3839 i += 1 3840 for item in DelItemList: 3841 phase = self.GPXtree.GetItemPyData(item) 3842 for h in phase['Histograms']: 3843 if 'Use' not in phase['Histograms'][h]: continue 3844 if phase['Histograms'][h]['Use']: 3845 usedPhase = True 3846 break 3847 if 'pId' in phase: 3848 p = phase['pId'] 3849 else: 3850 p = '?' 3851 self.GPXtree.Delete(item) 3852 if item == selItem: selItem = self.root 3853 # look for constraints to remove 3854 for key in constr: 3855 delThis = [] 3856 if key.startswith('_'): continue 3857 for i,cons in enumerate(constr[key]): 3858 for var in cons[0:-3]: 3859 if str(var[1]).startswith(str(p)): 3860 delThis.append(i) 3861 break 3862 for i in reversed(delThis): 3863 consDeleted += 1 3864 del constr[key][i] 3865 # delete refinement results from histograms 3866 item, cookie = self.GPXtree.GetFirstChild(self.root) 3867 while item: 3868 name = self.GPXtree.GetItemText(item) 3869 if 'PWDR' in name: 3870 data = self.GPXtree.GetItemPyData(item) 3871 if usedPhase: # remove r-factors 3872 dellist = [value for value in data[0] if ':' in value] 3873 for v in dellist+['Durbin-Watson', 'R', 'wR', 'Rb', 3874 'wRb', 'wRmin','Nobs']: 3875 if v in data[0]: del data[0][v] 3876 # could wipe out computed & difference patterns, but does not work 3877 #data[1][3] = np.zeros_like(data[1][3]) 3878 #data[1][5] = np.zeros_like(data[1][5]) 3879 # always get rid of reflection lists 3880 Id = GetGPXtreeItemId(self,item, 'Reflection Lists') 3881 refList = self.GPXtree.GetItemPyData(Id) 3882 if len(refList): 3883 for i,item in DelList: 3884 if item in refList: 3885 del(refList[item]) 3886 elif 'HKLF' in name and usedPhase: # probably not needed if phase is not used 3887 data = self.GPXtree.GetItemPyData(item) 3888 data[0] = {} 3889 3890 item, cookie = self.GPXtree.GetNextChild(self.root, cookie) 3891 finally: 3892 dlg.Destroy() 3893 if usedPhase: # clear info from last refinement for "deep clean" if a used phase is deleted 3894 id = GetGPXtreeItemId(self,self.root,'Covariance') 3895 if DelItemList and id: 3896 self.GPXtree.SetItemPyData(id,{}) 3897 id = GetGPXtreeItemId(self,self.root,'Sequential results') 3898 if DelItemList and id: 3899 self.GPXtree.Delete(id) 3900 if id == selItem: selItem = self.root 3901 # delete all plots 3902 for lbl in self.G2plotNB.plotList: 3903 self.G2plotNB.Delete(lbl) 3847 3904 if subr: #remove restraints for deleted phase 3848 3905 DelList = [itm[1] for itm in DelList] … … 3852 3909 if name in DelList: 3853 3910 self.GPXtree.Delete(item) 3854 item, cookie = self.GPXtree.GetNextChild(subr, cookie) 3855 3911 if item == selItem: selItem = self.root 3912 item, cookie = self.GPXtree.GetNextChild(subr, cookie) 3913 # force redisplay of current tree item if it was not deleted 3914 self.PickIdText = None 3915 SelectDataTreeItem(self,selItem) 3916 wx.CallAfter(self.GPXtree.SelectItem,selItem) 3917 if consDeleted: 3918 print('\n',consDeleted,'constraints were deleted') 3919 3856 3920 def OnRenameData(self,event): 3857 3921 'Renames an existing phase. Called by Data/Rename Phase menu' -
trunk/GSASIIpwdGUI.py
r4334 r4410 50 50 import GSASIIphsGUI as G2phsG 51 51 import GSASIIctrlGUI as G2G 52 import GSASIIIO as G2IO53 52 import GSASIIElemGUI as G2elemGUI 54 53 import GSASIIElem as G2elem … … 1872 1871 for l in dI.defaultIparm_lbl: 1873 1872 choices.append('Defaults for '+l) 1874 res = G2 IO.BlockSelector(choices,ParentFrame=G2frame,title=head,1873 res = G2G.BlockSelector(choices,ParentFrame=G2frame,title=head, 1875 1874 header='Select default inst parms',useCancel=True) 1876 1875 if res is None: return None -
trunk/imports/G2phase_CIF.py
r4399 r4410 25 25 import re 26 26 import copy 27 import GSASIIIO as G2IO28 27 import GSASIIobj as G2obj 29 28 import GSASIIspc as G2spc … … 32 31 import GSASIIpy3 as G2p3 33 32 import GSASIIpath 33 try: 34 import GSASIIctrlGUI as G2G 35 except ImportError: 36 pass 34 37 GSASIIpath.SetVersionNumber("$Revision$") 35 38 import CifFile as cif # PyCifRW from James Hester … … 132 135 sg = sg.replace('_','') 133 136 if sg: choice[-1] += ', (' + sg.strip() + ')' 134 selblk = G2 IO.PhaseSelector(choice,ParentFrame=ParentFrame,137 selblk = G2G.PhaseSelector(choice,ParentFrame=ParentFrame, 135 138 title= 'Select a phase from one the CIF data_ blocks below',size=(600,100)) 136 139 self.errors = 'Error during reading of selected block' … … 1152 1155 for atmline in self.Phase['Atoms']: 1153 1156 lbl = atmline[0] 1154 print( lbl,atmline[6],Occ[lbl])1157 if lbl in Occ: print( lbl,atmline[6],Occ[lbl]) 1155 1158 1156 1159 print( 70*'=') -
trunk/imports/G2phase_GPX.py
r3828 r4410 24 24 import random as ran 25 25 import GSASIIobj as G2obj 26 import GSASIIIO as G2IO27 26 import GSASIIstrIO as G2stIO 28 27 import GSASIIpath 28 try: 29 import GSASIIctrlGUI as G2G 30 except ImportError: 31 pass 29 32 GSASIIpath.SetVersionNumber("$Revision$") 30 33 … … 69 72 selblk = 0 70 73 else: # choose from options 71 selblk = G2 IO.PhaseSelector(phasenames,ParentFrame=ParentFrame,74 selblk = G2G.PhaseSelector(phasenames,ParentFrame=ParentFrame, 72 75 title= 'Select a phase from the list below',) 73 76 if selblk is None: -
trunk/imports/G2pwd_CIF.py
r4081 r4410 18 18 import os.path 19 19 import GSASIIobj as G2obj 20 import GSASIIIO as G2IO21 20 import CifFile as cif # PyCifRW from James Hester 22 21 import GSASIIpath 22 try: 23 import GSASIIctrlGUI as G2G 24 except ImportError: 25 pass 23 26 asind = lambda x: 180.*np.arcsin(x)/np.pi 24 27 GSASIIpath.SetVersionNumber("$Revision$") … … 182 185 'Block '+str(blk)+', '+str(l)+' points. X='+sx+' & Y='+sy 183 186 ) 184 selections = G2 IO.MultipleBlockSelector(187 selections = G2G.MultipleBlockSelector( 185 188 choices, 186 189 ParentFrame=ParentFrame, … … 221 224 chlbls.append('Divide intensities by data item') 222 225 choices.append(['none']+modch) 223 res = G2 IO.MultipleChoicesSelector(choices,chlbls)226 res = G2G.MultipleChoicesSelector(choices,chlbls) 224 227 if not res: 225 228 self.errors = "Abort: data items not selected" -
trunk/imports/G2sfact_CIF.py
r3245 r4410 19 19 import os.path 20 20 import GSASIIobj as G2obj 21 import GSASIIIO as G2IO22 21 import GSASIIpath 22 try: 23 import GSASIIctrlGUI as G2G 24 except ImportError: 25 pass 23 26 GSASIIpath.SetVersionNumber("$Revision$") 24 27 import CifFile as cif # PyCifRW from James Hester … … 163 166 if self.repeatcount >= len(blklist): self.repeat = False 164 167 else: 165 selblk = G2 IO.BlockSelector(168 selblk = G2G.BlockSelector( 166 169 choice, 167 170 ParentFrame=ParentFrame,
Note: See TracChangeset
for help on using the changeset viewer.