[MOBY-guts] biomoby commit

Yan Wong yanwong at pub.open-bio.org
Mon Jan 24 11:26:55 UTC 2005


yanwong
Mon Jan 24 06:26:55 EST 2005
Update of /home/repository/moby/moby-live/Python/utils/wx
In directory pub.open-bio.org:/tmp/cvs-serv29497

Modified Files:
	objectBrowser.py 
Log Message:


moby-live/Python/utils/wx objectBrowser.py,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Python/utils/wx/objectBrowser.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Python/utils/wx/objectBrowser.py	2004/12/09 14:39:05	1.3
+++ /home/repository/moby/moby-live/Python/utils/wx/objectBrowser.py	2005/01/24 11:26:55	1.4
@@ -1,17 +1,18 @@
 #!/usr/bin/env python
-#Browse the bioMoby Object ontology
 
 from wxPython.wx import *
+import os, md5, pickle
 
 [wxID_WXFRAME1, wxID_WXFRAME1BUTTON1, wxID_WXFRAME1BUTTON2, 
+ wxID_WXFRAME1CHECKBOX1, wxID_WXFRAME1COMBOBOX1, wxID_WXFRAME1COMBOBOX2, 
  wxID_WXFRAME1GAUGE1, wxID_WXFRAME1LISTBOX1, wxID_WXFRAME1LISTBOX2, 
  wxID_WXFRAME1LISTBOX3, wxID_WXFRAME1LISTBOX4, wxID_WXFRAME1ONTOLOGYTREEVIEW, 
  wxID_WXFRAME1PANEL1, wxID_WXFRAME1STATICTEXT1, wxID_WXFRAME1STATICTEXT2, 
  wxID_WXFRAME1STATICTEXT3, wxID_WXFRAME1STATICTEXT4, wxID_WXFRAME1STATICTEXT5, 
  wxID_WXFRAME1STATICTEXT6, wxID_WXFRAME1STATICTEXT7, wxID_WXFRAME1STATICTEXT8, 
  wxID_WXFRAME1STATICTEXT9, wxID_WXFRAME1TEXTCTRL1, wxID_WXFRAME1TEXTCTRL2, 
- wxID_WXFRAME1TEXTCTRL3, wxID_WXFRAME1TEXTCTRL4, wxID_WXFRAME1TEXTCTRL5, 
-] = map(lambda _init_ctrls: wxNewId(), range(24))
+ wxID_WXFRAME1TEXTCTRL3, 
+] = map(lambda _init_ctrls: wxNewId(), range(25))
 
 #ISA=u"urn:lsid:biomoby.org:objectrelation:isa"
 #HAS=u"urn:lsid:biomoby.org:objectrelation:has"
@@ -26,6 +27,8 @@
         self.relations={}
         self.inputServices={}
         self.outputServices={}
+        self.url=client.url
+        self.ns=client.ns
         
         objectNames=client.retrieveObjectNames()
         
@@ -35,11 +38,11 @@
         for objectName in objectNames.keys():
             if setInc:
                 setInc()
-            
             self.definitions[objectName]=client.retrieveObjectDefinition(objectName)
-	    self.relations[objectName]=self.definitions[objectName]["Relationship"]
+            self.relations[objectName]=self.definitions[objectName]["Relationship"]
             sq=ServiceQuery(inputObjects=[ ('', str(objectName), []) ])
             
+            
             sl=client.findService(sq)
             self.inputServices[objectName]=[]
             for service in sl:
@@ -67,7 +70,7 @@
                 self._ISARelations[obj].append(objectName)
             else:
                 self._ISARelations[obj]=[objectName]
-		
+
     def __getitem__(self, key):
         return self._ISARelations[key]
 
@@ -76,23 +79,18 @@
 
 
 class wxFrame1(wxFrame):
-    def _init_utils(self):
-        # generated method, don't edit
-        pass
-
     def _init_ctrls(self, prnt):
         # generated method, don't edit
         wxFrame.__init__(self, id=wxID_WXFRAME1, name='', parent=prnt,
-              pos=wxPoint(348, 197), size=wxSize(800, 600),
+              pos=wxPoint(191, 101), size=wxSize(800, 600),
               style=wxSYSTEM_MENU | wxCAPTION | wxMINIMIZE_BOX,
               title='Object browser')
