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

View of /PyGUI/Catalogpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (download) (as text) (annotate)
Fri Mar 26 17:12:46 2004 UTC (15 years, 9 months ago) by efrank
Branch: MAIN
Changes since 1.23: +11 -10 lines
Modifications to install the new Catalog code, FoundryId stuff.  I ripped
out old code as well:  the list of foundryComboBoxes is gone since we now
have just one combo box.

the notion of FoundryId's intVal is gone.  at least for the moment.  it's too hard
at the mment to have a (bottleneck!) central authority to manage the intVals.

so, starting now, foundryId's are based on strings that are notionally URLs and
its up to the dataFoundry manager to make sure all distinct instances at his
site have distinct urls.

this also means that if a foundry moves, then the history information that
refers to it becomes incorrect.

from wxPython.wx             import *
from FaST.BssFactory         import BssFactory
from FaST.WitFactory         import WitFactory
from FaST.SeedDataFactory    import SeedDataFactory
from FaST.SeedDataFactory    import SeedOrganism
from FaST.RecoElem           import RecoElem
from RecoElempanel           import RecoElempanel
from CatalogServices.Catalog import Catalog


class Catalogpanel:
#    def __init__(self, parent):
#    def initCatEvents(self ):
#    def initCatData( self ):
#    def loadBssCatalog(self, bssItemId):
#    def loadWitCatalog(self, witItemId):
#    def loadSeedCatalog(self, witItemId):
#    def onLeftClick(self,treeEvent):
#    def onLoadBtnPress(self, event):
#    def bssLoader( self, bssCatEntry ):
#    def witOrgLoader(self,  orgName ):
#    def witPwyLoader(self,  pwyName ):

    #------------------------------------------------------------------------
    def __init__(self, parent):
    #------------------------------------------------------------------------
        self.parent            = parent

        self.to_re    = parent.re 
        self.selected = None       #remember last selected catalog entry
                                   #..is used when LOAD button is hit.

        # seedItemId is the wxPython id for the "Seed" node
        # in the catalog tree under which all specific Seed servers
        # are listed

        self.seedItemId        = None

        self.initCatEvents()
        self.initCatData()


        self.seedServerMenu = wxMenu()
        self.seedServerAddId = wxNewId()
        self.setupSeedServerMenu()

        return

    
    #------------------------------------------------------------------------
    def initCatEvents(self ):
    #------------------------------------------------------------------------

        EVT_TREE_SEL_CHANGED(self.parent.catalog_tree,
                             self.parent.catalog_treeId,
                             self.onLeftClick)

        # Right click on List item for Seed will let you connect to
        # another Seed server

        EVT_RIGHT_DOWN(self.parent.catalog_tree, self.onRightClickCatalogTree)

                
        EVT_LEFT_DCLICK (self.parent.catalog_tree, self.onLeftDClick)

        return
        
    #------------------------------------------------------------------------
    def initCatData( self ):
    #------------------------------------------------------------------------
        self.parent.catalogRootId = self.parent.catalog_tree.AddRoot("Data Sources")

        bssItemId=self.parent.catalog_tree.AppendItem(self.parent.catalogRootId,
                                                   "BioSimScratch" )
        witItemId=self.parent.catalog_tree.AppendItem(self.parent.catalogRootId,
                                                   "WIT3" )
        self.seedItemId=self.parent.catalog_tree.AppendItem(self.parent.catalogRootId,
                                                   "Seed" )

        self.loadBssCatalog( bssItemId )
        self.loadWitCatalog( witItemId )

        localSeedServer        = "http://localhost/FIG/"
