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

Diff of /PyGUI/Catalogpanel.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.25, Wed May 26 01:38:25 2004 UTC revision 1.36, Wed Jul 14 20:45:24 2004 UTC
# Line 1  Line 1 
1  from wxPython.wx             import *  from wxPython.wx             import *
2  from FaST.BssFactory         import BssFactory  from FaST.BssFactory         import BssFactory
3    from FaST.BssFactoryProxy    import BssFactoryProxy
4  from FaST.WitFactory         import WitFactory  from FaST.WitFactory         import WitFactory
5  from FaST.SeedDataFactory    import SeedDataFactory  from FaST.SeedDataFactory    import SeedDataFactory
6  from FaST.SeedDataFactory    import SeedOrganism  from FaST.SeedDataFactory    import SeedOrganism
7  from FaST.RecoElem           import RecoElem  from KahOM.RecoElem           import RecoElem
8  from RecoElempanel           import RecoElempanel  from PyGUI.RecoElempanel           import RecoElempanel
9  from CatalogServices.Catalog import Catalog  from CatalogServices.Catalog import Catalog
10    
11    
12  class Catalogpanel:  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 ):  
   
13      #------------------------------------------------------------------------      #------------------------------------------------------------------------
14      def __init__(self, parent):      def __init__(self, parent):
15      #------------------------------------------------------------------------      #------------------------------------------------------------------------
# Line 75  Line 64 
64      #------------------------------------------------------------------------      #------------------------------------------------------------------------
65      def initCatData( self ):      def initCatData( self ):
66      #------------------------------------------------------------------------      #------------------------------------------------------------------------
         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)  
67    
68            self.parent.catalogRootId = self.parent.catalog_tree.AddRoot("/")
69          self.loadCatalog()          self.loadCatalog()
70    
   
71          self.parent.catalog_tree.Expand( self.parent.catalogRootId)          self.parent.catalog_tree.Expand( self.parent.catalogRootId)
72          return          return
73    
# Line 112  Line 86 
86          return          return
87    
88      #------------------------------------------------------------------------      #------------------------------------------------------------------------
     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  
   
     #------------------------------------------------------------------------  
89      def loadCatalog(self):      def loadCatalog(self):
90      #------------------------------------------------------------------------      #------------------------------------------------------------------------
91          wxBeginBusyCursor()          wxBeginBusyCursor()
92    
93          localSeedServer        = "http://localhost/FIG/"          #localSeedServer        = "http://localhost/FIG"
94          seedFactory   = SeedDataFactory( localSeedServer )          #seedFactory   = SeedDataFactory( localSeedServer )
         b             = BssFactory()  
95    
96          try:          ##
97              Catalog.instance().addDataFactory( seedFactory )          # DO NOT CREATE BssFactory() HERE ANY LONGER
98              Catalog.instance().addDataFactory( b )          # See main progam, ModelEditor
99          except:          ##
             self.parent.error("loadCatalog: error" )  
             wxEndBusyCursor()  
             return  
   
         top = Catalog.instance().getCatalogTop()  
         self.recurseCatalog( top, self.parent.catalog_tree, self.parent.catalogRootId)  
   
         wxEndBusyCursor()  
100    
101          return          ##
102            # Handle top/root of catalog/tree specially to avoid "two root"
103            # on display problem
104            ##
105    
106      #------------------------------------------------------------------------          top = Catalog.instance().getCatalogTop()
107      def loadSeedCatalog(self, seedServer ):          parentTree = self.parent.catalog_tree
108      #------------------------------------------------------------------------          parentTree.SetPyData( self.parent.catalogRootId,
109          wxBeginBusyCursor()                                (self.recoElemLoader, top, self.parent.catalogRootId) )
110    
111          seedFactory   = SeedDataFactory( seedServer )          for e in top.entries():
112                self.recurseCatalog( e, parentTree, self.parent.catalogRootId)
113    
114          # add it to the list in the catalog          parentTree.SortChildren( self.parent.catalogRootId)
         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)  
115    
116          wxEndBusyCursor()          wxEndBusyCursor()
117    
# Line 194  Line 121 
121      def recurseCatalog( self, catEntry, parentTree, parentItemId):      def recurseCatalog( self, catEntry, parentTree, parentItemId):
122      #------------------------------------------------------------------------      #------------------------------------------------------------------------
123          """          """
124          terminal nodes have FoundryItemKeys associated with them that we          Create a new item under parentItemId in wxTree, parentTree.  Associate
125          can read if requested.  associate that key and a handler with the          catEntry with it.  If catEntry has entries, recurse on them.
         wxTree item in that case.  