-        self._init_utils()
         self.SetClientSize(wxSize(800, 600))
         self.SetToolTipString('bioMoby objects browser')
 
         self.OntologyTreeview = wxTreeCtrl(id=wxID_WXFRAME1ONTOLOGYTREEVIEW,
-              name='OntologyTreeview', parent=self, pos=wxPoint(8, 136),
-              size=wxSize(336, 440), style=wxTR_HAS_BUTTONS,
+              name='OntologyTreeview', parent=self, pos=wxPoint(8, 168),
+              size=wxSize(336, 408), style=wxTR_HAS_BUTTONS,
               validator=wxDefaultValidator)
         EVT_TREE_SEL_CHANGED(self.OntologyTreeview,
               wxID_WXFRAME1ONTOLOGYTREEVIEW,
@@ -160,25 +158,17 @@
               label='URL', name='staticText7', parent=self, pos=wxPoint(8, 16),
               size=wxSize(24, 16), style=0)
 
-        self.textCtrl4 = wxTextCtrl(id=wxID_WXFRAME1TEXTCTRL4, name='textCtrl4',
-              parent=self, pos=wxPoint(8, 32), size=wxSize(320, 22), style=0,
-              value='http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY05/mobycentral.pl')
-
         self.staticText8 = wxStaticText(id=wxID_WXFRAME1STATICTEXT8, label='NS',
               name='staticText8', parent=self, pos=wxPoint(8, 56),
               size=wxSize(16, 16), style=0)
 
