Changeset 2899 for branch/2frame/GSASIIctrls.py
- Timestamp:
- Jul 3, 2017 4:12:45 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/2frame/GSASIIctrls.py
r2895 r2899 2776 2776 parent.Raise() 2777 2777 self.EndModal(wx.ID_OK) 2778 2779 ################################################################################ 2780 class DisAglDialog(wx.Dialog): 2781 '''Distance/Angle Controls input dialog. After 2782 :meth:`ShowModal` returns, the results are found in 2783 dict :attr:`self.data`, which is accessed using :meth:`GetData`. 2784 2785 :param wx.Frame parent: reference to parent frame (or None) 2786 :param dict data: a dict containing the current 2787 search ranges or an empty dict, which causes default values 2788 to be used. 2789 Will be used to set element `DisAglCtls` in 2790 :ref:`Phase Tree Item <Phase_table>` 2791 :param dict default: A dict containing the default 2792 search ranges for each element. 2793 :param bool Reset: if True (default), show Reset button 2794 :param bool Angle: if True (default), show angle radii 2795 ''' 2796 def __init__(self,parent,data,default,Reset=True,Angle=True): 2797 text = 'Distance Angle Controls' 2798 if not Angle: 2799 text = 'Distance Controls' 2800 wx.Dialog.__init__(self,parent,wx.ID_ANY,text, 2801 pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE) 2802 self.default = default 2803 self.Reset = Reset 2804 self.Angle = Angle 2805 self.panel = wx.Panel(self) #just a dummy - gets destroyed in Draw! 2806 self._default(data,self.default) 2807 self.Draw(self.data) 2808 2809 def _default(self,data,default): 2810 '''Set starting values for the search values, either from 2811 the input array or from defaults, if input is null 2812 ''' 2813 if data: 2814 self.data = copy.deepcopy(data) # don't mess with originals 2815 else: 2816 self.data = {} 2817 self.data['Name'] = default['Name'] 2818 self.data['Factors'] = [0.85,0.85] 2819 self.data['AtomTypes'] = default['AtomTypes'] 2820 self.data['BondRadii'] = default['BondRadii'][:] 2821 self.data['AngleRadii'] = default['AngleRadii'][:] 2822 2823 def Draw(self,data): 2824 '''Creates the contents of the dialog. Normally called 2825 by :meth:`__init__`. 2826 ''' 2827 self.panel.Destroy() 2828 self.panel = wx.Panel(self) 2829 mainSizer = wx.BoxSizer(wx.VERTICAL) 2830 mainSizer.Add(wx.StaticText(self.panel,-1,'Controls for phase '+data['Name']), 2831 0,WACV|wx.LEFT,10) 2832 mainSizer.Add((10,10),1) 2833 2834 ncol = 3 2835 if not self.Angle: 2836 ncol=2 2837 radiiSizer = wx.FlexGridSizer(0,ncol,5,5) 2838 radiiSizer.Add(wx.StaticText(self.panel,-1,' Type'),0,WACV) 2839 radiiSizer.Add(wx.StaticText(self.panel,-1,'Bond radii'),0,WACV) 2840 if self.Angle: 2841 radiiSizer.Add(wx.StaticText(self.panel,-1,'Angle radii'),0,WACV) 2842 self.objList = {} 2843 for id,item in enumerate(self.data['AtomTypes']): 2844 radiiSizer.Add(wx.StaticText(self.panel,-1,' '+item),0,WACV) 2845 bRadii = ValidatedTxtCtrl(self.panel,data['BondRadii'],id,nDig=(10,3)) 2846 radiiSizer.Add(bRadii,0,WACV) 2847 if self.Angle: 2848 aRadii = ValidatedTxtCtrl(self.panel,data['AngleRadii'],id,nDig=(10,3)) 2849 radiiSizer.Add(aRadii,0,WACV) 2850 mainSizer.Add(radiiSizer,0,wx.EXPAND) 2851 if self.Angle: 2852 factorSizer = wx.FlexGridSizer(0,2,5,5) 2853 Names = ['Bond','Angle'] 2854 for i,name in enumerate(Names): 2855 factorSizer.Add(wx.StaticText(self.panel,-1,name+' search factor'),0,WACV) 2856 bondFact = ValidatedTxtCtrl(self.panel,data['Factors'],i,nDig=(10,3)) 2857 factorSizer.Add(bondFact) 2858 mainSizer.Add(factorSizer,0,wx.EXPAND) 2859 2860 OkBtn = wx.Button(self.panel,-1,"Ok") 2861 OkBtn.Bind(wx.EVT_BUTTON, self.OnOk) 2862 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 2863 btnSizer.Add((20,20),1) 2864 btnSizer.Add(OkBtn) 2865 if self.Reset: 2866 ResetBtn = wx.Button(self.panel,-1,'Reset') 2867 ResetBtn.Bind(wx.EVT_BUTTON, self.OnReset) 2868 btnSizer.Add(ResetBtn) 2869 btnSizer.Add((20,20),1) 2870 mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 2871 self.panel.SetSizer(mainSizer) 2872 self.panel.Fit() 2873 self.Fit() 2874 2875 def GetData(self): 2876 'Returns the values from the dialog' 2877 return self.data 2878 2879 def OnOk(self,event): 2880 'Called when the OK button is pressed' 2881 parent = self.GetParent() 2882 parent.Raise() 2883 self.EndModal(wx.ID_OK) 2884 2885 def OnReset(self,event): 2886 'Called when the Reset button is pressed' 2887 data = {} 2888 self._default(data,self.default) 2889 self.Draw(self.data) 2890 2891 ################################################################################ 2892 class ShowLSParms(wx.Dialog): 2893 '''Create frame to show least-squares parameters 2894 ''' 2895 def __init__(self,parent,title,parmDict,varyList,fullVaryList, 2896 size=(375,430)): 2897 2898 wx.Dialog.__init__(self,parent,wx.ID_ANY,title,size=size, 2899 style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) 2900 self.panel = wxscroll.ScrolledPanel(self) #just a dummy - gets destroyed in DrawPanel! 2901 self.parmChoice = 'Phase' 2902 self.parmDict = parmDict 2903 self.varyList = varyList 2904 self.fullVaryList = fullVaryList 2905 2906 self.parmNames = parmDict.keys() 2907 self.parmNames.sort() 2908 splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],basestring)] 2909 self.globNames = [':'.join(item) for item in splitNames if not item[0] and not item[1]] 2910 self.globVars = list(set([' ',]+[item[2] for item in splitNames if not item[0] and not item[1]])) 2911 self.globVars.sort() 2912 self.hisNames = [':'.join(item) for item in splitNames if not item[0] and item[1]] 2913 self.hisNums = list(set([int(item.split(':')[1]) for item in self.hisNames])) 2914 self.hisNums.sort() 2915 self.hisNums = [' ',]+[str(item) for item in self.hisNums] 2916 self.hisVars = list(set([' ',]+[item[2] for item in splitNames if not item[0]])) 2917 self.hisVars.sort() 2918 self.phasNames = [':'.join(item) for item in splitNames if not item[1] and 'is' not in item[2]] 2919 self.phasNums = [' ',]+list(set([item.split(':')[0] for item in self.phasNames])) 2920 if '' in self.phasNums: self.phasNums.remove('') 2921 self.phasVars = list(set([' ',]+[item[2] for item in splitNames if not item[1] and 'is' not in item[2]])) 2922 self.phasVars.sort() 2923 self.phasNums.sort() 2924 self.hapNames = [':'.join(item) for item in splitNames if item[0] and item[1]] 2925 self.hapVars = list(set([' ',]+[item[2] for item in splitNames if item[0] and item[1]])) 2926 self.hapVars.sort() 2927 self.hisNum = ' ' 2928 self.phasNum = ' ' 2929 self.varName = ' ' 2930 self.listSel = 'Refined' 2931 self.DrawPanel() 2932 2933 2934 def DrawPanel(self): 2935 2936 def _OnParmSel(event): 2937 self.parmChoice = parmSel.GetStringSelection() 2938 self.varName = ' ' 2939 wx.CallLater(100,self.DrawPanel) 2940 2941 def OnPhasSel(event): 2942 event.Skip() 2943 self.phasNum = phasSel.GetValue() 2944 self.varName = ' ' 2945 wx.CallLater(100,self.DrawPanel) 2946 2947 def OnHistSel(event): 2948 event.Skip() 2949 self.hisNum = histSel.GetValue() 2950 self.varName = ' ' 2951 wx.CallLater(100,self.DrawPanel) 2952 2953 def OnVarSel(event): 2954 self.varName = varSel.GetValue() 2955 self.phasNum = ' ' 2956 self.hisNum = ' ' 2957 wx.CallLater(100,self.DrawPanel) 2958 2959 def OnListSel(event): 2960 self.listSel = listSel.GetStringSelection() 2961 wx.CallLater(100,self.DrawPanel) 2962 2963 if self.panel: 2964 #self.panel.DestroyChildren() # Bad on Mac: deletes scroll bars 2965 sizer = self.panel.GetSizer() 2966 if sizer: sizer.DeleteWindows() 2967 2968 mainSizer = wx.BoxSizer(wx.VERTICAL) 2969 num = len(self.varyList) 2970 mainSizer.Add(wx.StaticText(self.panel,label=' Number of refined variables: '+str(num)),0) 2971 if len(self.varyList) != len(self.fullVaryList): 2972 num = len(self.fullVaryList) - len(self.varyList) 2973 mainSizer.Add(wx.StaticText(self.panel,label=' + '+str(num)+' parameters are varied via constraints')) 2974 choiceDict = {'Global':self.globNames,'Phase':self.phasNames,'Phase/Histo':self.hapNames,'Histogram':self.hisNames} 2975 choice = ['Phase','Phase/Histo','Histogram'] 2976 if len(self.globNames): 2977 choice += ['Global',] 2978 parmSizer = wx.FlexGridSizer(0,3,5,5) 2979 parmSel = wx.RadioBox(self.panel,wx.ID_ANY,'Parameter type:',choices=choice, 2980 majorDimension=1,style=wx.RA_SPECIFY_COLS) 2981 parmSel.Bind(wx.EVT_RADIOBOX,_OnParmSel) 2982 parmSel.SetStringSelection(self.parmChoice) 2983 parmSizer.Add(parmSel,0) 2984 numSizer = wx.BoxSizer(wx.VERTICAL) 2985 numSizer.Add((5,25),0) 2986 if self.parmChoice in ['Phase','Phase/Histo'] and len(self.phasNums) > 1: 2987 numSizer.Add(wx.StaticText(self.panel,label='Phase'),0) 2988 phasSel = wx.ComboBox(self.panel,choices=self.phasNums,value=self.phasNum, 2989 style=wx.CB_READONLY|wx.CB_DROPDOWN) 2990 phasSel.Bind(wx.EVT_COMBOBOX,OnPhasSel) 2991 numSizer.Add(phasSel,0) 2992 if self.parmChoice in ['Histogram','Phase/Histo'] and len(self.hisNums) > 1: 2993 numSizer.Add(wx.StaticText(self.panel,label='Histogram'),0) 2994 histSel = wx.ComboBox(self.panel,choices=self.hisNums,value=self.hisNum, 2995 style=wx.CB_READONLY|wx.CB_DROPDOWN) 2996 histSel.Bind(wx.EVT_COMBOBOX,OnHistSel) 2997 # histSel = wx.TextCtrl(self.panel,size=(50,25),value='0',style=wx.TE_PROCESS_ENTER) 2998 # histSel.Bind(wx.EVT_TEXT_ENTER,OnHistSel) 2999 # histSel.Bind(wx.EVT_KILL_FOCUS,OnHistSel) 3000 numSizer.Add(histSel,0) 3001 parmSizer.Add(numSizer) 3002 varSizer = wx.BoxSizer(wx.VERTICAL) 3003 if self.parmChoice in ['Phase',]: 3004 varSel = wx.ComboBox(self.panel,choices=self.phasVars,value=self.varName, 3005 style=wx.CB_READONLY|wx.CB_DROPDOWN) 3006 varSel.Bind(wx.EVT_COMBOBOX,OnVarSel) 3007 elif self.parmChoice in ['Histogram',]: 3008 varSel = wx.ComboBox(self.panel,choices=self.hisVars,value=self.varName, 3009 style=wx.CB_READONLY|wx.CB_DROPDOWN) 3010 varSel.Bind(wx.EVT_COMBOBOX,OnVarSel) 3011 elif self.parmChoice in ['Phase/Histo',]: 3012 varSel = wx.ComboBox(self.panel,choices=self.hapVars,value=self.varName, 3013 style=wx.CB_READONLY|wx.CB_DROPDOWN) 3014 varSel.Bind(wx.EVT_COMBOBOX,OnVarSel) 3015 if self.parmChoice != 'Global': 3016 varSizer.Add(wx.StaticText(self.panel,label='Parameter')) 3017 varSizer.Add(varSel,0) 3018 parmSizer.Add(varSizer,0) 3019 mainSizer.Add(parmSizer,0) 3020 listChoice = ['All','Refined'] 3021 listSel = wx.RadioBox(self.panel,wx.ID_ANY,'Parameter type:',choices=listChoice, 3022 majorDimension=0,style=wx.RA_SPECIFY_COLS) 3023 listSel.SetStringSelection(self.listSel) 3024 listSel.Bind(wx.EVT_RADIOBOX,OnListSel) 3025 mainSizer.Add(listSel,0) 3026 subSizer = wx.FlexGridSizer(cols=4,hgap=2,vgap=2) 3027 subSizer.Add((-1,-1)) 3028 subSizer.Add(wx.StaticText(self.panel,wx.ID_ANY,'Parameter name ')) 3029 subSizer.Add(wx.StaticText(self.panel,wx.ID_ANY,'refine?')) 3030 subSizer.Add(wx.StaticText(self.panel,wx.ID_ANY,'value'),0,wx.ALIGN_RIGHT) 3031 explainRefine = False 3032 for name in choiceDict[self.parmChoice]: 3033 # skip entries without numerical values 3034 if isinstance(self.parmDict[name],basestring): continue 3035 if 'Refined' in self.listSel and (name not in self.fullVaryList 3036 ) and (name not in self.varyList): 3037 continue 3038 if 'Phase' in self.parmChoice: 3039 if self.phasNum != ' ' and name.split(':')[0] != self.phasNum: continue 3040 if 'Histo' in self.parmChoice: 3041 if self.hisNum != ' ' and name.split(':')[1] != self.hisNum: continue 3042 if (self.varName != ' ') and (self.varName not in name): continue 3043 try: 3044 value = G2py3.FormatSigFigs(self.parmDict[name]) 3045 except TypeError: 3046 value = str(self.parmDict[name])+' -?' # unexpected 3047 #continue 3048 v = G2obj.getVarDescr(name) 3049 if v is None or v[-1] is None: 3050 subSizer.Add((-1,-1)) 3051 else: 3052 ch = HelpButton(self.panel,G2obj.fmtVarDescr(name)) 3053 subSizer.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1) 3054 subSizer.Add(wx.StaticText(self.panel,wx.ID_ANY,str(name))) 3055 if name in self.varyList: 3056 subSizer.Add(wx.StaticText(self.panel,label='R')) #TODO? maybe a checkbox for one stop refinemnt flag setting? 3057 elif name in self.fullVaryList: 3058 subSizer.Add(wx.StaticText(self.panel,label='C')) 3059 explainRefine = True 3060 else: 3061 subSizer.Add((-1,-1)) 3062 subSizer.Add(wx.StaticText(self.panel,label=value),0,wx.ALIGN_RIGHT) 3063 3064 mainSizer.Add(subSizer,0) 3065 if explainRefine: 3066 mainSizer.Add( 3067 wx.StaticText(self.panel,label='"R" indicates a refined variable\n'+ 3068 '"C" indicates generated from a constraint'),0, wx.ALL,0) 3069 # make OK button 3070 btnsizer = wx.BoxSizer(wx.HORIZONTAL) 3071 btn = wx.Button(self.panel, wx.ID_CLOSE,"Close") 3072 btn.Bind(wx.EVT_BUTTON,self._onClose) 3073 btnsizer.Add(btn) 3074 mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5) 3075 # Allow window to be enlarged but not made smaller 3076 self.panel.SetSizer(mainSizer) 3077 self.panel.SetAutoLayout(1) 3078 self.panel.SetupScrolling() 3079 self.panel.SetMinSize(self.GetSize()) 3080 3081 def _onClose(self,event): 3082 self.EndModal(wx.ID_CANCEL) 2778 3083 2779 3084 ################################################################################
Note: See TracChangeset
for help on using the changeset viewer.