[Bio] / PyGUI / RXFromMetPageDialog.py Repository:
ViewVC logotype

View of /PyGUI/RXFromMetPageDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (download) (as text) (annotate)
Fri Jul 2 22:08:02 2004 UTC (15 years, 3 months ago) by hwang
Branch: MAIN
CVS Tags: V00-00-03, MigrateToNewPackage, forRick-14Jul04-0, mass-spec-01, mass-spec-03, mass-spec-02, forRick-14Jul04-1, HEAD
Changes since 1.12: +35 -36 lines
	To maintain state, self was taken out of local variables

from wxPython.wx import *
from wxPython.grid import *
from PyGUI.MetabolitePanel import MetabolitePanel

import random

class RXFromMetPageDialog(wxDialog):
#    def __init__(self, parent, ID, title,
#    def onDialogCancel(self, evt):
#    def onDialogOK(self, evt):
#    def getCellValuesFromMetPage(self):
#    def onSelectCell(self, evt):
#    def GetValue( self ):
    

    #------------------------------------------------------------------------
    def __init__(self, parent, ID, title,
                 pos=wxDefaultPosition, size=wxDefaultSize,
                 style=wxDEFAULT_DIALOG_STYLE):
    #------------------------------------------------------------------------

        
        wxDialog.__init__(self, parent, ID, title, pos, size, style)
        
        self.parent= parent
        
        fromMetPagePanel  = wxPanel(self, -1)

        self.okDialogBtn       = wxButton(fromMetPagePanel, wxID_OK, "ok")
        self.cancelDialogBtn   = wxButton(fromMetPagePanel, wxID_CANCEL, "cancel")

        self.rxInputLabel  = wxStaticText(fromMetPagePanel, -1, "Selected Inputs   ")
        self.rxOutputLabel = wxStaticText(fromMetPagePanel, -1, "Selected Outputs  ")
        
        self.rxInputComboBox  = wxComboBox(fromMetPagePanel, -1, "Or Together",
                                     size=(150,-1), choices=["Or Together",
                                     "And Together"],
                                     style=wxCB_DROPDOWN | wxCB_READONLY)
        self.rxInputComboBox.SetValue( "Or Together")

        self.rxOutputComboBox = wxComboBox(fromMetPagePanel, -1, "Or Together",
                                     size=(150,-1), choices=["Or Together",
                                     "And Together"],
                                     style=wxCB_DROPDOWN |wxCB_READONLY)
        self.rxOutputComboBox.SetValue( "Or Together")

        self.rxAndOrComboBox  = wxComboBox(fromMetPagePanel, -1, "And",size=(100,-1),
                                     choices=["And", "Or"],
                                     style=wxCB_DROPDOWN | wxCB_READONLY)
        self.rxAndOrComboBox.SetValue("Or")
        


        self.fromMetPageGrid = wxGrid(fromMetPagePanel, -1)
        self.fromMetPageGrid.CreateGrid(0, 4)
        self.fromMetPageGrid.SetColLabelValue(0,"Input")
        self.fromMetPageGrid.SetColLabelValue(1,"Output")
        self.fromMetPageGrid.SetColLabelValue(2,"Short Name")
        self.fromMetPageGrid.AutoSizeColumn(2)
        self.fromMetPageGrid.SetColLabelValue(3,"Long Name")
        self.fromMetPageGrid.AutoSizeColumn(3)

        self.fromMetPageGrid.SetColFormatBool(0)
        self.fromMetPageGrid.SetColFormatBool(1)

        fromMetPageMainSizer   = wxBoxSizer(wxVERTICAL)
        dialogChoicesHSizer    = wxBoxSizer(wxHORIZONTAL)
        inputComboSizer   = wxBoxSizer(wxHORIZONTAL)
        outputComboSizer  = wxBoxSizer(wxHORIZONTAL)

        inputComboSizer.Add(self.rxInputLabel)
        inputComboSizer.Add(self.rxInputComboBox, 0, wxEXPAND)

        outputComboSizer.Add(self.rxOutputLabel)
        outputComboSizer.Add(self.rxOutputComboBox, 0, wxEXPAND)
        
        
        dialogChoicesHSizer.Add (self.okDialogBtn)
        dialogChoicesHSizer.Add (self.cancelDialogBtn)


        fromMetPageMainSizer.Add (self.fromMetPageGrid, 7, wxEXPAND)
        
        fromMetPageMainSizer.Add (inputComboSizer)
        fromMetPageMainSizer.Add (20,20, 0, wxEXPAND)
        fromMetPageMainSizer.Add (self.rxAndOrComboBox,0,wxALIGN_LEFT)
        fromMetPageMainSizer.Add (20,20, 0, wxEXPAND)
        fromMetPageMainSizer.Add (outputComboSizer)
        fromMetPageMainSizer.Add (20,20, 0, wxEXPAND)
        fromMetPageMainSizer.Add (dialogChoicesHSizer)

        fromMetPagePanel.SetSizer(fromMetPageMainSizer)
        fromMetPagePanel.SetAutoLayout(true)

        self.getCellValuesFromMetPage()

        EVT_BUTTON(self, self.cancelDialogBtn.GetId(), self.onDialogCancel)
        EVT_BUTTON(self, self.okDialogBtn.GetId(),     self.onDialogOK)
        EVT_GRID_CELL_LEFT_CLICK(self, self.onSelectCell)

        return

    #------------------------------------------------------------------------
    def onDialogCancel(self, evt):
    #------------------------------------------------------------------------
        self.EndModal(wxID_CANCEL)
        self.Destroy()
        return

    #------------------------------------------------------------------------
    def onDialogOK(self, evt):
    #------------------------------------------------------------------------
        self.EndModal(wxID_OK)
        #self.Destroy()
        return



    #------------------------------------------------------------------------
    def getCellValuesFromMetPage(self):
    #------------------------------------------------------------------------
        
        sourceMetGrid             = self.parent.getSelectedMetabsGrid()
        sourceMetGridRows         = sourceMetGrid.GetNumberRows()

        for rowNum in range(sourceMetGridRows):
            sourceMetGrid.SelectRow(rowNum, True)

            shortValue = sourceMetGrid.GetCellValue(rowNum,1)
            longValue  = sourceMetGrid.GetCellValue(rowNum,2)

            self.fromMetPageGrid.AppendRows(numRows=1)
            self.fromMetPageGrid.SetCellValue(rowNum,0,'1' )
            self.fromMetPageGrid.SetCellValue(rowNum,1,'1' )
            self.fromMetPageGrid.SetCellValue(rowNum,2, shortValue)
            self.fromMetPageGrid.AutoSizeColumn(2)
            self.fromMetPageGrid.SetCellValue(rowNum,3, longValue)
            self.fromMetPageGrid.AutoSizeColumn(3)
            self.fromMetPageGrid.FitInside()
        
        return

    #------------------------------------------------------------------------
    def onSelectCell(self, evt):
    #------------------------------------------------------------------------
                
        cellRow = evt.GetRow()
        cellCol = evt.GetCol()
        cellValue = self.fromMetPageGrid.GetCellValue(cellRow, cellCol)

        if (cellCol==0 or cellCol==1):
            if (cellValue =='0'):
                self.fromMetPageGrid.SetCellValue(cellRow,cellCol, '1')
            else:
                self.fromMetPageGrid.SetCellValue(cellRow,cellCol, '0')
                
        return

    #------------------------------------------------------------------------
    def GetValue( self, whichName ):
    #------------------------------------------------------------------------
        # returns format appropriate for BssFactory.searchRxByMetabolites
        
        
        inputList = []
        outputList= []

        for rowNum in range( self.fromMetPageGrid.GetNumberRows() ):
            isIn      = self.fromMetPageGrid.GetCellValue(rowNum,0)
            isOut     = self.fromMetPageGrid.GetCellValue(rowNum,1)
            if (whichName=="short"):
                theName =  self.fromMetPageGrid.GetCellValue(rowNum,2)
            else:
                theName =  self.fromMetPageGrid.GetCellValue(rowNum,3)
                
            if (isIn=="1") :  inputList.append( theName )
            if (isOut=="1"): outputList.append( theName )

        if ( "Or Together" == self.rxInputComboBox.GetValue() ):
            inputOperator = "Or"
        else:
            inputOperator = "And"

        
        if ( "Or Together" == self.rxOutputComboBox.GetValue() ):
            outputOperator = "Or"
        else:
            outputOperator = "And"


        inputOutputJoinOperator = self.rxAndOrComboBox.GetValue()

        
        return  [inputList, inputOperator, outputList, outputOperator, 
                 inputOutputJoinOperator ] 
    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3