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

View of /PyGUI/MainMenuBar.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (download) (as text) (annotate)
Wed Jul 14 20:22:13 2004 UTC (15 years, 4 months ago) by efrank
Branch: MAIN
CVS Tags: V00-00-03, MigrateToNewPackage, mass-spec-01, forRick-14Jul04-0, mass-spec-03, mass-spec-02, forRick-14Jul04-1, HEAD
Changes since 1.17: +1 -1 lines
getting it to work.  in a rush for rick demo.

#########################################################################
#
#
#########################################################################

from wxPython.wx import *
from PyGUI.FontManager           import FontManager
from PyGUI.AGGetPubDialog        import AGGetPubDialog
from PyGUI.DoubleTextEntryDialog import DoubleTextEntryDialog
from FaST.BssFactory             import BssFactory
from FaST.BssFactoryProxy        import BssFactoryProxy
from FaST.SeedDataFactory        import SeedDataFactory
from CatalogServices.Catalog     import Catalog

class MainMenuBar:

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

        self.setupMenuBar()
        self.initEvents()
       
        # below used in selectFont.  Why member data here???
        
        self.fontData = None
        self.newFont  = None 
        self.curFont  = None
        self.isConnected = 0

        return
    
    #------------------------------------------------------------------------
    def setupMenuBar(self):
    #------------------------------------------------------------------------
    
        ##
        # "File" dropdown
        ##
        self.exitID       = wxNewId()
        self.fontID       = wxNewId()
        self.addPlugInId  = wxNewId()

        self.optionsMenu = wxMenu()
        self.optionsMenu.Append(self.fontID, "Change  Font",  "changing font")
        self.optionsMenu.Append(self.addPlugInId, "Add Plug-in", "Add Plug-in")
        self.optionsMenu.Append(self.exitID, "Exit    ", "quitting the program")
        self.parent.theMainMenuBar.Append(self.optionsMenu, "&File")
    

        ##
        # "Data" drop down
        ##

        self.dataDropDownMenu = wxMenu()

        self.addLocalFactoryId = wxNewId()
        self.dataDropDownMenu.Append(self.addLocalFactoryId,
                                     "Connect Directly to a KahDb",
                                     "Start local data factory")

        self.dataDropDownMenu.AppendSeparator()

        self.addSeedServerId = wxNewId()
        self.dataDropDownMenu.Append(self.addSeedServerId,
                                     "Connect to Seed Instance",
                                     "Connect to another seed server")

        self.addKahDBServerId = wxNewId()
        self.dataDropDownMenu.Append(self.addKahDBServerId,
                                     "Connect to KahDB Server",
                                     "Connect to another KahDB server")

        self.dataDropDownMenu.AppendSeparator()
       
        self.getPubAGId = wxNewId()
        self.dataDropDownMenu.Append(self.getPubAGId,
                                   "Find KahDb Servers via AG",
                                   "Connect to currently published dbs on AG")

        self.advertiseAGId = wxNewId()
        self.dataDropDownMenu.Append(self.advertiseAGId,
                                   "Advertise KahDb Server on AG",
                                   "Advertise a Server on Kah venue")

        self.parent.theMainMenuBar.Append(self.dataDropDownMenu, "&Data")

        ##
        # "AccessGrid" drop down
        ##
        self.AGDropDownMenu = wxMenu()

        self.connectAGId = wxNewId()
        self.AGDropDownMenu.Append(self.connectAGId, "Connect to AG", "Connect to the AccessGrid")

        self.disconnectAGId = wxNewId()
        self.AGDropDownMenu.Append(self.disconnectAGId, "Disconnect from AG", "Leave the AccessGrid")
        
        self.parent.theMainMenuBar.Append(self.AGDropDownMenu, "&AccessGrid")
        
        return
    
    #------------------------------------------------------------------------
    def initEvents(self):
    #------------------------------------------------------------------------
        EVT_MENU(self.parent, self.exitID, self.exitApp)
        EVT_MENU(self.parent, self.fontID, self.selectFont)
        EVT_MENU(self.parent, self.addLocalFactoryId, self.doAddLocalFactory)
        EVT_MENU(self.parent, self.addSeedServerId, self.doAddSeedServer)
        EVT_MENU(self.parent, self.addKahDBServerId, self.doAddKahDBServer)
        EVT_MENU(self.parent, self.addPlugInId, self.doAddPlugIn)
        EVT_MENU(self.parent, self.connectAGId, self.doAGConnect)
        EVT_MENU(self.parent, self.disconnectAGId, self.doAGDisconnect)
        EVT_MENU(self.parent, self.advertiseAGId, self.doAGAdvertise)
        EVT_MENU(self.parent, self.getPubAGId, self.doAGgetPub)

        return
        
    #------------------------------------------------------------------------
    def exitApp(self, event):
    #------------------------------------------------------------------------
        print "in exitApp"

        if self.isConnected:
            self.catManager.__del__()
            del self.catManager
        self.parent.Destroy()
        
	return

    #------------------------------------------------------------------------
    def doAddPlugIn(self, event):
    #------------------------------------------------------------------------
        prompt = "Name of source file holding plug-in:"
        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

        theModule = __import__( theName )

        try:
            #handler  = theModule.process
            theModule.registerHook( self.parent.re.extendRecoElemEditMenu)
        except LookupError:
            self.parent.error( "No register hook called 'register' found in plugin")
            return

        return
    
        try:
            menuText = theModule.menuText
        except:
            menuText = theName

        try:
            helpText = theModule.helpText
        except:
            helpText = theName + " empty help string"

        
        self.parent.re.extendRecoElemEditMenu(menuText, helpText, handler)

        return


    #------------------------------------------------------------------------
    def doAddLocalFactory( self, event):
    #------------------------------------------------------------------------
        dialog = DoubleTextEntryDialog(self.parent, -1,
                                       "Connect to Database",
                                       prompt = ("Connect string",
                                                 "'oracle' or 'postgres'"),
                                       pos =(300,300),
                                       size=wxSize(300,90),
                                       style=wxDEFAULT_DIALOG_STYLE)
                                       
                                                      
        showDialogResult = dialog.ShowModal()

        if (showDialogResult == wxID_CANCEL):
            return
        elif (showDialogResult == wxID_OK):
            (connectString, dbType) = dialog.GetValue()
        else:
            self.parent.error("Program error in doAddLocalFactory")

        if (connectString == "" or connectString == None or
            dbType == "" or dbType == None):
            self.parent.error("Invalid information.")
            return
        
        try:
            b = BssFactory( connectString, dbType )
        except:
            self.parent.error( "MainMenuBar:doAddLocalFactory could not create factory for %s (type= %s)" % (connectString, dbType ) )
                               

        #try:
        Catalog.instance().addDataFactory(b)
        #except:
        #    self.parent.error("MainMenuBar:doAddLocalFactory could not load %s." % (b.getFoundryName()))
        #    return
        
            
        return
    

    # Begin AG Stuff
    #------------------------------------------------------------------------
    def doAGConnect(self, event):
    #------------------------------------------------------------------------
        from KahDataServices.KahCatAGCfgMgr import KahCatAGCfgMgr
        
        if  not self.isConnected:
            prompt = "URL of AG Venue"
            dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)
            dlg.SetValue("https://ag-2.mcs.anl.gov:8000/Venues/000000fdba5817dd008c00dd000b004f92a")
            if ( dlg.ShowModal() == wxID_OK):
                url = dlg.GetValue()
                if ( url=="" ): return
                dlg.Destroy()
                wxBeginBusyCursor()
                self.catManager = KahCatAGCfgMgr(url)
                self.isConnected = 1
                wxEndBusyCursor()
            else:
                #didn't get a kid name
                dlg.Destroy()
                return

        return

    #------------------------------------------------------------------------
    def doAGDisconnect(self, event):
    #------------------------------------------------------------------------
        if self.isConnected:
            wxBeginBusyCursor()
            self.catManager.__del__()
            del self.catManager
            self.isConnected = 0
            wxEndBusyCursor()
        else:
            self.parent.error("Disconnect failed:  No connection found.")

        return
    
    #------------------------------------------------------------------------
    def doAGAdvertise(self, event):
    #------------------------------------------------------------------------
        if self.isConnected:
            advertiseAGEntryDialog = DoubleTextEntryDialog(self.parent, -1,
                                                      "Advertise on AG",
                                                      prompt = ("server:",
                                                               "port:   "),
                                                      pos =(300,300),
                                                      size=wxSize(300,90),
                                                      style=wxDEFAULT_DIALOG_STYLE)
            
            showAGAdvertise = advertiseAGEntryDialog.ShowModal()

            if (showAGAdvertise == wxID_CANCEL):
                return
            elif (showAGAdvertise == wxID_OK):
                (hostName, portNum) = advertiseAGEntryDialog.GetValue()
            else:
                self.parent.error("Program error in doAGAdvertise")

            if (hostName == "" or hostName == None or
                portNum == "" or portNum == None):
                self.parent.error("Invalid information")
                return

            f = self.parent.getCurrentDataFactory().getFoundryId()
            
            self.catManager.advertise(f, [hostName, int(portNum)])
            
        else:
            self.parent.error("Advertise failed:  No connection found.")
            
        return
    
    #------------------------------------------------------------------------
    def doAGgetPub(self, event):
    #------------------------------------------------------------------------
        
        if ( not self.isConnected ):
            self.parent.error("getPublished failed:  No connection found.")
            return
    
        wxBeginBusyCursor()
        dlg = AGGetPubDialog(self.parent, -1,
                             "AG Server", pos=(300,300),
                             size=(500,400),
                             style=wxDEFAULT_FRAME_STYLE)
        if ( dlg.ShowModal() == wxID_OK):
            dlg.Destroy()
        else:
            #didn't get a kid name
            dlg.Destroy()
            wxEndBusyCursor()
            return

        servers  = dlg.GetValue()
        self.parent.mainMenuBar.catManager.addServers(servers)
        wxEndBusyCursor()
        
        return
            
    #------------------------------------------------------------------------
    def selectFont(self, event):
    #------------------------------------------------------------------------
        
        #All fonts will be change, but need to know what is the font is for
        #at least one
        self.curFont = self.parent.GetFont()
        print "self.curFont", self.curFont
        
        self.fontData = wxFontData()
        self.fontData.EnableEffects(True)
        self.fontData.SetInitialFont(self.curFont)
        print "main point size", self.curFont.GetPointSize()

        dlg = wxFontDialog(self.parent, self.fontData)
        if dlg.ShowModal() == wxID_OK:
            
            self.fontData = dlg.GetFontData()
            self.newFont = self.fontData.GetChosenFont()
            print "still keeps?", self.newFont.GetPointSize()
            self.parent.fontManager.updateFont(self.newFont)
        dlg.Destroy()
        
        return
	    

    #------------------------------------------------------------------------
    def doAddKahDBServer(self, event):
    #------------------------------------------------------------------------
        addKahDBTextEntryDialog = DoubleTextEntryDialog(self.parent, -1,
                                                      "Add KahDB Server",
                                                      prompt = ("server",
                                                               "port          "),
                                                      pos =(300,300),
                                                      size=(250,90),
                                                      style=wxDEFAULT_DIALOG_STYLE)
                                                      
        showAddKahDBServer = addKahDBTextEntryDialog.ShowModal()

        if (showAddKahDBServer == wxID_CANCEL):
            return
        elif (showAddKahDBServer == wxID_OK):
            (theServer, thePort) = addKahDBTextEntryDialog.GetValue()
        else:
            self.parent.error("Program error in doAddKahDBServer")

        if (theServer == "" or theServer == None or
            thePort == "" or thePort == None):
            self.parent.error("Invalid information")
            return
        
        theConnectionInfo = [theServer, int(thePort)]
        b = BssFactoryProxy(theConnectionInfo)

        try:
            Catalog.instance().addDataFactory(b)
        except:
            self.parent.error("MainMenuBar:doAddKahDBServer could not load %s." % (b.getFoundryName()))
            return
        
            
        #self.parent.error("Not implemented yet")
        return

    #------------------------------------------------------------------------
    def doAddSeedServer(self, event):
    #------------------------------------------------------------------------
        wxBeginBusyCursor()

        prompt = "Seed server, (e.g. 'http://theSeed.uchicago.edu/FIG)"
        dlg = wxTextEntryDialog(self.parent, message=prompt, style=wxOK)

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


	# 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

        wxEndBusyCursor()

        return 


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3