Changeset 1403 for trunk/GSASIIgrid.py


Ignore:
Timestamp:
Jul 2, 2014 2:20:23 PM (8 years ago)
Author:
vondreele
Message:

allow renaming of multiple columns in seq refinement results
allow changing of plot titles for seq plots.
new dialog - MultiStringDialog?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1402 r1403  
    135135] = [wx.NewId() for item in range(9)]
    136136
    137 [ wxID_SAVESEQSEL,wxID_SAVESEQSELCSV,wxID_PLOTSEQSEL,
     137[ wxID_RENAMESEQSEL,wxID_SAVESEQSEL,wxID_SAVESEQSELCSV,wxID_PLOTSEQSEL,
    138138  wxADDSEQVAR,wxDELSEQVAR,wxEDITSEQVAR,
    139139  wxADDPARFIT,wxDELPARFIT,wxEDITPARFIT,wxDOPARFIT,
    140 ] = [wx.NewId() for item in range(10)]
     140] = [wx.NewId() for item in range(11)]
    141141
    142142[ wxID_MODELCOPY,wxID_MODELFIT,wxID_MODELADD,wxID_ELEMENTADD,wxID_ELEMENTDELETE,
     
    14701470        '''
    14711471        return self.value
     1472
     1473################################################################################
     1474class MultiStringDialog(wx.Dialog):
     1475    '''Dialog to obtain a multi string values from user
     1476   
     1477    :param wx.Frame parent: name of parent frame
     1478    :param str title: title string for dialog
     1479    :param str prompts: strings to tell use what they are inputting
     1480    :param str values: default input values, if any
     1481    '''
     1482    def __init__(self,parent,title,prompts,values=[]):      #,size=(200,-1)?
     1483       
     1484        wx.Dialog.__init__(self,parent,wx.ID_ANY,title,
     1485                           pos=wx.DefaultPosition,
     1486                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
     1487        self.values = values
     1488        self.prompts = prompts
     1489        self.CenterOnParent()
     1490        self.panel = wx.Panel(self)
     1491        mainSizer = wx.BoxSizer(wx.VERTICAL)
     1492        promptSizer = wx.FlexGridSizer(0,2,5,5)
     1493        self.Indx = {}
     1494        for prompt,value in zip(prompts,values):
     1495            promptSizer.Add(wx.StaticText(self.panel,-1,prompt),0,WACV)
     1496            valItem = wx.TextCtrl(self.panel,-1,value=value,style=wx.TE_PROCESS_ENTER)
     1497            self.Indx[valItem.GetId()] = prompt
     1498            valItem.Bind(wx.EVT_TEXT,self.newValue)
     1499            promptSizer.Add(valItem,0,WACV)
     1500        mainSizer.Add(promptSizer,0)
     1501        btnsizer = wx.StdDialogButtonSizer()
     1502        OKbtn = wx.Button(self.panel, wx.ID_OK)
     1503        OKbtn.SetDefault()
     1504        btnsizer.AddButton(OKbtn)
     1505        btn = wx.Button(self.panel, wx.ID_CANCEL)
     1506        btnsizer.AddButton(btn)
     1507        btnsizer.Realize()
     1508        mainSizer.Add(btnsizer,0,wx.ALIGN_CENTER)
     1509        self.panel.SetSizer(mainSizer)
     1510        self.panel.Fit()
     1511        self.Fit()
     1512       
     1513    def newValue(self,event):
     1514        Obj = event.GetEventObject()
     1515        item = self.Indx[Obj.GetId()]
     1516        id = self.prompts.index(item)
     1517        self.values[id] = Obj.GetValue()
     1518
     1519    def Show(self):
     1520        '''Use this method after creating the dialog to post it
     1521        :returns: True if the user pressed OK; False if the User pressed Cancel
     1522        '''
     1523        if self.ShowModal() == wx.ID_OK:
     1524            return True
     1525        else:
     1526            return False
     1527
     1528    def GetValues(self):
     1529        '''Use this method to get the value entered by the user
     1530        :returns: string entered by user
     1531        '''
     1532        return self.values
    14721533
    14731534################################################################################
     
    25412602        self.SequentialFile = wx.Menu(title='')
    25422603        self.SequentialMenu.Append(menu=self.SequentialFile, title='Selected Cols')
     2604        self.SequentialFile.Append(id=wxID_RENAMESEQSEL, kind=wx.ITEM_NORMAL,text='Rename',
     2605            help='Rename selected sequential refinement columns')
    25432606        self.SequentialFile.Append(id=wxID_SAVESEQSEL, kind=wx.ITEM_NORMAL,text='Save as text',
    25442607            help='Save selected sequential refinement results as a text file')
     
    37553818                'No columns or rows selected in table. Click on row or column labels to select fields for plotting.'
    37563819                )
     3820               
     3821    def OnRenameSelSeq(event):
     3822        cols = sorted(G2frame.dataDisplay.GetSelectedCols()) # ignore selection order
     3823        colNames = [G2frame.SeqTable.GetColLabelValue(c) for c in cols]
     3824        newNames = colNames[:]
     3825        for i,name in enumerate(colNames):
     3826            if name in variableLabels:
     3827                newNames[i] = variableLabels[name]
     3828        if not cols:
     3829            G2frame.ErrorDialog('Select columns',
     3830                'No columns selected in table. Click on column labels to select fields for rename.')
     3831            return
     3832        dlg = MultiStringDialog(G2frame.dataDisplay,'Set column names',colNames,newNames)
     3833        if dlg.Show():
     3834            newNames = dlg.GetValues()           
     3835            variableLabels.update(dict(zip(colNames,newNames)))
     3836        dlg.Destroy()
     3837        UpdateSeqResults(G2frame,data,G2frame.dataDisplay.GetSize()) # redisplay variables
     3838        G2plt.PlotSelectedSequence(G2frame,cols,GetColumnInfo,SelectXaxis)
    37573839           
    37583840    def OnSaveSelSeqCSV(event):
     
    42564338            return u'\u03c3 = '+str(colSigs[col][row])
    42574339        return ''
     4340       
    42584341    def GridColLblToolTip(col):
    42594342        '''Define a tooltip for a column. This will be the user-entered value
     
    42654348        var = colLabels[col]
    42664349        return variableLabels.get(var,G2obj.fmtVarDescr(var))
     4350       
    42674351    def SetLabelString(event):
    42684352        '''Define or edit the label for a column in the table, to be used
     
    42784362        if dlg.Show():
    42794363            variableLabels[var] = dlg.GetValue()
    4280             print variableLabels
    42814364        dlg.Destroy()
    42824365       
     
    43724455        Status = G2frame.dataFrame.CreateStatusBar()
    43734456        Status.SetStatusText('')
     4457    G2frame.dataFrame.Bind(wx.EVT_MENU, OnRenameSelSeq, id=wxID_RENAMESEQSEL)
    43744458    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveSelSeq, id=wxID_SAVESEQSEL)
    43754459    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveSelSeqCSV, id=wxID_SAVESEQSELCSV)
Note: See TracChangeset for help on using the changeset viewer.