Changeset 3772
- Timestamp:
- Dec 23, 2018 6:02:12 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r3759 r3772 566 566 return 567 567 568 objectScanIgnore = [int,bool,float,str,np.float64,np.int32,np.int64,np.ndarray,G2obj.G2VarObj ]568 objectScanIgnore = [int,bool,float,str,np.float64,np.int32,np.int64,np.ndarray,G2obj.G2VarObj,G2obj.ExpressionObj] 569 569 try: 570 570 objectScanIgnore += [ma.MaskedArray] # fails in doc builds -
trunk/GSASIIexprGUI.py
r3458 r3772 107 107 may be a list with parameter values and a refine flag or may just contain 108 108 the parameter value (non-float/int values in dict are ignored) 109 :param strexprObj: a :class:`GSASIIobj.ExpressionObj` object with an expression and109 :param exprObj: a :class:`GSASIIobj.ExpressionObj` object with an expression and 110 110 label assignments or None (default) 111 111 :param str wintitle: String placed on title bar of dialog; … … 114 114 what they will do here; default is "Enter restraint expression here" 115 115 :param bool fit: determines if the expression will be used in fitting (default=True). 116 If set to False, andrefinement flags are not shown116 If set to False, refinement flags are not shown 117 117 and Free parameters are not offered as an assignment option. 118 118 :param str VarLabel: an optional variable label to include before the expression -
trunk/GSASIIrestrGUI.py
r3682 r3772 31 31 import GSASIIctrlGUI as G2G 32 32 import GSASIIphsGUI as G2phsGUI 33 import GSASIIobj as G2obj 34 import GSASIIconstrGUI as G2cnstG 35 import GSASIIexprGUI as G2exG 33 36 34 37 WACV = wx.ALIGN_CENTER_VERTICAL … … 151 154 finally: 152 155 dlg.Destroy() 153 156 157 def SetupParmDict(G2frame): 158 '''Creates a parameter dict with variable names as keys and 159 numerical values (only) 160 ''' 161 G2cnstG.CheckAllScalePhaseFractions(G2frame) 162 try: 163 parmDict,varyList = G2frame.MakeLSParmDict() 164 except: 165 print('Error retrieving parameters') 166 return {} 167 return {i:parmDict[i][0] for i in parmDict} 168 154 169 def OnAddRestraint(event): 170 '''Adds a restraint depending on which tab is currently displayed''' 155 171 page = G2frame.restrBook.GetSelection() 156 172 if 'Bond' in G2frame.restrBook.GetPageText(page): … … 164 180 elif 'Texture' in G2frame.restrBook.GetPageText(page): 165 181 AddTextureRestraint(restrData['Texture']) 182 elif 'General' in G2frame.restrBook.GetPageText(page): 183 parmDict = SetupParmDict(G2frame) 184 dlg = G2exG.ExpressionDialog(G2frame,parmDict, 185 header="Create a restraint expression", 186 fit=False,wildCard=G2frame.testSeqRefineMode()) 187 restobj = dlg.Show(True) 188 if restobj: 189 restrData['General'].append([restobj,0.0,1.0]) 190 wx.CallAfter(UpdateGeneralRestr,restrData['General']) 166 191 167 192 def OnAddAARestraint(event): … … 1830 1855 G2phsGUI.SetPhaseWindow(TextureRestr,mainSizer,Scroll=0) 1831 1856 1857 def UpdateGeneralRestr(generalRestData): 1858 '''Display any generalized restraint expressions''' 1859 def OnEditGenRestraint(event): 1860 '''Edit a restraint expression''' 1861 n = event.GetEventObject().index 1862 parmDict = SetupParmDict(G2frame) 1863 dlg = G2exG.ExpressionDialog(G2frame,parmDict, 1864 exprObj=generalRestData[n][0], 1865 header="Edit a restraint expression", 1866 fit=False,wildCard=G2frame.testSeqRefineMode()) 1867 restobj = dlg.Show(True) 1868 if restobj: 1869 generalRestData[n][0] = restobj 1870 wx.CallAfter(UpdateGeneralRestr,restrData['General']) 1871 def OnDelGenRestraint(event): 1872 '''Delete a restraint expression''' 1873 n = event.GetEventObject().index 1874 del generalRestData[n] 1875 wx.CallAfter(UpdateGeneralRestr,restrData['General']) 1876 1877 if GeneralRestr.GetSizer(): GeneralRestr.GetSizer().Clear(True) 1878 mainSizer = wx.BoxSizer(wx.VERTICAL) 1879 mainSizer.Add((5,5),0) 1880 mainSizer.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,'(not implemented yet)')) 1881 btn = wx.Button(GeneralRestr, wx.ID_ANY,"Add restraint") 1882 btn.Bind(wx.EVT_BUTTON,OnAddRestraint) 1883 mainSizer.Add(btn,0,wx.ALIGN_CENTER) 1884 mainSizer.Add((5,5),0) 1885 if generalRestData: 1886 parmDict = SetupParmDict(G2frame) 1887 GridSiz = wx.FlexGridSizer(0,7,10,2) 1888 for lbl in ('expression','target\nvalue','current\nvalue','weight'): 1889 GridSiz.Add( 1890 wx.StaticText(GeneralRestr,wx.ID_ANY,lbl,style=wx.CENTER), 1891 0,wx.ALIGN_CENTER) 1892 GridSiz.Add((-1,-1)) 1893 GridSiz.Add((-1,-1)) 1894 GridSiz.Add( 1895 wx.StaticText(GeneralRestr,wx.ID_ANY,'Variables',style=wx.CENTER), 1896 0,wx.ALIGN_CENTER) 1897 for i,rest in enumerate(generalRestData): 1898 txt = rest[0].expression 1899 if len(txt) > 50: 1900 txt = txt[:47]+'... ' 1901 GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt)) 1902 GridSiz.Add( 1903 G2G.ValidatedTxtCtrl(GeneralRestr,rest,1,nDig=(10,2),typeHint=float) 1904 ) 1905 # evaluate the expression 1906 try: 1907 calcobj = G2obj.ExpressionCalcObj(rest[0]) 1908 calcobj.SetupCalc(parmDict) 1909 txt = '{:f}'.format(calcobj.EvalExpression()) 1910 except: 1911 txt = '(error)' 1912 GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt)) 1913 GridSiz.Add( 1914 G2G.ValidatedTxtCtrl(GeneralRestr,rest,2,nDig=(10,1),typeHint=float) 1915 ) 1916 btn = wx.Button(GeneralRestr, wx.ID_ANY,"Edit",size=(40,-1)) 1917 btn.index = i 1918 btn.Bind(wx.EVT_BUTTON,OnEditGenRestraint) 1919 GridSiz.Add(btn) 1920 btn = wx.Button(GeneralRestr, wx.ID_ANY,"Delete",size=(60,-1)) 1921 btn.index = i 1922 btn.Bind(wx.EVT_BUTTON,OnDelGenRestraint) 1923 GridSiz.Add(btn) 1924 txt = str(rest[0].assgnVars)[1:-1].replace("'","") 1925 if len(txt) > 50: 1926 txt = txt[:47]+'...' 1927 GridSiz.Add(wx.StaticText(GeneralRestr,wx.ID_ANY,txt)) 1928 mainSizer.Add(GridSiz) 1929 G2phsGUI.SetPhaseWindow(GeneralRestr,mainSizer,Scroll=0) 1930 1931 1832 1932 def OnPageChanged(event): 1833 1933 page = event.GetSelection() … … 1891 1991 textureRestData = restrData['Texture'] 1892 1992 UpdateTextureRestr(textureRestData) 1993 elif text == 'General': 1994 G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.RestraintMenu) 1995 G2frame.dataWindow.RestraintEdit.Enable(G2G.wxID_RESTRAINTADD,True) 1996 G2frame.dataWindow.RestraintEdit.Enable(G2G.wxID_RESRCHANGEVAL,False) 1997 UpdateGeneralRestr(restrData['General']) 1893 1998 event.Skip() 1894 1999 … … 1947 2052 if 'ChemComp' not in restrData: 1948 2053 restrData['ChemComp'] = {'wtFactor':1.0,'Sites':[],'Use':True} 2054 if 'General' not in restrData: restrData['General'] = [] 1949 2055 General = phasedata['General'] 1950 2056 Cell = General['Cell'][1:7] #skip flag & volume … … 2022 2128 Pages.append(txt) 2023 2129 2130 if GSASIIpath.GetConfigValue('debug'): 2131 txt = 'General' 2132 GeneralRestr = wx.ScrolledWindow(G2frame.restrBook) 2133 G2frame.restrBook.AddPage(GeneralRestr,txt) 2134 Pages.append(txt) 2135 2024 2136 if General['SH Texture']['Order']: 2025 2137 txt = 'Texture'
Note: See TracChangeset
for help on using the changeset viewer.