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

View of /PyGUI/Catalogpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Mon Aug 4 12:46:49 2003 UTC (16 years, 4 months ago) by efrank
Branch: MAIN
Changes since 1.5: +52 -26 lines
sync with kaitlyn's mods.  add new fn'ality:

Catalogpanel.py:
   o include Wit as Datasource via FaST/WitFactory
   o Catalog tree of data sources expands to basic level at startup
   o to handle multiple data sources:
        We use EVT_TREE_SEL_CHANGED to know when a user has chosen something.
        At that point, we remember the data associated with tree item that was
        set when the item was added to the tree.  That data is a tuple comprising
        (ptr-to-function, arg list). When the load button is hit, it looks at
        this tuple and evaluates ptr-to-fnction on the arg list.  The idea is
        that when the catalog tree is built, it is built by various data-base
        specific functions.  Those functions know the database they are dealing
        with, so they can load the (func, args) correctly to achieve the correct
        behavior.  The point here is that wxPython only allows you set a single
        selection-handler per tree, not per tree item.  Thus we build our own
        little dispatch handler as just described since our tree is really
        heterogeneous.  Get it?

MainLayout.py:
   o Just some name changes, like the title of the window.

from wxPython.wx import *
from FaST.BssFactory import BssFactory
from FaST.WitFactory import WitFactory
from FaST.RecoElem import RecoElem
from RecoElempanel import RecoElemWindow

class CatalogWindow:
    #------------------------------------------------------------------------
    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.

        self.initCatEvents()
        self.initCatData()
        return

    
    #------------------------------------------------------------------------
    def initCatEvents(self ):
    #------------------------------------------------------------------------
        button1= self.parent.OK_button
        EVT_BUTTON(self.parent, self.parent.loadbtn.GetId(),
                   self.onLoadBtnPress)
        EVT_TREE_SEL_CHANGED(self.parent.catalog_tree,
                             self.parent.catalog_treeId,
                             self.onLeftClick)

        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.loadBssCatalog( bssItemId )
        self.loadWitCatalog( witItemId )

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

    #------------------------------------------------------------------------
    def loadBssCatalog(self, bssItemId):
    #------------------------------------------------------------------------
        b=BssFactory()
        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()

        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 InitLsCat(self):
    #------------------------------------------------------------------------
        return

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

        return

    #------------------------------------------------------------------------
    def onLoadBtnPress(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 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