/[papo]/gnue/forms/src/GFClient.py
ViewVC logotype

Diff of /gnue/forms/src/GFClient.py

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

revision 1.5 by styxman, Thu Nov 14 22:16:53 2002 UTC revision 1.5.2.1 by anthonyl, Tue Mar 4 22:18:22 2003 UTC
# Line 16  Line 16 
16  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
17  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
18  #  #
19  # Copyright 2000-2002 Free Software Foundation  # Copyright 2000-2003 Free Software Foundation
20  #  #
21  # FILE:  # FILE:
22  # GFClient.py  # GFClient.py
23  #  #
24  # DESCRIPTION:  # DESCRIPTION:
25  # Client startup file that parses args, builds form from file  # Command line client startup file that parses args,
26  # and passes control to a UI.  # imports the required UI, configures the controling
27    # GFInstance and passes control to it.
28  #  #
29  # NOTES:  # NOTES:
30  #  Once all the events are moved back in here  #
31  #    debug  
32  #    make the next/prec methods more generic in the GFForm  import os, sys
 #    change self._form in here to a list  
   
 import os, copy  
 import os.path  
 import sys  
 import urllib  
33    
34  from gnue.common.GClientApp import *  from gnue.common.GClientApp import *
 from gnue.forms.GFInstance import *  
 from gnue.forms.GFForm import *  
 from gnue.forms.GFParser import loadFile  
 from gnue.forms import GFKeyMapper  
