Changeset 1400


Ignore:
Timestamp:
Jun 30, 2014 10:53:00 AM (9 years ago)
Author:
toby
Message:

validatedtextcrtl fixes; add checkbox to scrolledmultieditor; print correct values in seq fit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1398 r1400  
    239239
    240240    :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.
    242242
    243243    '''
     
    310310        # When the mouse is moved away or the widget loses focus,
    311311        # 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)
    313313        self.Bind(wx.EVT_TEXT_ENTER, self._onLoseFocus)
    314314        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)
    315319
    316320    def SetValue(self,val):
     
    353357        if self.OKcontrol:
    354358            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                   
    356369    def _onStringKey(self,event):
    357370        event.Skip()
     
    413426
    414427    def _onLoseFocus(self,event):
    415         # wx 2.9 patch: may be unregistered changes since backspace is not seen
    416         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 patch
    420428        if self.evaluated:
    421429            self.EvaluateExpression()
     
    428436        if event: event.Skip()
    429437
    430     # def _onLeaveWindow(self,event):
    431     #     if self.evaluated:
    432     #         self.EvaluateExpression()
    433     #     elif self.result is not None: # show formatted result, as Bob wants
    434     #         self._setValue(self.result[self.key])
    435 
    436438    def EvaluateExpression(self):
    437439        '''Show the computed value when an expression is entered to the TextCtrl
    438440        Make sure that the number fits by truncating decimal places and switching
    439441        to scientific notation, as needed.
    440         Called on loss of focus.
     442        Called on loss of focus, enter, etc..
    441443        '''
    442444        if self.invalid: return # don't substitute for an invalid expression
     
    835837def CallScrolledMultiEditor(parent,dictlst,elemlst,prelbl=[],postlbl=[],
    836838                 title='Edit items',header='',size=(300,250),
    837                              CopyButton=False):
     839                             CopyButton=False, **kw):
    838840    '''Shell routine to call a ScrolledMultiEditor dialog. See
    839841    :class:`ScrolledMultiEditor` for parameter definitions.
     
    845847    dlg = ScrolledMultiEditor(parent,dictlst,elemlst,prelbl,postlbl,
    846848                              title,header,size,
    847                               CopyButton)
     849                              CopyButton, **kw)
    848850    if dlg.ShowModal() == wx.ID_OK:
    849851        dlg.Destroy()
     
    899901    :param list sizevals: optional list of wx.Size values for each input
    900902      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     
    901910    :returns: the wx.Dialog created here. Use method .ShowModal() to display it.
    902911   
     
    928937                 title='Edit items',header='',size=(300,250),
    929938                 CopyButton=False,
    930                  minvals=[],maxvals=[],sizevals=[]):
     939                 minvals=[],maxvals=[],sizevals=[],
     940                 checkdictlst=[], checkelemlst=[], checklabel=""):
    931941        if len(dictlst) != len(elemlst):
    932942            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))
    933945        wx.Dialog.__init__( # create dialog & sizer
    934946            self,parent,wx.ID_ANY,title,
     
    938950        self.dictlst = dictlst
    939951        self.elemlst = elemlst
     952        self.checkdictlst = checkdictlst
     953        self.checkelemlst = checkelemlst
     954        self.StartCheckValues = [checkdictlst[i][checkelemlst[i]] for i in range(len(checkdictlst))]
    940955        self.ButtonIndex = {}
    941956        for d,i in zip(dictlst,elemlst):
     
    956971            size=size,
    957972            style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
    958         cols = 3
     973        cols = 4
    959974        if CopyButton: cols += 1
    960975        subSizer = wx.FlexGridSizer(cols=cols,hgap=2,vgap=2)
    961976        self.ValidatedControlsList = [] # make list of TextCtrls
     977        self.CheckControlsList = [] # make list of CheckBoxes
    962978        for i,(d,k) in enumerate(zip(dictlst,elemlst)):
    963979            if i >= len(prelbl): # label before TextCtrl, or put in a blank
     
    9891005            self.ValidatedControlsList.append(ctrl)
    9901006            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:
    9921010                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)                   
    9931015            else:
    994                 subSizer.Add(wx.StaticText(panel,wx.ID_ANY,str(postlbl[i])))
     1016                subSizer.Add((-1,-1))
    9951017        # finish up ScrolledPanel
    9961018        panel.SetSizer(subSizer)
     
    10241046            d[k] = val
    10251047            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]])
    10271052    def _onClose(self,event):
    1028         'Restore original values & close the window'
     1053        'Used on Cancel: Restore original values & close the window'
    10291054        for d,i,v in zip(self.dictlst,self.elemlst,self.orig):
    10301055            d[i] = v
     1056        for i in range(len(self.checkdictlst)):
     1057            self.checkdictlst[i][self.checkelemlst[i]] = self.StartCheckValues[i]
    10311058        self.EndModal(wx.ID_CANCEL)
    10321059       
     
    41284155        print('==== Fit Results ====')
    41294156        for obj in eqObjList:
     4157            obj.UpdateVariedVars(varyList,values)
    41304158            ind = '      '
    41314159            print('  '+obj.GetDepVar()+' = '+obj.expression)
     
    41414169        # create a plot for each parametric variable
    41424170        for fitnum,obj in enumerate(eqObjList):
    4143             obj.UpdateVariedVars(varyList,values)
    41444171            calcobj = G2obj.ExpressionCalcObj(obj)
    41454172            # lookup dependent var position
     
    50395066    #======================================================================
    50405067    # 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]
    50465074    # elemlst = sorted(Data1.keys())
    5047     # postlbl = sorted(Data1.keys())
     5075    # prelbl = sorted(Data1.keys())
    50485076    # 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
    50495109
    50505110    # Data2 = list(range(100))
     
    50985158
    50995159    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)
    51085166    pnl.SetSizer(siz)
    51095167    siz.Fit(frm)
Note: See TracChangeset for help on using the changeset viewer.