#        localSeedServer        = "http://float179.mcs.anl-external.org/FIG/"
        self.loadSeedCatalog( localSeedServer)

        self.parent.catalog_tree.Expand( self.parent.catalogRootId)
        return

    #------------------------------------------------------------------
    def setupSeedServerMenu(self):
    #------------------------------------------------------------------
        self.seedServerAddId = wxNewId()

        self.seedServerMenu.Append( self.seedServerAddId,
                                      "Add Seed Server", "New seed server arg3" )
        EVT_MENU(self.parent, self.seedServerAddId, self.doSeedServerAdd)

    #------------------------------------------------------------------------
    def loadBssCatalog(self, bssItemId):
    #------------------------------------------------------------------------
        b=BssFactory()
        Catalog.instance().addDataFactory( b )
        for catEntryTuple in b.getLsCat():
            id=self.parent.catalog_tree.AppendItem(bssItemId, catEntryTuple[0])
            self.parent.catalog_tree.SetPyData(id, (self.bssLoader, catEntryTuple) )

        return
        
    #------------------------------------------------------------------------
    def loadWitCatalog(self, witItemId):
    #------------------------------------------------------------------------
        w=WitFactory()
        Catalog.instance().addDataFactory( w )
        pwyItemId=self.parent.catalog_tree.AppendItem(witItemId, "Pathways" )

        pwyList = w.listPathways( )
        for pwy in pwyList: 
            id=self.parent.catalog_tree.AppendItem(pwyItemId, pwy)
            self.parent.catalog_tree.SetPyData(id, (self.witPwyLoader,pwy) )

        orgItemId=self.parent.catalog_tree.AppendItem(witItemId, "Organisms" )

        orgList = w.listOrganisms( )
        for org in orgList: 
            id=self.parent.catalog_tree.AppendItem(orgItemId, org)
            self.parent.catalog_tree.SetPyData(id, (self.witOrgLoader, org ))

        return
        
    #------------------------------------------------------------------------
    def loadSeedCatalog(self, seedServer ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()

	# The SeedDataFactory ctor is slow and actually reads a bunch of
	# data from the server

        seedFactory   = SeedDataFactory( seedServer )

        # add it to the list in the catalog
        try:
            Catalog.instance().addDataFactory( seedFactory )
        except:
            self.parent.error("loadSeedCatalog: %s already in foundry list." % seedServer)
            wxEndBusyCursor()
            return

	# make an entry in the tree for it
	#
        newSeedItemId=self.parent.catalog_tree.AppendItem(self.seedItemId, seedServer )

	# jam in the data
	#
        orgList = seedFactory.listOrganisms( )
        if ( orgList== None ):
            orgItemId=self.parent.catalog_tree.AppendItem(newSeedItemId,
                         "Could not get Org list from "+ seedServer )
            wxEndBusyCursor()
            return
            
        itemName="Spontaneous Reactions"
        spontaneousRxItemId=self.parent.catalog_tree.AppendItem(newSeedItemId, itemName)
        self.parent.catalog_tree.SetPyData(spontaneousRxItemId,
                                           (self.seedRecoElemLoader,
                                           (seedFactory.getRecoElemSpontaneousRx, None) ))


        orgItemId=self.parent.catalog_tree.AppendItem(newSeedItemId, "Organisms" )
        for org in orgList: 
            id=self.parent.catalog_tree.AppendItem(orgItemId, org.figOrgName )
            self.parent.catalog_tree.SetPyData(id, (self.seedRecoElemLoader, 
                                                   (seedFactory.getRecoElemByOrg, org) ))

    
        wxEndBusyCursor()
        return
        
    #------------------------------------------------------------------------
    def onLeftClick(self,treeEvent):
    #------------------------------------------------------------------------
        item = treeEvent.GetItem()
        
        catEntryTuple = self.parent.tree_ctr.GetPyData(item)
        if (catEntryTuple == None ):
            return
        self.selected = catEntryTuple

        return

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

        goober = event.GetEventObject()
        goober.PopupMenu(self.seedServerMenu, event.GetPosition())

        return

    #------------------------------------------------------------------------
    def doSeedServerAdd(self, event):
    #------------------------------------------------------------------------
        prompt = "Name of Seed server"
        dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)

        if ( dlg.ShowModal() == wxID_OK):
            serverName = dlg.GetValue()
            if ( serverName=="" ): return
            dlg.Destroy()
        else:
            #didn't get a kid name
            dlg.Destroy()
            return

        self.loadSeedCatalog( serverName )

        return 


    #------------------------------------------------------------------------
    def onLeftDClick(self, event):
    #------------------------------------------------------------------------
        if ( self.selected == None ):
            print "No selection in onLoadBtnPress"
            return 

        catEntryTuple = self.selected
        apply( catEntryTuple[0], [catEntryTuple[1]] )

        return
    
    #------------------------------------------------------------------------
    def bssLoader( self, bssCatEntry ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()
        b=BssFactory()
        top= b.getRecoElemById( bssCatEntry[1] )
        self.to_re.AddRecoElemTree(self.parent.rootId, top)
        wxEndBusyCursor()

        return

    #------------------------------------------------------------------------
    def witOrgLoader(self,  orgName ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()
        w=WitFactory()
        top= w.getRxnByOrg( orgName )
        self.to_re.AddRecoElemTree(self.parent.rootId, top)
        wxEndBusyCursor()
        return

    #------------------------------------------------------------------------
    def seedRecoElemLoader(self,  argList ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()

        (theSeedFactoryMethod, org) = argList
        top = apply( theSeedFactoryMethod, [org] )
        # top=self.__seedDataFactory.getRecoElemByOrg( org )
        self.to_re.AddRecoElemTree(self.parent.rootId, top)

        wxEndBusyCursor()
        return

    #------------------------------------------------------------------------
    def witPwyLoader(self,  pwyName ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()
        w=WitFactory()
        top= w.getRxnByPwy( pwyName )
        self.to_re.AddRecoElemTree(self.parent.rootId, top)
        wxEndBusyCursor()
        return

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3