Changeset 1400
- Timestamp:
- Jun 30, 2014 10:53:00 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r1398 r1400 239 239 240 240 :param (other): other optional keyword parameters for the 241 wx.TextCtrl widget such as Size or Style may be specified.241 wx.TextCtrl widget such as size or style may be specified. 242 242 243 243 ''' … … 310 310 # When the mouse is moved away or the widget loses focus, 311 311 # display the last saved value, if an expression 312 # self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow) #leads to weird behavior 312 #self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow) 313 313 self.Bind(wx.EVT_TEXT_ENTER, self._onLoseFocus) 314 314 self.Bind(wx.EVT_KILL_FOCUS, self._onLoseFocus) 315 # patch for wx 2.9 on Mac 316 i,j= wx.__version__.split('.')[0:2] 317 if int(i)+int(j)/10. > 2.8 and 'wxOSX' in wx.PlatformInfo: 318 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) 315 319 316 320 def SetValue(self,val): … … 353 357 if self.OKcontrol: 354 358 self.OKcontrol(not self.invalid) 355 359 360 def OnKeyDown(self,event): 361 'Special callback for wx 2.9+ on Mac where backspace is not processed by validator' 362 key = event.GetKeyCode() 363 if key in [wx.WXK_BACK, wx.WXK_DELETE]: 364 if self.Validator: wx.CallAfter(self.Validator.TestValid,self) 365 if key == wx.WXK_RETURN: 366 self._onLoseFocus(None) 367 event.Skip() 368 356 369 def _onStringKey(self,event): 357 370 event.Skip() … … 413 426 414 427 def _onLoseFocus(self,event): 415 # wx 2.9 patch: may be unregistered changes since backspace is not seen416 i,j= wx.__version__.split('.')[0:2]417 if int(i)+int(j)/10. > 2.8:418 if self.Validator: self.Validator.TestValid(self)419 # end patch420 428 if self.evaluated: 421 429 self.EvaluateExpression() … … 428 436 if event: event.Skip() 429 437 430 # def _onLeaveWindow(self,event):431 # if self.evaluated:432 # self.EvaluateExpression()433 # elif self.result is not None: # show formatted result, as Bob wants434 # self._setValue(self.result[self.key])435 436 438 def EvaluateExpression(self): 437 439 '''Show the computed value when an expression is entered to the TextCtrl 438 440 Make sure that the number fits by truncating decimal places and switching 439 441 to scientific notation, as needed. 440 Called on loss of focus .442 Called on loss of focus, enter, etc.. 441 443 ''' 442 444 if self.invalid: return # don't substitute for an invalid expression … … 835 837 def CallScrolledMultiEditor(parent,dictlst,elemlst,prelbl=[],postlbl=[], 836 838 title='Edit items',header='',size=(300,250), 837 CopyButton=False ):839 CopyButton=False, **kw): 838 840 '''Shell routine to call a ScrolledMultiEditor dialog. See 839 841 :class:`ScrolledMultiEditor` for parameter definitions. … … 845 847 dlg = ScrolledMultiEditor(parent,dictlst,elemlst,prelbl,postlbl, 846 848 title,header,size, 847 CopyButton )849 CopyButton, **kw) 848 850 if dlg.ShowModal() == wx.ID_OK: 849 851 dlg.Destroy() … … 899 901 :param list sizevals: optional list of wx.Size values for each input 900 902 widget. Ignored if value is None. 903 904 :param tuple checkdictlst: an optional list of dicts or lists containing bool 905 values (similar to dictlst). 906 :param tuple checkelemlst: an optional list of dicts or lists containing bool 907 key values (similar to elemlst). Must be used with checkdictlst. 908 :param string checklabel: a string to use for each checkbutton 909 901 910 :returns: the wx.Dialog created here. Use method .ShowModal() to display it. 902 911 … … 928 937 title='Edit items',header='',size=(300,250), 929 938 CopyButton=False, 930 minvals=[],maxvals=[],sizevals=[]): 939 minvals=[],maxvals=[],sizevals=[], 940 checkdictlst=[], checkelemlst=[], checklabel=""): 931 941 if len(dictlst) != len(elemlst): 932 942 raise Exception,"ScrolledMultiEditor error: len(dictlst) != len(elemlst) "+str(len(dictlst))+" != "+str(len(elemlst)) 943 if len(checkdictlst) != len(checkelemlst): 944 raise Exception,"ScrolledMultiEditor error: len(checkdictlst) != len(checkelemlst) "+str(len(checkdictlst))+" != "+str(len(checkelemlst)) 933 945 wx.Dialog.__init__( # create dialog & sizer 934 946 self,parent,wx.ID_ANY,title, … … 938 950 self.dictlst = dictlst 939 951 self.elemlst = elemlst 952 self.checkdictlst = checkdictlst 953 self.checkelemlst = checkelemlst 954 self.StartCheckValues = [checkdictlst[i][checkelemlst[i]] for i in range(len(checkdictlst))] 940 955 self.ButtonIndex = {} 941 956 for d,i in zip(dictlst,elemlst): … … 956 971 size=size, 957 972 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER) 958 cols = 3973 cols = 4 959 974 if CopyButton: cols += 1 960 975 subSizer = wx.FlexGridSizer(cols=cols,hgap=2,vgap=2) 961 976 self.ValidatedControlsList = [] # make list of TextCtrls 977 self.CheckControlsList = [] # make list of CheckBoxes 962 978 for i,(d,k) in enumerate(zip(dictlst,elemlst)): 963 979 if i >= len(prelbl): # label before TextCtrl, or put in a blank … … 989 1005 self.ValidatedControlsList.append(ctrl) 990 1006 subSizer.Add(ctrl) 991 if i >= len(postlbl): # label after TextCtrl, or put in a blank 1007 if i < len(postlbl): # label after TextCtrl, or put in a blank 1008 subSizer.Add(wx.StaticText(panel,wx.ID_ANY,str(postlbl[i]))) 1009 else: 992 1010 subSizer.Add((-1,-1)) 1011 if i < len(checkdictlst): 1012 ch = G2CheckBox(panel,checklabel,checkdictlst[i],checkelemlst[i]) 1013 self.CheckControlsList.append(ch) 1014 subSizer.Add(ch) 993 1015 else: 994 subSizer.Add( wx.StaticText(panel,wx.ID_ANY,str(postlbl[i])))1016 subSizer.Add((-1,-1)) 995 1017 # finish up ScrolledPanel 996 1018 panel.SetSizer(subSizer) … … 1024 1046 d[k] = val 1025 1047 ctrl.SetValue(val) 1026 1048 for i in range(len(self.checkdictlst)): 1049 if i < n: continue 1050 self.checkdictlst[i][self.checkelemlst[i]] = self.checkdictlst[n][self.checkelemlst[n]] 1051 self.CheckControlsList[i].SetValue(self.checkdictlst[i][self.checkelemlst[i]]) 1027 1052 def _onClose(self,event): 1028 ' Restore original values & close the window'1053 'Used on Cancel: Restore original values & close the window' 1029 1054 for d,i,v in zip(self.dictlst,self.elemlst,self.orig): 1030 1055 d[i] = v 1056 for i in range(len(self.checkdictlst)): 1057 self.checkdictlst[i][self.checkelemlst[i]] = self.StartCheckValues[i] 1031 1058 self.EndModal(wx.ID_CANCEL) 1032 1059 … … 4128 4155 print('==== Fit Results ====') 4129 4156 for obj in eqObjList: 4157 obj.UpdateVariedVars(varyList,values) 4130 4158 ind = ' ' 4131 4159 print(' '+obj.GetDepVar()+' = '+obj.expression) … … 4141 4169 # create a plot for each parametric variable 4142 4170 for fitnum,obj in enumerate(eqObjList): 4143 obj.UpdateVariedVars(varyList,values)4144 4171 calcobj = G2obj.ExpressionCalcObj(obj) 4145 4172 # lookup dependent var position … … 5039 5066 #====================================================================== 5040 5067 # Data1 = { 5041 # 'Order':1, 5042 # 'omega':'string', 5043 # 'chi':2.0, 5044 # 'phi':'', 5045 # } 5068 # 'Order':1, 5069 # 'omega':'string', 5070 # 'chi':2.0, 5071 # 'phi':'', 5072 # } 5073 # Data2 = [True,False,False,True] 5046 5074 # elemlst = sorted(Data1.keys()) 5047 # p ostlbl = sorted(Data1.keys())5075 # prelbl = sorted(Data1.keys()) 5048 5076 # dictlst = len(elemlst)*[Data1,] 5077 # Checkdictlst = len(elemlst)*[Data2,] 5078 # Checkelemlst = range(len(Checkdictlst)) 5079 # print 'before',Data1,'\n',Data2 5080 # dlg = ScrolledMultiEditor( 5081 # frm,dictlst,elemlst,prelbl, 5082 # checkdictlst=Checkdictlst,checkelemlst=Checkelemlst, 5083 # checklabel="Refine?", 5084 # header="test") 5085 # if dlg.ShowModal() == wx.ID_OK: 5086 # print "OK" 5087 # else: 5088 # print "Cancel" 5089 # print 'after',Data1,'\n',Data2 5090 # dlg.Destroy() 5091 # Data3 = { 5092 # 'Order':1.0, 5093 # 'omega':1.1, 5094 # 'chi':2.0, 5095 # 'phi':2.3, 5096 # } 5097 # dictlst = len(elemlst)*[Data3,] 5098 # print 'before',Data3,'\n',Data2 5099 # dlg = ScrolledMultiEditor( 5100 # frm,dictlst,elemlst,prelbl, 5101 # checkdictlst=Checkdictlst,checkelemlst=Checkelemlst, 5102 # checklabel="Refine?", 5103 # header="test",CopyButton=True) 5104 # if dlg.ShowModal() == wx.ID_OK: 5105 # print "OK" 5106 # else: 5107 # print "Cancel" 5108 # print 'after',Data3,'\n',Data2 5049 5109 5050 5110 # Data2 = list(range(100)) … … 5098 5158 5099 5159 pnl = wx.Panel(frm) 5100 siz = wx.BoxSizer(wx.HORIZONTAL) 5101 5102 td = {'Goni':200.,'a':1} 5103 txt = ValidatedTxtCtrl(pnl,td,'Goni') 5104 siz.Add(txt) 5105 txt = ValidatedTxtCtrl(pnl,td,'a') 5106 siz.Add(txt) 5107 5160 siz = wx.BoxSizer(wx.VERTICAL) 5161 5162 td = {'Goni':200.,'a':1.,'calc':1./3.,'string':'s'} 5163 for key in sorted(td): 5164 txt = ValidatedTxtCtrl(pnl,td,key) 5165 siz.Add(txt) 5108 5166 pnl.SetSizer(siz) 5109 5167 siz.Fit(frm)
Note: See TracChangeset
for help on using the changeset viewer.