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

View of /ModelEditor/RunSpecieInfoDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Tue Jan 17 17:12:47 2006 UTC (12 years, 10 months ago) by efrank
Branch: MAIN
CVS Tags: lwc, HEAD
persistence for dynamics stuff
bunch of flux modelinig stuff including flux model building in modeleditor

#-----------------------------------------------------------------------------
# Name:        RunSpecieInfoDialog.py
#
# Purpose:     Associated with Models are (or will be), "Runs" meaning
#              a set of parameters needed to run a computation.  SpecieInfo
#              has info about species for a run- initi conc., balanced or not,
#              etc.  This panel lets you edit them.#              
#
# History:
#              04Dec05efrank     First version.
#
# RCS-ID:      $Id: RunSpecieInfoDialog.py,v 1.1 2006/01/17 17:12:47 efrank Exp $
# Copyright:   (c) 2004
# Licence:     See COPYING.TXT
#-----------------------------------------------------------------------------

from wxPython.wx import *
from wxPython.grid import *
from KahOM.RunSpeciesInfo import RunSpeciesInfo

class RunSpecieInfoDialog(wxDialog):
    #------------------------------------------------------------------------
    def __init__(self, parent, ID, title, speciesInfo, 
                 pos=wxDefaultPosition, size=wxDefaultSize,
                 style=wxDEFAULT_FRAME_STYLE, allow=0):
    #------------------------------------------------------------------------
        """
        @type speciesInfo:  KahOM.RunSpeciesInfo
        """

        wxDialog.__init__(self, parent, ID, title, pos, size, style)

        self.parent = parent
    
        paramPanel = wxPanel(self, -1)

        self.paramGrid = wxGrid(paramPanel, -1)
        self.paramGrid.CreateGrid(0, 5)
        self.paramGrid.SetColLabelValue(0, "Species")
        self.paramGrid.SetColLabelValue(1, "Type")
        self.paramGrid.SetColLabelValue(2, "Init.Conc.") 
        self.paramGrid.SetColLabelValue(3, "Balanced")
        self.paramGrid.SetColLabelValue(4, "Accum")
        self.paramGrid.AutoSizeColumn(0)
        self.paramGrid.AutoSizeColumn(1)
        self.paramGrid.AutoSizeColumn(2)
        self.paramGrid.AutoSizeColumn(3)
        self.paramGrid.AutoSizeColumn(4)


        attr = wxGridCellAttr()
	attr.SetReadOnly(1)
        attr2 = wxGridCellAttr()
	attr2.SetReadOnly(1)
       
        self.paramGrid.SetColAttr(0, attr)
        self.paramGrid.SetColAttr(1, attr)  

        self.paramGrid.SetColAttr(3, attr2)  
        self.paramGrid.SetColFormatBool(3)

        i = 0
        x = speciesInfo.keys()
        x.sort()
        for key in x:
            self.paramGrid.AppendRows(numRows=1)
            self.paramGrid.SetCellValue(i,0,key)
            self.paramGrid.SetCellValue(i,1, "float")
            initConc=speciesInfo.getInitConc(key)
            if (None==initConc):
                self.paramGrid.SetCellValue(i,2, "None")
            else:
                self.paramGrid.SetCellValue(i,2,str(initConc) )
            #
            self.paramGrid.SetCellValue(i,3,str(speciesInfo.getIsBal(key)))
            self.paramGrid.SetCellValue(i,4,str(speciesInfo.getAccum(key)))
            i = i + 1

        self.okDialogBtn = wxButton(paramPanel, wxID_OK, "OK")
        self.cancelDialogBtn = wxButton(paramPanel, wxID_CANCEL, "Cancel")

        paramMainSizer = wxBoxSizer(wxVERTICAL)
        dialogChoicesHSizer = wxBoxSizer(wxHORIZONTAL)

        dialogChoicesHSizer.Add (self.okDialogBtn)
        dialogChoicesHSizer.Add (self.cancelDialogBtn)
        
        paramGridHSizer    = wxBoxSizer(wxHORIZONTAL)
        paramGridHSizer.Add(self.paramGrid, 1, wxEXPAND)
        
        paramMainSizer.Add(self.paramGrid, 1, wxEXPAND)
        #paramMainSizer.Add(paramGridHSizer, 3, wxEXPAND)
        paramMainSizer.Add((20,20), 0, wxEXPAND)
        paramMainSizer.Add(dialogChoicesHSizer)

        paramPanel.SetSizer(paramMainSizer)
        paramPanel.SetAutoLayout(true)

        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)
        return

    #------------------------------------------------------------------------
    def onDialogOK(self, evt):
    #------------------------------------------------------------------------
        self.EndModal(wxID_OK)
        return
    
    #------------------------------------------------------------------------
    def DOOMonAddParam(self, evt):
    #------------------------------------------------------------------------
        """ should this exist??? """

        n = self.paramGrid.GetNumberRows()
        self.paramGrid.AppendRows(numRows=1)
        self.paramGrid.SetCellValue(n,0,self.paramNameBox.GetValue())
        self.paramGrid.SetCellValue(n,1,self.paramTypeBox.GetValue())
        self.paramGrid.SetCellValue(n,2,self.paramValBox.GetValue())
        return

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

        Grope through values in the grid and shove into a RunSpeciesInfo
        instance.
        """

        rsi = RunSpeciesInfo()
        for i in range(self.paramGrid.GetNumberRows()):
            speciesName = self.paramGrid.GetCellValue(i,0).strip()
            initConc    = self.paramGrid.GetCellValue(i,2)
            isBal       = int( self.paramGrid.GetCellValue(i,3) )
            accum       = float( self.paramGrid.GetCellValue(i,4) )

            if ("NONE" == initConc.strip().upper() ):
                initConc = None
            else:
                initConc = float( initConc )
                
            # defer to setInfo() for rest of arg checking and let it
            # raise exceptions

            rsi.setInfo( speciesName, initConc, accum, isBal)
                    

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

        if (cellCol==3):
            if (cellValue =='0'):
                self.paramGrid.SetCellValue(cellRow,cellCol, '1')
            else:
                self.paramGrid.SetCellValue(cellRow,cellCol, '0')
        else:
            evt.Skip()
                
        return


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3