Changeset 1403 for trunk


Ignore:
Timestamp:
Jul 2, 2014 2:20:23 PM (11 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?

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified 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)
  • TabularUnified trunk/GSASIIplot.py

    r1402 r1403  
    24072407      number (or None) as the X-axis selection
    24082408    '''
     2409    global Title,xLabel,yLabel
     2410    xLabel = yLabel = Title = ''
    24092411    def OnMotion(event):
    24102412        if event.xdata and event.ydata:                 #avoid out of frame errors
     
    24152417
    24162418    def OnKeyPress(event):
     2419        global Title,xLabel,yLabel
    24172420        if event.key == 's':
    24182421            G2frame.seqXaxis = G2frame.seqXselect()
    24192422            Draw()
     2423        elif event.key == 't':
     2424            dlg = G2gd.MultiStringDialog(G2frame,'Set titles & labels',[' Title ',' x-Label ',' y-Label '],
     2425                [Title,xLabel,yLabel])
     2426            if dlg.Show():
     2427                Title,xLabel,yLabel = dlg.GetValues()
     2428            dlg.Destroy()
     2429            Draw()
    24202430           
    24212431    def Draw():
     2432        global Title,xLabel,yLabel
    24222433        Page.SetFocus()
    2423         G2frame.G2plotNB.status.SetStatusText('press s to select X axis',1)
     2434        G2frame.G2plotNB.status.SetStatusText('press s to select X axis, t to change titles',1)
    24242435        Plot.clear()
    24252436        if G2frame.seqXaxis is not None:   
     
    24462457           
    24472458        Plot.legend(loc='best')
    2448         Plot.set_ylabel('Parameter values')
    2449         Plot.set_xlabel(xName)
     2459        if Title:
     2460            Plot.set_title(Title)
     2461        else:
     2462            Plot.set_title('')
     2463        if xLabel:
     2464            Plot.set_xlabel(xLabel)
     2465        else:
     2466            Plot.set_xlabel(xName)
     2467        if yLabel:
     2468            Plot.set_ylabel(yLabel)
     2469        else:
     2470            Plot.set_ylabel('Parameter values')
    24502471        Page.canvas.draw()           
    24512472           
     
    24732494        Page.canvas.mpl_connect('key_press_event', OnKeyPress)
    24742495        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    2475     Page.Choice = ['s to select plot x-axis',]
     2496    Page.Choice = ['s - select x-axis','t - change titles',]
    24762497    Page.keyPress = OnKeyPress
    24772498    Page.seqYaxisList = ColumnList
Note: See TracChangeset for help on using the changeset viewer.