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

View of /PyGUI/MetabolitePanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (download) (as text) (annotate)
Mon Jul 12 20:38:19 2004 UTC (15 years, 3 months ago) by efrank
Branch: MAIN
CVS Tags: V00-00-03, MigrateToNewPackage, forRick-14Jul04-0, mass-spec-01, mass-spec-03, mass-spec-02, forRick-14Jul04-1, HEAD
Changes since 1.31: +0 -150 lines
KahOM/KahDataMgr:
	first pass at top level data manager to be returned from catalogentry read

Schema:
	added KahDatabaseInfo to put fid into database.
	create- changed so that no long initialize name of top catalogEntry (see below)
	destroyBss- changed !#/usr/bin/py to env py

FaST:
	txMgr - fixed close()...added self
	BssFactory - now gets fid via kahDatabaseInfo in database

PyGUI
	change so that something or another

from wxPython.wx import *
from wxPython.grid import *
from KahOM.RecoElem import RecoElem
from PyGUI.RecoElempanel import RecoElempanel
from PyGUI.MainLayout import MainLayout
from PyGUI.DoubleTextEntryDialog import DoubleTextEntryDialog

class MetabolitePanel:
#    def __init__(self, parent):
#    def initEvents(self ):
#    def onSearchMetabs(self, evt):
#    def onAddMetabs(self, evt):
#    def searchBssMetabs(self, evt):
#    def searchWitMetabs(self, evt):
#    def onClearSearchResults(self, event):
#    def onClearSelectedMetabs(self, event):
#    def onSelectSearchResults(self, event):
#    def onFoundryComboBox(self, evt):

    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        #wxPanel.__init__(self, parent, -1)
        self.parent = parent
        
        
        self.initEvents()
        
       
        return

    
    #------------------------------------------------------------------------
    def initEvents(self):
    #------------------------------------------------------------------------
        EVT_COMBOBOX(self.parent,
                     self.parent.foundryComboBox.GetId(),
                     self.onFoundryComboBox)

        searchMetabsBtn = self.parent.searchMetabsBtn
        EVT_BUTTON(self.parent, searchMetabsBtn.GetId(), self.onSearchMetabs)

        addMetabsBtn = self.parent.addMetabsBtn
        EVT_BUTTON(self.parent, addMetabsBtn.GetId(),
                   self.onAddMetabs)


        clearSearchResultsBtn = self.parent.clearSearchResultsBtn
        EVT_BUTTON(self.parent, clearSearchResultsBtn.GetId(),
                   self.onClearSearchResults)

        
        clearSelectedMetabsBtn =  self.parent.clearSelectedMetabsBtn
        
        EVT_BUTTON(self.parent, clearSelectedMetabsBtn.GetId(),
                   self.onClearSelectedMetabs)

        
        
        selectSearchResultsBtn = self.parent.selectSearchResultsBtn
        EVT_BUTTON(self.parent, selectSearchResultsBtn.GetId(),
                   self.onSelectSearchResults)

        return
        
    #------------------------------------------------------------------------
    def onSearchMetabs(self, evt):
    #------------------------------------------------------------------------
        # this replaces the old seed specific and bss specific searches.
        # that means that the short name search is now kaput.

        wxBeginBusyCursor()

        factory = self.parent.getCurrentDataFactory()
        foundryName = factory.getFoundryName()

        longName    = self.parent.longText.GetValue() 
        longLikeOpt   = self.parent.optionsLongComboBox.GetValue()

        if longName  == "": longName = None

        
        if (longName != None):
            metabsResults = factory.longMetabSearch( longName, longLikeOpt )
        else:
            metabsResults = []

        
        theGrid = self.parent.bssGrid
        n       = theGrid.GetNumberRows()
        

        for r in metabsResults:
            (compId, name) = r
            theGrid.AppendRows(numRows=1)
            theGrid.SetCellValue(n, 0 , foundryName)
            theGrid.SetCellValue(n, 1, "" )
            theGrid.SetCellValue(n, 2, name )
            theGrid.SetCellValue(n, 3, compId )
            theGrid.SetReadOnly(n, 0)
            theGrid.SetReadOnly(n, 1)
            theGrid.SetReadOnly(n, 2)
            theGrid.SetReadOnly(n, 3)
            theGrid.AutoSizeColumn(1)
            theGrid.AutoSizeColumn(2)
            theGrid.AutoSizeColumn(3)
            n += 1
        theGrid.FitInside()
        

        wxEndBusyCursor()

        return

    #------------------------------------------------------------------------
    def onAddMetabs(self, evt):
    #------------------------------------------------------------------------
        
        factory = self.parent.getCurrentDataFactory()
        if ( not factory.getFoundryType() == "Bss"):
            self.parent.error( "Add metabolite only supported by Bss" )
            return

        onAddMetDialogWin =  DoubleTextEntryDialog(self.parent, -1,
                             "New Metabolite", prompt=("Short Name", "Long Name"),
                             pos=(300,300),size=wxSize(350,200),
                             style=wxDEFAULT_DIALOG_STYLE)
        result = onAddMetDialogWin.ShowModal()

        if ( result == wxID_CANCEL):
            return
        elif ( result == wxID_OK ):
            (shortName,longName) = onAddMetDialogWin.GetValue()
        else:
            self.parent.error( "Program error in onAddMetabs" )

        if ( longName == "" or longName == None or
             shortName =="" or shortName == None ):
            self.parent.error( "Invalid Metabolite name: [%s] [%s]" %
                               (shortName, longName) )
            return
             

        try:
            factory.writeMetabolite( shortName, longName)
        except:
            self.parent.error( "Database Error adding " + shortName 
                               + " " + longName )
            return

        bssRowNum= self.parent.bssGrid.GetNumberRows()
        self.parent.bssGrid.AppendRows(numRows=1)
        self.parent.bssGrid.SetCellValue(bssRowNum, 0, "Bss")
        self.parent.bssGrid.SetCellValue(bssRowNum, 1, shortName)
        self.parent.bssGrid.AutoSizeColumn(1)
        self.parent.bssGrid.SetCellValue(bssRowNum, 2, longName)
        self.parent.bssGrid.AutoSizeColumn(2)
         
        return

    #------------------------------------------------------------------------
    def onClearSearchResults(self, event):
    #------------------------------------------------------------------------
        if (self.parent.bssGrid.GetNumberRows() == 0 ):
            return
        
        self.parent.bssGrid.DeleteRows(0, self.parent.bssGrid.GetNumberRows())
        self.parent.bssGrid.ClearGrid()
        return

    #------------------------------------------------------------------------
    def onClearSelectedMetabs(self, event):
    #------------------------------------------------------------------------

        if (self.parent.selectedMetabsGrid.GetNumberRows() == 0 ):
            return
        
        self.parent.selectedMetabsGrid.DeleteRows(0, self.parent.selectedMetabsGrid.GetNumberRows())
        self.parent.selectedMetabsGrid.ClearGrid()
        return
        
    #------------------------------------------------------------------------
    def onSelectSearchResults(self, event):
    #------------------------------------------------------------------------
        onSelectRows = self.parent.bssGrid.GetSelectedRows()

        bottomGrid       = self.parent.selectedMetabsGrid
        bottomGridNumber = self.parent.selectedMetabsGrid.GetNumberRows()
        
        for s in onSelectRows:
            bottomFoundryValue = self.parent.bssGrid.GetCellValue(s, 0)
            bottomShortValue = self.parent.bssGrid.GetCellValue(s, 1)
            bottomLongValue = self.parent.bssGrid.GetCellValue(s, 2)
            bottomAuxValue = self.parent.bssGrid.GetCellValue(s, 3)

            bottomGrid.AppendRows(numRows=1)
            bottomGrid.SetCellValue(bottomGridNumber, 0, bottomFoundryValue)
            bottomGrid.SetCellValue(bottomGridNumber, 1, bottomShortValue)
            bottomGrid.AutoSizeColumn(1)
            bottomGrid.SetCellValue(bottomGridNumber, 2, bottomLongValue)
            bottomGrid.AutoSizeColumn(2)
            bottomGrid.SetCellValue(bottomGridNumber, 3, bottomAuxValue)
            bottomGrid.AutoSizeColumn(3)
            bottomGridNumber += 1
            
        
        #doesn't work 
        #bottomGrid.SelectAll()
        #print "bottomGridSelectAll ", bottomGrid.GetSelectedRows()
        bottomGrid.FitInside()
        
        return
        
    #------------------------------------------------------------------------
    def onFoundryComboBox(self, evt):
    #------------------------------------------------------------------------

        print "i'm in the metabolitepanel onFoundryComboBox"
        self.parent.error( "CALLED onFoundryCombBox in MetabolitePanel")
        return
        
        cb = evt.GetEventObject()
        choice = evt.GetString()
        
        if (choice == "Bss"):
            self.parent.shortText.Enable(true)
            self.parent.optionsShortComboBox.Enable(true)
            self.parent.orAndMetabsComboBox.Enable(true)
        elif (choice == "Wit"):
            self.parent.shortText.Enable(false)
            self.parent.optionsShortComboBox.Enable(false)
            self.parent.orAndMetabsComboBox.Enable(false)
        else:
            # of of the N seed factory instances.
            self.parent.shortText.Enable(false)
            self.parent.optionsShortComboBox.Enable(false)
            self.parent.orAndMetabsComboBox.Enable(false)

            
        return
        
    #------------------------------------------------------------------------
    def DOOMwitShow(self):
    #------------------------------------------------------------------------

        self.parent.MetTop.ReplaceWindow(self.parent.theBssPanel, self.parent.theWitPanel)
        self.parent.theBssPanel.Hide()
                
        return

    
    #------------------------------------------------------------------------
    def DOOMbssShow(self):
    #------------------------------------------------------------------------
        
        self.parent.MetTop.ReplaceWindow(self.parent.theWitPanel, self.parent.theBssPanel)
        self.parent.theWitPanel.Hide()

        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3