-        self.textCtrl5 = wxTextCtrl(id=wxID_WXFRAME1TEXTCTRL5, name='textCtrl5',
-              parent=self, pos=wxPoint(8, 72), size=wxSize(320, 22), style=0,
-              value='http://mobycentral.cbr.nrc.ca/MOBY/Central')
-
         self.button2 = wxButton(id=wxID_WXFRAME1BUTTON2,
               label='Retrieve objects', name='button2', parent=self,
-              pos=wxPoint(8, 104), size=wxSize(120, 22), style=0)
+              pos=wxPoint(8, 136), size=wxSize(120, 22), style=0)
         EVT_BUTTON(self.button2, wxID_WXFRAME1BUTTON2, self.OnButton2Button)
 
         self.gauge1 = wxGauge(id=wxID_WXFRAME1GAUGE1, name='gauge1',
-              parent=self, pos=wxPoint(136, 104), range=100, size=wxSize(184,
+              parent=self, pos=wxPoint(136, 136), range=100, size=wxSize(184,
               22), style=wxGA_HORIZONTAL, validator=wxDefaultValidator)
 
         self.staticText9 = wxStaticText(id=wxID_WXFRAME1STATICTEXT9,
@@ -190,11 +180,56 @@
               name='listBox4', parent=self.panel1, pos=wxPoint(16, 456),
               size=wxSize(400, 72), style=0, validator=wxDefaultValidator)
 
+        self.comboBox1 = wxComboBox(choices=[], id=wxID_WXFRAME1COMBOBOX1,
+              name='comboBox1', parent=self, pos=wxPoint(8, 32),
+              size=wxSize(312, 22), style=0,
+              value='http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY05/mobycentral.pl')
+        self.comboBox1.SetLabel('')
+
+        self.comboBox2 = wxComboBox(choices=[], id=wxID_WXFRAME1COMBOBOX2,
+              name='comboBox2', parent=self, pos=wxPoint(8, 72),
+              size=wxSize(312, 22), style=0,
+              value='http://mobycentral.cbr.nrc.ca/MOBY/Central')
+        self.comboBox2.SetLabel('')
+
+        self.checkBox1 = wxCheckBox(id=wxID_WXFRAME1CHECKBOX1,
+              label='Fetch data from cache (if there is any)', name='checkBox1',
+              parent=self, pos=wxPoint(8, 104), size=wxSize(248, 24), style=0)
+        self.checkBox1.SetValue(False)
+
     def __init__(self, parent):
         self._init_ctrls(parent)
         self.CenterOnScreen()
         self.gauge1.Hide()
         
+        try:
+            os.mkdir("%s/.objectBrowser"%os.environ['HOME'])
+        except:
+            pass
+        
+        try:
+            fp=file("%s/.objectBrowser/.url"%os.environ['HOME'])
+            for l in fp.readlines():
+                self.comboBox1.Append(l.replace("\n",""))
+            fp.close()
+        except:
+            fp=file("%s/.objectBrowser/.url"%os.environ['HOME'],"w")
+            fp.write("http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY05/mobycentral.pl")
+            fp.close()
+            self.comboBox1.Append("http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY05/mobycentral.pl")
+            
+        try:
+            fp=file("%s/.objectBrowser/.ns"%os.environ['HOME'])
+            for l in fp.readlines():
+                self.comboBox2.Append(l.replace("\n",""))
+            fp.close()
+        except:
+            fp=file("%s/.objectBrowser/.ns"%os.environ['HOME'],"w")
+            fp.write("http://mobycentral.cbr.nrc.ca/MOBY/Central")
+            fp.close()
+            self.comboBox2.Append("http://mobycentral.cbr.nrc.ca/MOBY/Central")
+            
+        
     def _feedNode(self, nodeName, node):
         
         if nodeName in self._otm.keys():
@@ -213,22 +248,31 @@
         if  parent != self.OntologyTreeview.GetRootItem():
             self._getRelationships(parent, listbox, relationship)
 
-
-    def OnOntologytreeviewTreeSelChanged(self, event):
-        item=event.GetItem()
-        text=self.OntologyTreeview.GetItemText(item)
+    def _treeClear(self):
+        #self.OntologyTreeview.CollapseAndReset(self.OntologyTreeview.GetRootItem())
+        self.OntologyTreeview.DeleteAllItems()
+        
+    def _infoClear(self):
         self.textCtrl1.SetValue("")
         self.textCtrl2.SetValue("")
         self.textCtrl3.SetValue("")
         self.listBox1.Clear()
         self.listBox2.Clear()
         self.listBox3.Clear()
+
+
+    def OnOntologytreeviewTreeSelChanged(self, event):
+        item=event.GetItem()
+        text=self.OntologyTreeview.GetItemText(item)
+        self._infoClear()
+        
         if text in self._otm.definitions:
             self.textCtrl1.SetValue(self._otm.definitions[text]['Description'])
             self.textCtrl2.SetValue(self._otm.definitions[text]['contactEmail'])
             self.textCtrl3.SetValue(self._otm.definitions[text]['authURI'])
-            
+        
             self._getRelationships(item, self.listBox1, "HAS")
+            
             self._getRelationships(item, self.listBox2, "HASA")
             
             for service in self._otm.inputServices[text]:
@@ -241,15 +285,38 @@
         event.Skip()
 
     def OnButton2Button(self, event):
+        import wx
         self.gauge1.Show()
         wxBeginBusyCursor()
         
-        from bioMoby import Client
+        fetchFromCache=self.checkBox1.GetValue()
+        url=self.comboBox1.GetValue()
+        ns=self.comboBox2.GetValue()
+
+        m=md5.md5("%s+%s"%(url,ns))
+        filename=m.hexdigest()
+        
+        if fetchFromCache:
+            fp=file("%s/.objectBrowser/%s"%(os.environ['HOME'], filename))
+
+            #try:
+            self._otm=pickle.load(fp)
+            #except:
+            #    fetchFromCache=False
+            fp.close()
+            
+        if not fetchFromCache:
+            from bioMoby import Client
+            client=Client(url=url, ns=ns)
+            self._otm=OntologyTreeModel(client, setRange=self.gauge1.SetRange, setInc=self._makeProgress)
+            fp=file("%s/.objectBrowser/%s"%(os.environ['HOME'], filename),"w")
+            pickle.dump(self._otm, fp)
+            fp.close()
+            
+        self._treeClear()
+        self._infoClear()
         
-        client=Client(url=self.textCtrl4.GetValue(), ns=self.textCtrl5.GetValue())
-        self._otm=OntologyTreeModel(client, setRange=self.gauge1.SetRange, setInc=self._makeProgress)
-        self.OntologyTreeview.Clear()
-        root=self.OntologyTreeview.AddRoot(self.textCtrl4.GetValue())
+        root=self.OntologyTreeview.AddRoot(url)
         self._feedNode('None', root)
         wxEndBusyCursor()
         self.gauge1.Hide()
@@ -262,8 +329,7 @@
     def _makeProgress(self):
         self.gauge1.SetValue(self.gauge1.GetValue()+1)
         wxYield()
-
-
+        
 class ObjectBrowser(wxApp):
     def OnInit(self):
         wxInitAllImageHandlers()




More information about the MOBY-guts mailing list