126          """          """
127    
128          newItemId=parentTree.AppendItem(parentItemId, catEntry.name() )          if ( catEntry.isTerminal() ):
129                displayedName = catEntry.name()
130            else:
131                displayedName = catEntry.name() + "/"
132    
133            newItemId=parentTree.AppendItem(parentItemId, displayedName )
134    
135            # associate data needed to manipulate the catEntry
136    
137          parentTree.SetPyData( newItemId,          parentTree.SetPyData( newItemId,
138                                (self.recoElemLoader, catEntry, newItemId )                                (self.recoElemLoader, catEntry, newItemId ) )
                               )  
139    
140          if ( not catEntry.isTerminal() ):          if ( not catEntry.isTerminal() ):
141              for e in catEntry.entries():              for e in catEntry.entries():
142                  self.recurseCatalog( e, parentTree, newItemId)                  self.recurseCatalog( e, parentTree, newItemId)
143    
         # not efficient becaure of re-sort  
   
144          parentTree.SortChildren( newItemId )          parentTree.SortChildren( newItemId )
145    
146          return          return
147    
148      #------------------------------------------------------------------------      #------------------------------------------------------------------------
149      def OLDloadSeedCatalog(self, seedServer ):      def DOOMloadSeedCatalog(self, seedServer ):
150      #------------------------------------------------------------------------      #------------------------------------------------------------------------
151            """
152            This adds a Seed instance to the catalog.  It is called from the
153            MainMenuBar when Data->Add Seed Instance is called, for example.
154            """
155    
156          wxBeginBusyCursor()          wxBeginBusyCursor()
157    
158          # The SeedDataFactory ctor is slow and actually reads a bunch of          # The SeedDataFactory ctor is slow and actually reads a bunch of
# Line 233  Line 168 
168              wxEndBusyCursor()              wxEndBusyCursor()
169              return              return
170    
171          # make an entry in the tree for it          top = seedFactory.getCatalogTop()
172          #          self.recurseCatalog( top, self.parent.catalog_tree, self.parent.catalogRootId)
         newSeedItemId=self.parent.catalog_tree.AppendItem(self.seedItemId, seedServer )  
173    
         # jam in the data  
         #  
         orgList = seedFactory.listOrganisms( )  
         if ( orgList== None ):  
             orgItemId=self.parent.catalog_tree.AppendItem(newSeedItemId,  
                          "Could not get Org list from "+ seedServer )  
174              wxEndBusyCursor()              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) )  
   
175    
         wxEndBusyCursor()  
176          return          return
177    
178      #------------------------------------------------------------------------      #------------------------------------------------------------------------
# Line 271  Line 182 
182    
183          catEntryTuple = self.parent.tree_ctr.GetPyData(item)          catEntryTuple = self.parent.tree_ctr.GetPyData(item)
184          if (catEntryTuple == None ):          if (catEntryTuple == None ):
             print "None value for catEntryTuple"  
185              return              return
186          self.selected = catEntryTuple          self.selected = catEntryTuple
187          catEntry   = catEntryTuple[1]          catEntry   = catEntryTuple[1]
# Line 284  Line 194 
194          theBox.Clear()          theBox.Clear()
195    
196          if ( not catEntry.isTerminal() ):          if ( not catEntry.isTerminal() ):
197              self.parent.catPathValue.SetLabel( catEntry.path() )  
198                self.parent.catPathValue.SetValue( catEntry.path() + "/" )
199              self.parent.catVersionValueComboBox.SetLabel( "")              self.parent.catVersionValueComboBox.SetLabel( "")
200              self.parent.catHistoryDateValue.SetLabel( "" )              self.parent.catHistoryDateValue.SetLabel( "" )
201              self.parent.catHistoryUserValue.SetLabel( "" )              self.parent.catHistoryUserValue.SetLabel( "" )
202              self.parent.catHistoryCreatedFromValue.SetLabel( "")              self.parent.catHistoryCreatedFromValue.SetLabel( "")
203                theBox.SetValue( "" )
204          else:          else:
205              versions   = catEntry.versions()              versions   = catEntry.versions()
206              if ( [] == versions ):              if ( [] == versions ):
207                  self.parent.catPathValue.SetLabel( catEntry.path()+";[None]" )                  self.parent.catPathValue.SetValue( catEntry.path()+";[None]" )
208                    theBox.SetValue( "None" )
209              else:              else:
210                  maxVersion = max( versions )                  maxVersion = max( versions )
211                  for v in versions:                  for v in versions:
212                      theBox.Append( "%s" % (v ) )                      theBox.Append( "%s" % (v ) )
213                      theBox.SetValue( "%s" % (maxVersion) )                      theBox.SetValue( "%s" % (maxVersion) )
214                  self.parent.catPathValue.SetLabel(catEntry.path()+";[%s]" % (maxVersion))                  self.parent.catPathValue.SetValue(catEntry.path()+";[%s]" % (maxVersion))
215              #              #
216              self.parent.catHistoryDateValue.SetLabel( "no date info yet" )              self.parent.catHistoryDateValue.SetLabel( "no date info yet" )
217              self.parent.catHistoryUserValue.SetLabel( "no user info yet" )              self.parent.catHistoryUserValue.SetLabel( "no user info yet" )
# Line 316  Line 229 
229    
230          # get the value selected in the combo box.          # get the value selected in the combo box.
231          choice = event.GetString()          choice = event.GetString()
232            self.parent.catVersionValueComboBox.SetValue( "%s" % (choice) )
233    
234          # the operation is interpreted relative to the currently selected          # the operation is interpreted relative to the currently selected
235          # catalogEntry.  find what that is.          # catalogEntry.  find what that is.
# Line 332  Line 246 
246      #------------------------------------------------------------------------      #------------------------------------------------------------------------
247      def onRightClickCatalogTree(self, event):      def onRightClickCatalogTree(self, event):
248      #------------------------------------------------------------------------      #------------------------------------------------------------------------
249            """ Fires off the pop-up menu to handle right click events. """
250    
251          goober = event.GetEventObject()          event.GetEventObject().PopupMenu(self.catEditMenu, event.GetPosition())
         goober.PopupMenu(self.catEditMenu, event.GetPosition())  
   
