Changeset 1138 for trunk/GSASIIgrid.py


Ignore:
Timestamp:
Nov 7, 2013 12:12:55 PM (10 years ago)
Author:
toby
Message:

major constraints revision

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1128 r1138  
    118118
    119119[ wxID_CONSTRAINTADD,wxID_EQUIVADD,wxID_HOLDADD,wxID_FUNCTADD,
    120 ] = [wx.NewId() for item in range(4)]
     120  wxID_CONSPHASE, wxID_CONSHIST, wxID_CONSHAP, wxID_CONSGLOBAL,
     121] = [wx.NewId() for item in range(8)]
    121122
    122123[ wxID_RESTRAINTADD, wxID_RESTSELPHASE,wxID_RESTDELETE, wxID_RESRCHANGEVAL,
     
    279280            else:
    280281                self.invalid = False
     282                self.Bind(wx.EVT_CHAR,self._GetStringValue)
    281283        elif val is None:
    282284            raise Exception,("ValidatedTxtCtrl error: value of "+str(key)+
     
    360362        elif self.OKcontrol and previousInvalid:
    361363            self.OKcontrol(True)
     364        # always store the result
     365        if self.CIFinput: # for CIF make results ASCII
     366            self.result[self.key] = val.encode('ascii','replace')
     367        else:
     368            self.result[self.key] = val
     369
     370    def _GetStringValue(self,event):
     371        '''Get string input and store.
     372        '''
     373        event.Skip() # process keystroke
     374        wx.CallAfter(self._SaveStringValue)
     375       
     376    def _SaveStringValue(self):
     377        val = self.GetValue().strip()
    362378        # always store the result
    363379        if self.CIFinput: # for CIF make results ASCII
     
    13211337    :param str header: Title to place on window frame
    13221338    :param list ChoiceList: a list of choices where one will be selected
     1339    :param bool toggle: If True (default) the toggle and select all buttons
     1340      are displayed
    13231341
    13241342    :param kw: optional keyword parameters for the wx.Dialog may
    1325       be included such as Size [which defaults to `(320,310)`] and
    1326       Style (which defaults to `wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL`);
     1343      be included such as size [which defaults to `(320,310)`] and
     1344      style (which defaults to `wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTRE| wx.OK | wx.CANCEL`);
    13271345      note that `wx.OK` and `wx.CANCEL` controls
    13281346      the presence of the eponymous buttons in the dialog.
    13291347    :returns: the name of the created dialog 
    13301348    '''
    1331     def __init__(self,parent, title, header, ChoiceList, **kw):
     1349    def __init__(self,parent, title, header, ChoiceList, toggle=True, **kw):
    13321350        # process keyword parameters, notably Style
    13331351        options = {'size':(320,310), # default Frame keywords
     
    13551373        Sizer.Add((-1,10))
    13561374        # set/toggle buttons
    1357         bSizer = wx.BoxSizer(wx.VERTICAL)
    1358         setBut = wx.Button(self,wx.ID_ANY,'Set All')
    1359         setBut.Bind(wx.EVT_BUTTON,self._SetAll)
    1360         bSizer.Add(setBut,0,wx.ALIGN_CENTER)
    1361         bSizer.Add((-1,5))
    1362         togBut = wx.Button(self,wx.ID_ANY,'Toggle All')
    1363         togBut.Bind(wx.EVT_BUTTON,self._ToggleAll)
    1364         bSizer.Add(togBut,0,wx.ALIGN_CENTER)
    1365         Sizer.Add(bSizer,0,wx.LEFT,12)
     1375        if toggle:
     1376            bSizer = wx.BoxSizer(wx.VERTICAL)
     1377            setBut = wx.Button(self,wx.ID_ANY,'Set All')
     1378            setBut.Bind(wx.EVT_BUTTON,self._SetAll)
     1379            bSizer.Add(setBut,0,wx.ALIGN_CENTER)
     1380            bSizer.Add((-1,5))
     1381            togBut = wx.Button(self,wx.ID_ANY,'Toggle All')
     1382            togBut.Bind(wx.EVT_BUTTON,self._ToggleAll)
     1383            bSizer.Add(togBut,0,wx.ALIGN_CENTER)
     1384            Sizer.Add(bSizer,0,wx.LEFT,12)
    13661385        # OK/Cancel buttons
    13671386        btnsizer = wx.StdDialogButtonSizer()
     
    18521871
    18531872################################################################################
     1873class HelpButton(wx.Button):
     1874    '''Create a help button that displays help information.
     1875    The text is displayed in a modal message window.
     1876
     1877    TODO: it might be nice if it were non-modal: e.g. it stays around until
     1878    the parent is deleted or the user closes it, but this did not work for
     1879    me.
     1880
     1881    :param parent: the panel which will be the parent of the button
     1882    :param str msg: the help text to be displayed
     1883    '''
     1884    def __init__(self,parent,msg):
     1885        if sys.platform == "darwin":
     1886            wx.Button.__init__(self,parent,wx.ID_HELP)
     1887        else:
     1888            wx.Button.__init__(self,parent,wx.ID_ANY,'?',style=wx.BU_EXACTFIT)
     1889        self.Bind(wx.EVT_BUTTON,self._onPress)
     1890        self.msg=msg
     1891        self.parent = parent
     1892    def _onPress(self,event):
     1893        'Respond to a button press by displaying the requested text'
     1894        dlg = wx.MessageDialog(self.parent,self.msg,'Help info',wx.OK)
     1895        dlg.ShowModal()
     1896        dlg.Destroy()
     1897################################################################################
    18541898class MyHtmlPanel(wx.Panel):
    18551899    '''Defines a panel to display HTML help information, as an alternative to
     
    19882032        self.ConstraintMenu = wx.MenuBar()
    19892033        self.PrefillDataMenu(self.ConstraintMenu,helpType='Constraints')
     2034        self.ConstraintTab = wx.Menu(title='')
     2035        self.ConstraintMenu.Append(menu=self.ConstraintTab, title='Select tab')
     2036        for id,txt in (
     2037            (wxID_CONSPHASE,'Phase'),
     2038            (wxID_CONSHAP,'Histogram/Phase'),
     2039            (wxID_CONSHIST,'Histogram'),
     2040            (wxID_CONSGLOBAL,'Global')):
     2041            self.ConstraintTab.Append(
     2042                id=id, kind=wx.ITEM_NORMAL,text=txt,
     2043                help='Select '+txt+' constraint editing tab')
    19902044        self.ConstraintEdit = wx.Menu(title='')
    19912045        self.ConstraintMenu.Append(menu=self.ConstraintEdit, title='Edit')
     
    19982052        self.ConstraintEdit.Append(id=wxID_FUNCTADD, kind=wx.ITEM_NORMAL,text='Add New Var',
    19992053            help='Add variable composed of existing parameter')
     2054
     2055        # item = self.ConstraintEdit.Append(id=wx.ID_ANY,kind=wx.ITEM_NORMAL,text='Update GUI')
     2056        # def UpdateGSASIIconstrGUI(event):
     2057        #     import GSASIIconstrGUI
     2058        #     reload(GSASIIconstrGUI)
     2059        #     import GSASIIobj
     2060        #     reload(GSASIIobj)
     2061        # self.Bind(wx.EVT_MENU,UpdateGSASIIconstrGUI,id=item.GetId())
     2062
    20002063        self.PostfillDataMenu()
    20012064       
Note: See TracChangeset for help on using the changeset viewer.