35  from gnue.common import GDebug  from gnue.common import GDebug
36  from gnue.common import GConfig, GDataObjects, GConnections  from gnue.common import GConfig, GDataObjects, GConnections
37  from gnue.common.FileUtils import dyn_import  from gnue.common.FileUtils import dyn_import
38    
39  from gnue.forms import VERSION  from gnue.forms import VERSION
40    from gnue.forms.GFInstance import *
41  from gnue.forms.GFConfig import ConfigOptions  from gnue.forms.GFConfig import ConfigOptions
42    
43  class GFClient(GClientApp):  class GFClient(GClientApp):
# Line 56  class GFClient(GClientApp): Line 49  class GFClient(GClientApp):
49    NAME = "GNUe Forms"    NAME = "GNUe Forms"
50    USAGE = GClientApp.USAGE + " file"    USAGE = GClientApp.USAGE + " file"
51    COMMAND_OPTIONS = [    COMMAND_OPTIONS = [
52        [ 'user_interface', 'u', 'interface', 1, 'wx', 'type',        [ 'user_interface', 'u', 'interface', 1, None, 'type',
53            _('The currently supported values for <type> are ') \            _('The currently supported values for <type> are ') \
54            +'wx (GUI), gtk2, and curses' ],            +'wx (GUI), gtk2, and curses' ],
55        [ 'splash_screen','s','no-splash', 0, None, None,        [ 'splash_screen','s','no-splash', 0, None, None,
# Line 65  class GFClient(GClientApp): Line 58  class GFClient(GClientApp):
58    SUMMARY = \    SUMMARY = \
59       _("GNUe Forms is the primary user interface to the GNU Enterprise system.")       _("GNUe Forms is the primary user interface to the GNU Enterprise system.")
60    
   #  
   # Initialize the class  
   #  
61    def __init__(self, connections=None):    def __init__(self, connections=None):
62      GClientApp.__init__(self, connections,'forms',ConfigOptions)      GClientApp.__init__(self, connections,'forms',ConfigOptions)
63      self.configurationManager.registerAlias('gConfigForms', 'forms')      self.configurationManager.registerAlias('gConfigForms', 'forms')
64    
     self._formInstances = {}  
     self._lastSerialNumber = 0  
   
     self.ui_type = self.OPTIONS['user_interface']  
   
     if gConfig('disableSplash') == '1':  
       self.disableSplash = 1  
     else:  
       self.disableSplash = self.OPTIONS['splash_screen']  
   
65    #    #
66    # Run the client application    # Run the client application
67    #    #
   # GClientApp().run() override  
   #  
68    def run(self):    def run(self):
69        #
70      # assign form file from 1st free argument      # assign form file from 1st free argument
71        #
72      try:      try:
73        formfile = self.ARGUMENTS[0]        formfile = self.ARGUMENTS[0]
74      except:      except:
75        try:        try:
76          basename=os.path.basename(sys.argv[0])          basename=os.path.basename(sys.argv[0])
77          # If no form specified, then see if this is a symlinked form definition          # If no form specified, then see if this is a symlinked form definition
78          if (string.split(string.lower(basename),'.')[0] != 'gnue-forms') and \          if not (string.split(string.lower(basename),'.')[0] in ('gnue-forms','gfclient')):
                (string.split(string.lower(basename),'.')[0] != 'gfclient'):  
79            formfile = os.path.join (            formfile = os.path.join (
80                GConfig.getInstalledBase('forms_appbase','common_appbase','install_prefix'),              GConfig.getInstalledBase('forms_appbase','common_appbase','install_prefix'),
81                gConfig('FormDir'),basename+".gfd" )              gConfig('FormDir'),basename+".gfd" )
82          else:          else:
83            raise IndexError            raise IndexError
84        except IndexError:        except IndexError:
85          self.handleStartupError (_("No Forms Definition File Specified."))          self.handleStartupError (_("No Forms Definition File Specified."))
86    
   
87      #      #
88      # Get the user supplied parameters      # Get the user supplied parameters
89      #      #
# Line 124  class GFClient(GClientApp): Line 101  class GFClient(GClientApp):
101        GDebug.printMesg(2,'Param "%s"="%s" ' % \        GDebug.printMesg(2,'Param "%s"="%s" ' % \
102             (string.lower(psplit[0]), psplit[1]))             (string.lower(psplit[0]), psplit[1]))
103    
104        #
105        # Initialize user interface
106        #
107        self.ui_type = self.OPTIONS['user_interface']
108        if not self.ui_type:
109          self.ui_type = gConfigForms('DefaultUI')
110    
111        while 1:
     # Initialize user interface (defaults to gui)  
     #  If the DISPLAY var isn't set then switch to text  
     uiloaded = 0  
   
     while not uiloaded:  
112        try:        try:
113          self._ui = dyn_import("gnue.forms.uidrivers.%s" % (self.ui_type))          self._ui = dyn_import("gnue.forms.uidrivers.%s" % (self.ui_type))
114          uiloaded = 1          break
115        except ImportError, err:        except ImportError, err:
116          GDebug.printMesg(1,_("Unable to load UI driver")+" %s" % self.ui_type)          GDebug.printMesg(1,_("Unable to load UI driver")+" %s" % self.ui_type)
117          GDebug.printMesg(1,err)          GDebug.printMesg(1,err)
118          if self.ui_type != 'curses':          if self.ui_type != 'curses':
           ## TODO: curses  
119            self.ui_type = 'curses'            self.ui_type = 'curses'
120          else:          else:
121            self.handleStartupError(_("Unable to load any valid UI drivers.  Aborting."))            self.handleStartupError(_("Unable to load any valid UI drivers.  Aborting."))
122            sys.exit()            sys.exit()
123    
124      self.loadKeyMappings()      if gConfig('disableSplash') == '1':
125      self.runForm(formfile, self.disableSplash, parameters=userParameters)        self.disableSplash = 1
126        else:
127          self.disableSplash = self.OPTIONS['splash_screen']
   def loadKeyMappings(self):  
     options = gConfigDict()  
     mapping = {}  
   
     for key in options.keys():  
       if string.lower(key)[:4] == 'key_':  
         mapping[key[4:]] = options[key]  
   
     GFKeyMapper.KeyMapper.loadUserKeyMap(mapping)  
128    
129        #
130        # Assign the proper login handler based upon the user interface choice
131        #
132        self.getConnectionManager().setLoginHandler(self._ui.UILoginHandler())
133    
134    def runFormFromTrigger(self, formFile, parameters={}):      #
135      self.runForm(formFile, disableSplash=1, parameters=parameters)      # Create the Instance that will control the loaded form(s)
136        #
137        instance = GFInstance(self,
138                              connections=self.connections, ui=self._ui,
139                              disableSplash=self.disableSplash,
140                              parameters=userParameters)
141    
142        instance.addFormFromFile(formfile)
143    
144    def runForm(self, formFile, disableSplash=0, parameters={}):      instance.activate()
     try:  
       #  
       # Create the instance  
       #  
       instance = GFInstance(self, self.getNextSerialNumber(),  
           connections=self.connections, ui=self._ui, disableSplash=disableSplash,  
           parameters=parameters)  
       self._formInstances[instance.getSerialNumber()] = instance  
   
       #  
       # Assign the proper login handler based upon the user interface choice  
       #  
       self.getConnectionManager().setLoginHandler(self._ui.UILoginHandler())  
   
       #  
       # Build the form tree  
       #  
       fileHandle=openResource(formFile)  
   
       form = loadFile (fileHandle, instance)  
       fileHandle.close()  
   
       #  
       # Start the instance  
       #  
       instance.setForm(form)  
       instance.activate()  
   
     except GConnections.Error, mesg:  
       self.handleStartupError(mesg)  
   
     except IOError, mesg:  
       self.handleStartupError(_("Unable to open file\n\n     %s")%mesg)  
   
     except GDataObjects.ConnectError, mesg:  
       self.handleStartupError(\  
          _("Unable to login to datasource.\n\n       %s") %mesg)  
   
     except GDataObjects.ConnectionError, mesg:  
       self.handleStartupError(\  
          _("Error while communicating with datasource.\n\n       %s") %mesg)  
   
     except GDataObjects.Error, mesg:  
       self.handleStartupError(mesg)  
   
   
   def getNextSerialNumber (self):  
      self._lastSerialNumber = self._lastSerialNumber + 1  
      return self._lastSerialNumber  
145    
146  if __name__ == '__main__':  if __name__ == '__main__':
147    GFClient().run()    GFClient().run()

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26