252          return          return
253    
254      #------------------------------------------------------------------------      #------------------------------------------------------------------------
# Line 365  Line 278 
278              dlg.Destroy()              dlg.Destroy()
279              return              return
280    
281          try:          #try:
282            if (1):
283              newCatEntry=catEntry.mkDir( theName )              newCatEntry=catEntry.mkDir( theName )
284              parentTree=self.parent.catalog_tree              parentTree=self.parent.catalog_tree
285              newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() )              newItemId=parentTree.AppendItem(treeItemId, newCatEntry.name() )
# Line 373  Line 287 
287                                    (self.recoElemLoader, newCatEntry, newItemId )  )                                    (self.recoElemLoader, newCatEntry, newItemId )  )
288    
289              parentTree.SortChildren( treeItemId )              parentTree.SortChildren( treeItemId )
290          except:          else:
291            #except:
292              self.parent.error( "Operation refused." )              self.parent.error( "Operation refused." )
293    
294    
# Line 424  Line 339 
339      #------------------------------------------------------------------------      #------------------------------------------------------------------------
340      def onLeftDClick(self, event):      def onLeftDClick(self, event):
341      #------------------------------------------------------------------------      #------------------------------------------------------------------------
342            """ Double left-click means, "Load the currently selected item." """
343    
344          if ( self.selected == None ):          if ( self.selected == None ):
345              print "No selection in onLoadBtnPress"              self.parent.error( "You must select a catalog entry before requesting load.")
346              return              return
347    
348            # We store a loader to actually load the selected item.  This dates
349            # back to a time before a single loader could handle all the various
350            # data factory kinds.
351    
352          catEntryTuple = self.selected          catEntryTuple = self.selected
353          apply( catEntryTuple[0], [catEntryTuple[1]] )          apply( catEntryTuple[0], [catEntryTuple[1]] )
354    
# Line 441  Line 362 
362          (catalogEntry) = argList          (catalogEntry) = argList
363    
364          if (catalogEntry.isTerminal() ):          if (catalogEntry.isTerminal() ):
365              top = catalogEntry.getRecoElem()              ver = self.parent.catVersionValueComboBox.GetValue()
366              self.to_re.AddRecoElemTree(self.parent.rootId, top, catalogEntry)              if ( ver == "None" ):
367                    top = RecoElem( catalogEntry.name() )
368          else:          else:
369              # current selection is directory. can't load that!                  top = catalogEntry.read( int( ver ) )
             wxEndBusyCursor()  
             return  
   
370    
371                self.to_re.addRecoElemTree(self.parent.rootId, top, catalogEntry)
372            else:
373                # current selection is directory. can't load that!
374          wxEndBusyCursor()          wxEndBusyCursor()
375          return          return
376    
     #------------------------------------------------------------------------  
     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)  
377    
378          wxEndBusyCursor()          wxEndBusyCursor()
379          return          return
   
     #------------------------------------------------------------------------  
     def witPwyLoader(self,  pwyName ):  
     #------------------------------------------------------------------------  
         wxBeginBusyCursor()  
         w=WitFactory()  
         top= w.getRxnByPwy( pwyName )  
         self.to_re.AddRecoElemTree(self.parent.rootId, top)  
         wxEndBusyCursor()  
         return  

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.36

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3