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

View of /ModelEditor/RXOnAddPageDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (download) (as text) (annotate)
Fri Mar 11 21:33:13 2005 UTC (14 years, 6 months ago) by efrank
Branch: MAIN
CVS Tags: before-dynamics-persistence, lwc, treatman-lastDay-0, preTreatmanDyn, HEAD
Changes since 1.6: +19 -13 lines
1. introduce Model as king of the hill rather than RecoElem.
2. migrations to follow
3. new modules for by-peg filtering
4. first stab at externalized app fwk
5. moved seed data factory

bunch of timing code still in this ...need to take out

from wxPython.wx import *
from wxPython.grid import *

from ModelEditor.MetabolitePanel import MetabolitePanel
from ModelEditor.EnzymeWindow    import EnzymeWindow
from KahOM.Reactant         import Reactant
from KahOM.Reaction         import Reaction

import random

class RXOnAddPageDialog(wxDialog):
#    def __init__(self, parent, ID, title,
#    def onDialogCancel(self, evt):
#    def onDialogOK(self, evt):
#    def getCellValuesFromEnzPage(self):
#    def onSelectCell(self, evt):
#    def GetValue( self ):
#    def updateRxComboBox(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
        
        self.onAddPagePanel  = wxPanel(self, -1)

        self.addDialogBtn       = wxButton(self.onAddPagePanel,-1, "add")
        self.cancelDialogBtn    = wxButton(self.onAddPagePanel, wxID_CANCEL, "cancel")
        self.previewBtn         = wxButton(self.onAddPagePanel,-1, "preview")

        self.rxCatalysisLabel   = wxStaticText(self.onAddPagePanel, -1, "Catalysis    ")
        self.rxDirectionLabel   = wxStaticText(self.onAddPagePanel, -1, "Direction    ")
        self.rxOutputLabel = wxStaticText(self.onAddPagePanel, -1, "Selected Outputs  ")
        self.rxPreviewLabel = wxStaticText(self.onAddPagePanel, -1, " press button to preview.")
        
        self.updateRxComboBox()

        self.directionComboBox  = wxComboBox(self.onAddPagePanel, -1, "both",
                                             size=(150,-1), choices = ["both", "forward", "backward"],
                                             style=wxCB_DROPDOWN | wxCB_READONLY)
        self.directionComboBox.SetValue( "both" )


        self.onAddPageGrid = wxGrid(self.onAddPagePanel, -1)
        self.onAddPageGrid.CreateGrid(0, 4)
        self.onAddPageGrid.SetColLabelValue(0,"Input")
        self.onAddPageGrid.SetColLabelValue(1,"Output")
        self.onAddPageGrid.SetColLabelValue(2,"Stoich")
        self.onAddPageGrid.AutoSizeColumn(2)
        self.onAddPageGrid.SetColLabelValue(3,"Compound Name")
        self.onAddPageGrid.AutoSizeColumn(3)

        attr = wxGridCellAttr()
        attr.SetReadOnly(1)
        self.onAddPageGrid.SetColAttr(0, attr)
        self.onAddPageGrid.SetColAttr(1, attr)
                          
        attr2 = wxGridCellAttr()
        attr2.SetReadOnly(1) 
        self.onAddPageGrid.SetColAttr(3, attr2)
              
        self.onAddPageGrid.SetColFormatBool(0)
        self.onAddPageGrid.SetColFormatBool(1)
        self.onAddPageGrid.SetColFormatFloat(2)
                      
        onAddPageMainSizer   = wxBoxSizer(wxVERTICAL)
        dialogChoicesHSizer  = wxBoxSizer(wxHORIZONTAL)
        previewChoicesHSizer = wxBoxSizer(wxHORIZONTAL)

        previewChoicesHSizer.Add(self.previewBtn)
        previewChoicesHSizer.Add(self.rxPreviewLabel)

        catalysisComboSizer    = wxBoxSizer(wxHORIZONTAL)
        catalysisComboSizer.Add(self.rxCatalysisLabel)
        catalysisComboSizer.Add(self.rxCatalysisComboBox, 0, wxEXPAND)
                
        directionComboSizer    = wxBoxSizer(wxHORIZONTAL)
        directionComboSizer.Add(self.rxDirectionLabel)
        directionComboSizer.Add(self.directionComboBox, 0, wxEXPAND)

        catalysisDirectionHSizer  = wxBoxSizer(wxHORIZONTAL)
        catalysisDirectionHSizer.Add( catalysisComboSizer )
        catalysisDirectionHSizer.Add( directionComboSizer )

        dialogChoicesHSizer.Add (self.addDialogBtn)
        dialogChoicesHSizer.Add (self.cancelDialogBtn)

        onAddPageMainSizer.Add (self.onAddPageGrid, 7, wxEXPAND)
        #onAddPageMainSizer.Add (catalysisComboSizer)
        onAddPageMainSizer.Add (catalysisDirectionHSizer)
        onAddPageMainSizer.Add ((20,20), 0, wxEXPAND)
        onAddPageMainSizer.Add (previewChoicesHSizer)
        onAddPageMainSizer.Add ((20,20), 0, wxEXPAND)
        onAddPageMainSizer.Add ((20,20), 0, wxEXPAND)
        onAddPageMainSizer.Add (dialogChoicesHSizer)
        self.onAddPagePanel.SetSizer(onAddPageMainSizer)
        self.onAddPagePanel.SetAutoLayout(true)

        self.getCellValuesFromEnzPage()

        EVT_BUTTON(self, self.previewBtn.GetId(), self.onPreviewBtn)
        EVT_BUTTON(self, self.cancelDialogBtn.GetId(), self.onDialogCancel)
        EVT_BUTTON(self, self.addDialogBtn.GetId(),     self.onDialogAdd)
        EVT_GRID_CELL_LEFT_CLICK(self, self.onSelectCell)

        return

    #------------------------------------------------------------------------
    def onPreviewBtn(self, evt):
    #------------------------------------------------------------------------
        try:
            displayedText = self.GetValue().asString()
        except ValueError:
            self.parent.error( "Invalid value entered.  Fix or cancel.")
            return

        self.rxPreviewLabel.SetLabel( displayedText )
        return

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

    #------------------------------------------------------------------------
    def onDialogAdd(self, evt):
    #------------------------------------------------------------------------
        try:
            self.GetValue()
        except ValueError:
            self.parent.error( "Invalid value entered.  Fix or cancel.")
            return

        self.EndModal(wxID_OK)
        #self.Destroy()
        return

    #------------------------------------------------------------------------
    def getCellValuesFromEnzPage(self):
    #------------------------------------------------------------------------
      #This function will be changed
      
        sourceRxGrid             = self.parent.getSelectedMetabsGrid()
        sourceRxGridRows         = sourceRxGrid.GetNumberRows()
        

        for rowNum in range(sourceRxGridRows):
            sourceRxGrid.SelectRow(rowNum, True)

            #stoichValue = sourceRxGrid.GetCellValue(rowNum,1)
            compoundValue  = sourceRxGrid.GetCellValue(rowNum,1)

            self.onAddPageGrid.AppendRows(numRows=1)
            self.onAddPageGrid.SetCellValue(rowNum,0,'0' )
            self.onAddPageGrid.SetCellValue(rowNum,1,'0' )
            self.onAddPageGrid.SetCellValue(rowNum,2,'1')
            self.onAddPageGrid.AutoSizeColumn(2)
            self.onAddPageGrid.SetCellValue(rowNum,3, compoundValue)
            self.onAddPageGrid.AutoSizeColumn(3)
            self.onAddPageGrid.FitInside()
        
        return
    
    #------------------------------------------------------------------------
    def onSelectCell(self, evt):
    #------------------------------------------------------------------------
                
        cellRow = evt.GetRow()
        cellCol = evt.GetCol()
        cellValue = self.onAddPageGrid.GetCellValue(cellRow, cellCol)
        self.onAddPageGrid.SetGridCursor(cellRow,cellCol)     
   
        if (cellCol==0 or cellCol==1):
            if (cellValue =='0'):
                self.onAddPageGrid.SetCellValue(cellRow,cellCol, '1')
            else:
                self.onAddPageGrid.SetCellValue(cellRow,cellCol, '0')
        
        if (cellCol == 2 ):
        	self.onAddPageGrid.EnableEditing(TRUE)
        	self.onAddPageGrid.EnableCellEditControl()
        else:
        	self.onAddPageGrid.EnableEditing(FALSE)
        	self.onAddPageGrid.EnableCellEditControl(FALSE)
        
        return

    #------------------------------------------------------------------------
    def GetValue( self):
    #------------------------------------------------------------------------
        """
        @rtype: KahOM.Reaction

        Exceptions, e.g., ValueError are allowed to raise up to caller to
        indicate invalid field values.
        """
        
        dir = self.directionComboBox.GetValue()

        inputList = []
        outputList= []

        for rowNum in range( self.onAddPageGrid.GetNumberRows() ):
            isIn      = self.onAddPageGrid.GetCellValue(rowNum,0)
            isOut     = self.onAddPageGrid.GetCellValue(rowNum,1)
            stoich    = float( self.onAddPageGrid.GetCellValue(rowNum,2) )
            theName =  self.onAddPageGrid.GetCellValue(rowNum,3)
                
            r = Reactant( theName, stoich)
            if (isIn=="1") :  inputList.append( r )
            if (isOut=="1"): outputList.append( r )


        rx = Reaction.nullCtor()
        rx.setState( dir, [inputList, outputList,
                           [ self.rxCatalysisComboBox.GetValue( ) ] ] )
                           

        return rx

    
    #------------------------------------------------------------------------
    def updateRxComboBox( self):
    #------------------------------------------------------------------------

    
       rxComboValues =["Unknown", "Spontaneous"]

       enzNumRows = self.parent.enzymesSelectedResultsGrid.GetNumberRows() 
       
       for enzNum  in range(enzNumRows):
           enzValues = self.parent.enzymesSelectedResultsGrid.GetCellValue(enzNum,2)
           rxComboValues.append(enzValues)
           
       self.rxCatalysisComboBox  = wxComboBox(self.onAddPagePanel, -1, "Unkown",
                                              size=(150,-1), choices = rxComboValues,
                                              style=wxCB_DROPDOWN | wxCB_READONLY)
           
       self.rxCatalysisComboBox.SetValue( "Unknown")

       return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3