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

View of /ModelEditor/GloParamsDialog.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Tue Jan 17 17:12:47 2006 UTC (12 years, 9 months ago) by efrank
Branch: MAIN
CVS Tags: lwc, HEAD
Changes since 1.2: +4 -3 lines
persistence for dynamics stuff
bunch of flux modelinig stuff including flux model building in modeleditor

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

class GloParamsDialog(wxDialog):
    #------------------------------------------------------------------------
    def __init__(self, parent, ID, title, d, 
                 pos=wxDefaultPosition, size=wxDefaultSize,
                 style=wxDEFAULT_FRAME_STYLE, allow=0):
    #------------------------------------------------------------------------
        wxDialog.__init__(self, parent, ID, title, pos, size, style)

        self.parent = parent
        self.d = d
        """ d is a dictionary of global params. see KahOM.Model """
    
        paramPanel = wxPanel(self, -1)



        self.paramGrid = wxGrid(paramPanel, -1)
        self.paramGrid.CreateGrid(0, 3)
        self.paramGrid.SetColLabelValue(0, "Name")
        self.paramGrid.SetColLabelValue(1, "Type")
        self.paramGrid.SetColLabelValue(2, "Value")
        self.paramGrid.AutoSizeColumn(0)
        self.paramGrid.AutoSizeColumn(1)
        self.paramGrid.AutoSizeColumn(2)

        i = 0
        x = self.d.keys()
        x.sort()
        for key in x:
            self.paramGrid.AppendRows(numRows=1)
            self.paramGrid.SetCellValue(i,0,key)
            self.paramGrid.SetCellValue(i,1,self.d[key][0])
            self.paramGrid.SetCellValue(i,2,str(self.d[key][1]))
            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)
        
        if(allow):
            self.onAddParamId = wxNewId()
            self.addParamBtn = wxButton(paramPanel, self.onAddParamId,
                                        "Add")
            self.paramTypeBox = wxComboBox(paramPanel, -1, "Type",
                                           choices=["float", "string"],
                                           style=wxCB_DROPDOWN| wxCB_READONLY)
            self.paramTypeBox.SetValue("float")
            self.paramValBox = wxTextCtrl(paramPanel, -1, "EnterValue")
            self.paramNameBox = wxTextCtrl(paramPanel, -1, "EnterName")
            addParamHSizer = wxBoxSizer(wxHORIZONTAL)
            addParamHSizer.Add (self.paramNameBox)
            addParamHSizer.Add (self.paramTypeBox)
            addParamHSizer.Add (self.paramValBox)
            addParamHSizer.Add (self.addParamBtn)
            paramMainSizer.Add(addParamHSizer)
            EVT_BUTTON(self, self.addParamBtn.GetId(), self.onAddParam)
            
        paramMainSizer.Add(self.paramGrid, 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)       
  
        return

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

    #------------------------------------------------------------------------
    def onDialogOK(self, evt):
    #------------------------------------------------------------------------
        self.EndModal(wxID_OK)
        return
    
    #------------------------------------------------------------------------
    def onAddParam(self, evt):
    #------------------------------------------------------------------------
        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):
    #------------------------------------------------------------------------
        newDict = {}
        for i in range(self.paramGrid.GetNumberRows()):
            if (not (self.paramGrid.GetCellValue(i,2) == "None" or
                     self.paramGrid.GetCellValue(i,2) == "")):
                print i
                if (self.paramGrid.GetCellValue(i,1) == "float"):
                    newDict[self.paramGrid.GetCellValue(i,0)] = ("float", float(self.paramGrid.GetCellValue(i,2)))
                elif (self.paramGrid.GetCellValue(i, 1) == "string"):
                    newDict[self.paramGrid.GetCellValue(i,0)] = ("string", self.paramGrid.GetCellValue(i,2))
                    
        print newDict
        return newDict

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3