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

View of /PyGUI/Catalogpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (download) (as text) (annotate)
Wed May 26 01:38:25 2004 UTC (15 years, 6 months ago) by efrank
Branch: MAIN
Changes since 1.24: +251 -28 lines
Lots of work aimed at getting catalog services to work, incorporating
catalog editing into the model editor, and simplifying the api
for going form path to model in hand to work with.

CatalogEntryTop was changed to CatalogEntrBase and made base of CatalogEntry
rather than other way around to break a dependency loop that was causing
python import problems.  CatalogEntry is still the base class to use
for extending to new data factories.

changed open() to return catalogEntry rather than foundryItemKey.  simpler
for the user and more opportunity to encapsulate.

made catalogEntry able to read a recoElem and return it.  all done in
terms of arch abstractions.  this is temorary.  we will add a Navigator
or Manager class and that will be returned from the CatalogEntry rather
than recoElem.  that's becausee Recoelem is just one of many things
that will be present, e.g., conditions data.

PyGui/MainMenuBar.  split out to help stay sane for when that becomes
more complex.

Moved add seed server to menu bar so that right click in catalog panel
coudl be used to pull up catalog editing tools.

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


        # setup catalog editing menu (right click)

        self.catEditMenu         = wxMenu()
        self.catEditMkItemId     = wxNewId()
        self.catEditMkDirId      = wxNewId()
        self.setupCatEditMenu()

        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)

        EVT_COMBOBOX(self.parent.catVersionValueComboBox,
                     self.parent.catVersionValueComboBox.GetId(),
                     self.onCatVersionValueComboBox)

        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.loadCatalog()
        

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

    #------------------------------------------------------------------
    def setupCatEditMenu(self):
    #------------------------------------------------------------------

        self.catEditMenu.Append( self.catEditMkDirId,
                                 "New Directory", "NewDirectory" )
        EVT_MENU(self.parent, self.catEditMkDirId, self.doCatEditMkDir)

        self.catEditMenu.Append( self.catEditMkItemId,
                                 "New Item", "NewDirectory" )
        EVT_MENU(self.parent, self.catEditMkItemId, self.doCatEditMkItem)

        return

    #------------------------------------------------------------------------
    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, id) )

        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, id) )

        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, id ))

        return
        
    #------------------------------------------------------------------------
    def loadCatalog(self):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()

        localSeedServer        = "http://localhost/FIG/"
        seedFactory   = SeedDataFactory( localSeedServer )
        b             = BssFactory()

        try:
            Catalog.instance().addDataFactory( seedFactory )
            Catalog.instance().addDataFactory( b )
        except:
            self.parent.error("loadCatalog: error" )
            wxEndBusyCursor()
            return

        top = Catalog.instance().getCatalogTop()
        self.recurseCatalog( top, self.parent.catalog_tree, self.parent.catalogRootId)

        wxEndBusyCursor()

        return

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

        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

        top = seedFactory.getCatalogTop()
        #self.recurseCatalog( top, self.parent.catalog_tree, self.seedItemId )
        self.recurseCatalog( top, self.parent.catalog_tree, self.parent.catalogRootId)

        wxEndBusyCursor()

        return

    #------------------------------------------------------------------------
    def recurseCatalog( self, catEntry, parentTree, parentItemId):
    #------------------------------------------------------------------------
        """
        terminal nodes have FoundryItemKeys associated with them that we
        can read if requested.  associate that key and a handler with the
        wxTree item in that case.
        """

        newItemId=parentTree.AppendItem(parentItemId, catEntry.name() )

        parentTree.SetPyData( newItemId,
                              (self.recoElemLoader, catEntry, newItemId )
                              )

        if ( not catEntry.isTerminal() ):
            for e in catEntry.entries():
                self.recurseCatalog( e, parentTree, newItemId)

        # not efficient becaure of re-sort

        parentTree.SortChildren( newItemId )

        return

    #------------------------------------------------------------------------
    def OLDloadSeedCatalog(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),
                                            spontaneousRxItemId ))


        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), id) )

    
        wxEndBusyCursor()
        return
        
    #------------------------------------------------------------------------
    def onLeftClick(self,treeEvent):
    #------------------------------------------------------------------------
        item = treeEvent.GetItem()
        
        catEntryTuple = self.parent.tree_ctr.GetPyData(item)
        if (catEntryTuple == None ):
            print "None value for catEntryTuple"
            return
        self.selected = catEntryTuple
        catEntry   = catEntryTuple[1]

        ##
        # update the history information display
        ##

        theBox = self.parent.catVersionValueComboBox
        theBox.Clear()

        if ( not catEntry.isTerminal() ):
            self.parent.catPathValue.SetLabel( catEntry.path() )
            self.parent.catVersionValueComboBox.SetLabel( "")
            self.parent.catHistoryDateValue.SetLabel( "" )
            self.parent.catHistoryUserValue.SetLabel( "" )
            self.parent.catHistoryCreatedFromValue.SetLabel( "")
        else:
            versions   = catEntry.versions()
            if ( [] == versions ):
                self.parent.catPathValue.SetLabel( catEntry.path()+";[None]" )
            else:
                maxVersion = max( versions )
                for v in versions:
                    theBox.Append( "%s" % (v ) )
                    theBox.SetValue( "%s" % (maxVersion) )
                self.parent.catPathValue.SetLabel(catEntry.path()+";[%s]" % (maxVersion))
            #
            self.parent.catHistoryDateValue.SetLabel( "no date info yet" )
            self.parent.catHistoryUserValue.SetLabel( "no user info yet" )
            self.parent.catHistoryCreatedFromValue.SetLabel( "no history info yet" )
            
        return


    #------------------------------------------------------------------------
    def onCatVersionValueComboBox(self, event):
    #------------------------------------------------------------------------
        """
        Handles activity in combo box where user sets Verion to use
        """

        # get the value selected in the combo box.
        choice = event.GetString()

        # the operation is interpreted relative to the currently selected
        # catalogEntry.  find what that is.
        
        catEntry   = self.selected[1]

        # update stuff
        #version = self.parent.catVersionValueComboBox.GetValue()
        self.parent.catPathValue.SetLabel( catEntry.path()+";[%s]" % (choice) )

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

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

        return

    #------------------------------------------------------------------------
    def doCatEditMkDir( self, event ):
    #------------------------------------------------------------------------
        if (None == self.selected):
            self.parent.error( "A selection is required first.")
            return
        
        catEntryTuple = self.selected
        catEntry      = catEntryTuple[1]
        treeItemId    = catEntryTuple[2]
        
        if (catEntry.isTerminal()):
            self.parent.error("Directories can not be added to items.")
            return

        prompt = "New catalog directory name:"
        dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)

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

        try:
            newCatEntry=catEntry.mkDir( theName )
            parentTree=self.parent.catalog_tree
            newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() )
            parentTree.SetPyData( newItemId,
                                  (self.recoElemLoader, newCatEntry, newItemId )  )

            parentTree.SortChildren( treeItemId )
        except:
            self.parent.error( "Operation refused." )
            

        return 

    #------------------------------------------------------------------------
    def doCatEditMkItem( self, event ):
    #------------------------------------------------------------------------
        if (None == self.selected):
            self.parent.error( "A selection is required first.")
            return

        catEntryTuple = self.selected
        catEntry      = catEntryTuple[1]
        treeItemId    = catEntryTuple[2]

        if (catEntry.isTerminal()):
            self.parent.error("Items can not be added to items. Add to a directory.")
            return

        prompt = "New catalog entry name:"
        dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)

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

        try:
            newCatEntry = catEntry.mkItem( theName )
            parentTree=self.parent.catalog_tree
            newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() )
            parentTree.SetPyData( newItemId,
                                  (self.recoElemLoader, newCatEntry, newItemId )  )

            parentTree.SortChildren( treeItemId )
        except:
            self.parent.error( "Operation refused." )
            

        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 recoElemLoader(self,  argList ):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()

        (catalogEntry) = argList

        if (catalogEntry.isTerminal() ):
            top = catalogEntry.getRecoElem()
            self.to_re.AddRecoElemTree(self.parent.rootId, top, catalogEntry)
        else:
            # current selection is directory. can't load that!
            wxEndBusyCursor()
            return


        wxEndBusyCursor()
        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