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

View of /ModelEditor/RXFromMetPageDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (download) (as text) (annotate)
Tue Mar 1 16:02:32 2005 UTC (14 years, 6 months ago) by mkubal
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.4: +10 -0 lines
no more editable checkboxes

from wxPython.wx import *
from wxPython.grid import *
from ModelEditor.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,"Comp. Name")
        self.fromMetPageGrid.AutoSizeColumn(2)
        self.fromMetPageGrid.SetColLabelValue(3,"Aux")
        self.fromMetPageGrid.AutoSizeColumn(3)

        attr = wxGridCellAttr()
	attr.SetReadOnly(1)
        attr2 = wxGridCellAttr()
	attr2.SetReadOnly(1)
       
        self.fromMetPageGrid.SetColAttr(0, attr)
        self.fromMetPageGrid.SetColAttr(1, attr)  
	self.fromMetPageGrid.SetColAttr(2, attr2)
        self.fromMetPageGrid.SetColAttr(3, attr2)  
	
        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)

            compName = sourceMetGrid.GetCellValue(rowNum,1)
            auxValue  = 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, compName)
            self.fromMetPageGrid.AutoSizeColumn(2)
            self.fromMetPageGrid.SetCellValue(rowNum,3, auxValue)
            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=="compName"):
                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