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

View of /PyGUI/RXpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (download) (as text) (annotate)
Fri Aug 13 17:41:11 2004 UTC (15 years, 3 months ago) by efrank
Branch: MAIN
CVS Tags: V00-00-03, MigrateToNewPackage, mass-spec-01, mass-spec-03, mass-spec-02, HEAD
Changes since 1.31: +3 -2 lines
Adding a bu

#########################################################################
#
# BUGS:
#   o In addSelectedRx and addSearchedRx, we don't pay attention to the
#   o foundry and aux info.  to fix this, i plan to extend the rx to
#   o carry that info.
#
#########################################################################

from wxPython.wx import *
from wxPython.grid import *
from KahOM.RecoElem import RecoElem
from FaST.FactoryUtils import union
from PyGUI.RecoElempanel import RecoElempanel
from PyGUI.MainLayout import MainLayout
#from RXAddDialog import RXAddDialog
from PyGUI.DoubleTextEntryDialog import DoubleTextEntryDialog
from PyGUI.MetabolitePanel import MetabolitePanel
from PyGUI.RXFromMetPageDialog import RXFromMetPageDialog
from PyGUI.RXOnAddPageDialog import RXOnAddPageDialog
from FoundryId.FoundryItemKey import FoundryItemKey

class RXPanel:
#
#    def getSelectedRx(self):
#    def addSearchedRx(self, rx):
#    def addSelectedRx(self, rx):
#    def __init__(self, parent):
#    def initEvents(self ):
#    def addRxToGrid(self, rx, theGrid):
#    def onSearchRx(self, evt):
#    def onOptionsRxComboValue(self, evt):
#    def onAddRx(self, evt):
#    def onSelectRxBtn(self, evt):
#    def onClearSearchedRxBtn(self, evt):
#    def onClearSelectedRxBtn(self, evt):
# 
    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        #wxPanel.__init__(self, parent, -1)
        self.parent = parent
        self.cutRx  = None
        self.selectedRxDict = {}
        self.searchedRxDict = {}
        self.initEvents()
        self.rxSearchOptionSelection = None
        # keeps us from clearing box unless last op was "From Metab Page"
        self.__needTextCtlClear = 0
       
        return

    
    #------------------------------------------------------------------------
    def initEvents(self ):
    #------------------------------------------------------------------------


        optionsRxComboValue = self.parent.optionsRxComboBox
        EVT_COMBOBOX(self.parent, optionsRxComboValue.GetId(),
                     self.onOptionsRxComboValue)
        
        addRxBtn = self.parent.addRxBtn
        EVT_BUTTON(self.parent, addRxBtn.GetId(), self.onAddRx)

        searchRxBtn = self.parent.searchRxBtn
        EVT_BUTTON(self.parent, searchRxBtn.GetId(), self.onSearchRx)

        selectRxBtn = self.parent.selectRxBtn
        EVT_BUTTON(self.parent, selectRxBtn.GetId(), self.onSelectRxBtn)
        
        clearSearchedRxBtn  = self.parent.clearSearchedRxBtn               
        EVT_BUTTON(self.parent, clearSearchedRxBtn.GetId(), 
                   self.onClearSearchedRxBtn)
                
        clearSelectedRxBtn  = self.parent.clearSelectedRxBtn
        EVT_BUTTON(self.parent, clearSelectedRxBtn.GetId(), 
                   self.onClearSelectedRxBtn)
                
        return
        

    #------------------------------------------------------------------------
    def getSelectedRx(self):
        # returns [Reaction] from the Selected Rx grid
    #------------------------------------------------------------------------
        return ( self.selectedRxDict.values() )

    #------------------------------------------------------------------------
    def getEnzymeText(self):
        # returns [Reaction] from the Selected Rx grid
    #------------------------------------------------------------------------
        return self.parent.hasEnzymesText.GetValue()


    #------------------------------------------------------------------------
    def addSearchedRx(self, rx):
    #------------------------------------------------------------------------
            
        theGrid = self.parent.rxSearchResultsGrid
        self.searchedRxDict[ theGrid.GetNumberRows() ] = rx
        self.addRxToGrid(rx, theGrid)
        theGrid.FitInside()
        return

    #------------------------------------------------------------------------
    def addSelectedRx(self, rx):
    #------------------------------------------------------------------------
        theGrid = self.parent.rxSelectedResultsGrid
        self.selectedRxDict[ theGrid.GetNumberRows() ] = rx
        self.addRxToGrid(rx, theGrid)
        return

    #------------------------------------------------------------------------
    def addRxToGrid(self, rx, theGrid):
    #------------------------------------------------------------------------

        nRow    = theGrid.GetNumberRows()
        theGrid.AppendRows(numRows=1)
        
        theGrid.SetCellValue(nRow, 0, rx.getFoundryId().getName() )
        #theGrid.SetCellValue(nRow, 1, rx.getFoundryItemKey().getIntVal(0) )
        theGrid.SetCellValue(nRow, 1, "")
        theGrid.SetCellValue(nRow, 2, rx.asString())
        theGrid.SetReadOnly(nRow, 0)
        theGrid.SetReadOnly(nRow, 1)
        theGrid.AutoSizeColumn(1)
        theGrid.SetReadOnly(nRow, 2)
        theGrid.AutoSizeColumn(2)

        return

   
    #------------------------------------------------------------------------
    def onSearchRx(self, evt):
    #------------------------------------------------------------------------
        factory     = self.parent.getCurrentDataFactory()
        foundryName = factory.getFoundryName()
        if (foundryName == "Wit" ):
            self.parent.error( "Reaction Search in WIT not supported" )
            return

        rxns = []
        # Get rxns accordinng to specified metabolites
        #
        if (self.rxSearchOptionSelection == "From Metabolite Page"):
            # get the search parameters via a dialog
            rxOnFromMetDialogWin = RXFromMetPageDialog(
                self.parent,  -1, "From Metabolite Page",
                pos=(300,300),size=(700,400),
                style=wxDEFAULT_FRAME_STYLE)

            result = rxOnFromMetDialogWin.ShowModal()

            if ( result != wxID_CANCEL):
                self.parent.error( "remember -long- in onSearchRx" )
                rxns = apply( factory.searchRxByMetabolites, rxOnFromMetDialogWin.GetValue("long") )
                rxOnFromMetDialogWin.Destroy()        

        elif (self.parent.optionsRxComboBox.GetValue() == "Input"):
            rxns = factory.findRxWithInput( self.parent.hasMetabsText.GetValue() )
        elif (self.parent.optionsRxComboBox.GetValue() == "Output"):
            rxns = factory.findRxWithOutput( self.parent.hasMetabsText.GetValue() )
        else:
            self.parent.error( "Program logic error RXPanel::onSearchRx")
            return
        
        # Get rxns according to EC number and union with rxns from above
        #
        enzText = self.getEnzymeText()
        if ( "" != enzText):
            enzRxns = factory.findRxViaEC( enzText )
            rxns = union(rxns, enzRxns)

        for r in rxns:
            self.addSearchedRx( r )

        return
    

    #------------------------------------------------------------------------
    def onOptionsRxComboValue(self, evt):
    #------------------------------------------------------------------------

        self.rxSearchOptionSelection = self.parent.optionsRxComboBox.GetValue()


        if (self.rxSearchOptionSelection  == "From Metabolite Page"):
            self.parent.hasMetabsText.SetValue( " Now Hit Search ")
            self.__needTextCtlClear = 1
        else:
            if (self.__needTextCtlClear == 1):
                self.parent.hasMetabsText.SetValue( "")
            self.__needTextCtlClear = 0
       
        return

    #------------------------------------------------------------------------
    def onAddRx(self, evt):
    #------------------------------------------------------------------------

        factory     = self.parent.getCurrentDataFactory()
        if (not factory.getFoundryType() == "KahDb" ):
            self.parent.error( "Adding Reactions only supported for KahDb, not for " +
                               factory.getFoundryType() )
            return

        rxOnAddRXPageDialog = RXOnAddPageDialog (self.parent, -1, "Add Reaction",
                                                  pos=(300,300), size=(700,400),
                                                  style=wxDEFAULT_FRAME_STYLE)

        result = rxOnAddRXPageDialog.ShowModal()

        if ( result == wxID_CANCEL):
            return
        elif ( result == wxID_OK ):
            rx = rxOnAddRXPageDialog.GetValue()
        else:
            self.parent.error( "Program error in RXpanel:onAddRx" )

        rx = rxOnAddRXPageDialog.GetValue()

        factory.writeReaction( rx, commit=1)
        
        return

   
    #------------------------------------------------------------------------
    def onSelectRxBtn(self, evt):
    #------------------------------------------------------------------------

        onSelectRows = self.parent.rxSearchResultsGrid.GetSelectedRows()

        rxBottomGrid       = self.parent.rxSelectedResultsGrid
        rxBottomGridNumber = self.parent.rxSelectedResultsGrid.GetNumberRows()
        
        for s in onSelectRows:
            self.addSelectedRx( self.searchedRxDict[s] )
                        
        rxBottomGrid.FitInside()
        
        return

    #------------------------------------------------------------------------
    def onClearSearchedRxBtn(self, evt):
    #------------------------------------------------------------------------
        self.parent.rxSearchResultsGrid.DeleteRows(0, self.parent.rxSearchResultsGrid.GetNumberRows())
        self.parent.rxSearchResultsGrid.ClearGrid()
        self.searchedRxDict.clear()
        return

    #------------------------------------------------------------------------
    def onClearSelectedRxBtn(self, evt):
    #------------------------------------------------------------------------
        theGrid = self.parent.rxSelectedResultsGrid
        theGrid.DeleteRows(0, theGrid.GetNumberRows())
        theGrid.ClearGrid()
        self.selectedRxDict.clear()
        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3