commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue designer/src/GFDesigner.py designer/src/Te...


From: Jason Cater
Subject: gnue designer/src/GFDesigner.py designer/src/Te...
Date: Fri, 14 Sep 2001 19:10:15 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/09/14 19:10:15

Modified files:
        designer/src   : GFDesigner.py TemplateBase.py TemplateParser.py 
        designer/templates/forms: Simple.py 
        gnue-common/src: GConnections.py 
        gnue-common/src/dbdrivers/postgresql: DBdriver.py 

Log message:
        Updates for Designer wizards

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/GFDesigner.py.diff?cvsroot=OldCVS&tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/TemplateBase.py.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/TemplateParser.py.diff?cvsroot=OldCVS&tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/templates/forms/Simple.py.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GConnections.py.diff?cvsroot=OldCVS&tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.15&tr2=1.16&r1=text&r2=text

Patches:
Index: gnue/designer/src/GFDesigner.py
diff -u gnue/designer/src/GFDesigner.py:1.16 
gnue/designer/src/GFDesigner.py:1.17
--- gnue/designer/src/GFDesigner.py:1.16        Sun Jul 29 16:18:55 2001
+++ gnue/designer/src/GFDesigner.py     Fri Sep 14 19:10:14 2001
@@ -50,6 +50,7 @@
   def __init__(self): 
     GClientApp.__init__(self, application="forms")
     self._instances = []
+    self.getConnectionManager().setLoginHandler(UIwxpython.UILoginHandler())
     wxApp.__init__(self,0)   
 
   def run(self):
Index: gnue/designer/src/TemplateBase.py
diff -u gnue/designer/src/TemplateBase.py:1.6 
gnue/designer/src/TemplateBase.py:1.7
--- gnue/designer/src/TemplateBase.py:1.6       Thu Sep 13 23:27:30 2001
+++ gnue/designer/src/TemplateBase.py   Fri Sep 14 19:10:14 2001
@@ -91,6 +91,7 @@
   def Start(self, object): 
     return 0
   
+
   # Verify contents of current step
   # Return None if no problems, otherwise
   # return a tuple of error message strings
@@ -119,6 +120,7 @@
       o.__dict__[attr] = attributes[attr]
     return o
 
+
   def GetAvailableConnections(self): 
     rv = []
     p = self._connections.getAllConnectionParameters()
@@ -130,6 +132,34 @@
     return rv
 
 
+  def GetTemporaryConnection(self, connection_name): 
+
+    if not self.__cachedConnections.has_key(connection_name): 
+      self.__cachedConnections[connection_name] = \
+         self._connections.getDataObject(connection_name, 'object')
+      self.__cachedConnections[connection_name].database = connection_name
+      self._connections.requestConnection( \
+         self.__cachedConnections[connection_name], connection_name)
+
+    return self.__cachedConnections[connection_name]
+
+
+  def GetAvailableSources(self, connection_name): 
+
+    if not self.__cachedSources.has_key(connection_name):
+      self.__cachedSources[connection_name] = \
+        self.GetTemporaryConnection(connection_name).getSchemaList()
+
+    list = []
+    for schema in self.__cachedSources[connection_name]: 
+      list.append ((schema.name, schema.name))
+    return list
+
+
+  def GetAvailableFields(self, connection_name, source_name): 
+    return [('field1','field1'),('field2','field2')]
+
+
   ##########################################
   # 
   #  The following methods are of no concern  
@@ -139,8 +169,11 @@
   def __init__(self, parser): 
     self.parser = parser
     self._connections = parser.instance._app.connections
+    self.__cachedConnections= {}
+    self.__cachedSources= {}
 
 
+
 ###########################################################
 #
 # Base class for a form template
@@ -185,7 +218,8 @@
 class WizardInput (WizardItem): 
   def __init__(self, variable, label, typecast=text, 
                set=None, size=10, lowerbound=None, upperbound=None, 
-               forceupper=0, forcelower=0, required=0):
+               forceupper=0, forcelower=0, required=0, lines=1, 
+               maxSelections=1, orderable=0):
 
     self.variable = variable
     self.label = label
@@ -196,4 +230,10 @@
     self.upperbound = upperbound
     self.forceupper = forceupper
     self.forcelower = forcelower
+    self.lines = lines
     required = required
+
+    # The following only have an effect is set != None
+    self.maxSelections = maxSelections
+    self.orderable = orderable
+
Index: gnue/designer/src/TemplateParser.py
diff -u gnue/designer/src/TemplateParser.py:1.4 
gnue/designer/src/TemplateParser.py:1.5
--- gnue/designer/src/TemplateParser.py:1.4     Thu Sep 13 23:27:30 2001
+++ gnue/designer/src/TemplateParser.py Fri Sep 14 19:10:14 2001
@@ -222,7 +222,14 @@
           x = x + xSpacing + o.GetSize().x
 
         if object.set != None and len(object.set): 
-          o = TextField(object, self, pos=wxPoint(x, nextY))          
+          if object.maxSelections != 1 and object.orderable: 
+            x = xMarginInput
+            nextY = nextY + ySpacing + o.GetSize().y
+            o = SortableListField(object, self, pos=wxPoint(x, nextY))
+          elif  object.lines > 1 or object.maxSelections != 1: 
+            o = ListField(object, self, pos=wxPoint(x, nextY))
+          else: 
+            o = ComboField(object, self, pos=wxPoint(x, nextY))
         else:
           o = TextField(object, self, pos=wxPoint(x, nextY))
 
@@ -235,7 +242,8 @@
 
 
 class TextField(wxTextCtrl): 
-  def __init__(self, source, parent, pos=wxDefaultPosition, 
size=wxDefaultSize): 
+  def __init__(self, source, parent, 
+               pos=wxDefaultPosition, size=wxDefaultSize): 
     wxTextCtrl.__init__(self, parent, -1, pos=pos, size=size)
     self.source = source
     self.parent = parent
@@ -265,6 +273,150 @@
 
 
 
-class SetTextField(wxTextCtrl): 
+class ComboField(wxComboBox): 
   def __init__(self, source, parent, pos=wxDefaultPosition, 
size=wxDefaultSize): 
-    wxTextCtrl.__init__(self, parent, -1, pos=pos, size=size)
+    wxComboBox.__init__(self, parent, -1, pos=pos, size=size)
+    self.source = source
+    self.parent = parent
+    self.mapping = {}
+    self.lookup = []
+
+    i = 0
+    for choice in source.set: 
+      key, descr = choice
+      self.mapping[key] = i
+      self.lookup.append(key)
+      self.Append(descr)
+      i = i + 1
+
+  def get(self): 
+    return self.lookup[self.GetSelection()]
+
+  def set(self, value): 
+    self.SetSelection(self.mapping[value])
+
+
+
+class ListField(wxListBox): 
+  def __init__(self, source, parent, pos=wxDefaultPosition, 
size=wxDefaultSize): 
+    if source.maxSelections != 1: 
+      style = wxLB_MULTIPLE
+    else: 
+      style = wxLB_SINGLE
+
+    wxListBox.__init__(self, parent, -1, pos=pos, size=size, \
+            style=style|wxLB_HSCROLL|wxLB_NEEDED_SB)
+
+    self.source = source
+    self.parent = parent
+    self.mapping = {}
+    self.lookup = []
+
+    i = 0
+    for choice in source.set: 
+      key, descr = choice
+      self.mapping[key] = i
+      self.lookup.append(key)
+      self.Append(descr)
+      i = i + 1
+
+  def get(self): 
+    return self.lookup[self.GetSelection()]
+
+  def set(self, value): 
+    self.SetSelection(self.mapping[value])
+
+
+
+class SortableListField(wxPanel): 
+  def __init__(self, source, parent, pos=wxDefaultPosition, 
+              size=wxDefaultSize): 
+
+    wxPanel.__init__(self, parent, -1, pos=pos, size=size, 
+              style=wxSIMPLE_BORDER)
+
+    self.source = source
+    self.parent = parent
+
+    self.addButton = wxButton(self, -1, "  Add >")
+    self.delButton = wxButton(self, -1, "< Remove  ")
+    self.upButton = wxButton(self, -1, "Move Up")
+    self.downButton = wxButton(self, -1, "Move Down")
+
+    self.addButton.SetSize(self.downButton.GetSize())
+    self.delButton.SetSize(self.downButton.GetSize())
+    self.upButton.SetSize(self.downButton.GetSize())
+
+    self.addButton.Enable(0)
+    self.delButton.Enable(0)
+    self.upButton.Enable(0)
+    self.downButton.Enable(0)
+
+    self.list1 =     wxListBox(self, -1, wxPoint(6,6), \
+            style=wxLB_MULTIPLE|wxLB_HSCROLL|wxLB_NEEDED_SB)
+
+    self.list2 =     wxListBox(self, -1, \
+            style=wxLB_MULTIPLE|wxLB_HSCROLL|wxLB_NEEDED_SB)
+
+
+    bw, bh = self.delButton.GetSizeTuple()
+    lw, lh = self.list1.GetSizeTuple()
+
+    self.addButton.SetPosition(wxPoint(lw + 12, 12))
+    self.delButton.SetPosition(wxPoint(lw + 12, 16 + bh))
+    self.upButton.SetPosition(wxPoint(lw + 12, 26 + bh*2))
+    self.downButton.SetPosition(wxPoint(lw + 12, 30 + bh*3))
+
+    self.list1.SetSize(wxSize(self.list1.GetSizeTuple()[0], 
+                              36 + bh*4))
+    self.list2.SetSize(self.list1.GetSize())
+
+    self.list2.SetPosition(wxPoint(lw+bw+18,6))
+    lw, lh = self.list1.GetSizeTuple()
+
+    self.SetSize(wxSize(lw*2+bw+25, lh + 13))
+
+    EVT_BUTTON(self, self.addButton.GetId(), self.OnAdd)
+    EVT_BUTTON(self, self.delButton.GetId(), self.OnRemove)
+    EVT_BUTTON(self, self.upButton.GetId(), self.OnMoveUp)
+    EVT_BUTTON(self, self.downButton.GetId(), self.OnMoveDown)
+
+    EVT_LISTBOX(self, self.list1.GetId(), self.OnSelectLeft)
+    EVT_LISTBOX(self, self.list2.GetId(), self.OnSelectRight)
+
+    self.mapping = {}
+    self.lookup = []
+
+    i = 0
+    for choice in source.set: 
+      key, descr = choice
+      self.mapping[key] = i
+      self.lookup.append(key)
+      self.list1.Append(descr)
+      i = i + 1
+
+  def get(self): 
+    return self.lookup[self.GetSelection()]
+
+  def set(self, value): 
+    self.SetSelection(self.mapping[value])
+
+  def OnSelectLeft(self, event): 
+    print "Left"
+
+  def OnSelectRight(self, event): 
+    print "Right"
+
+  def OnAdd(self, event): 
+    print "Add"
+
+  def OnRemove(self, event): 
+    print "Remove"
+
+  def OnMoveUp(self, event): 
+    print "Up"
+
+  def OnMoveDown(self, event): 
+    print "Down"
+
+
Index: gnue/designer/templates/forms/Simple.py
diff -u gnue/designer/templates/forms/Simple.py:1.6 
gnue/designer/templates/forms/Simple.py:1.7
--- gnue/designer/templates/forms/Simple.py:1.6 Thu Sep 13 23:27:30 2001
+++ gnue/designer/templates/forms/Simple.py     Fri Sep 14 19:10:14 2001
@@ -34,26 +34,54 @@
 #    "<insert type here> wizard", the word "wizard" must be
 #    in lower case, as many proper names such as "Foobar Wizard" 
 #    have been trademarked. (No, I'm not kidding :)
+#
+# TODO: Make sure "Foobar Wizard" is not trademarked.
+# TODO: If not, should we?
+#
 
     
 class SimpleFormTemplate(FormTemplate): 
 
-  # The first step in our wizard
+
+  # The first step in our wizard.
+  # The template parser will initially 
+  # call GetStep(FIRST_STEP).
   FIRST_STEP = '0'
 
+
   # Stores all the variables
   # entered by the wizard user.
   variables = {}
+
 
-  # Initialize 
+  ###############
+  #
+  # Initialize any runtime variables
+  #
   def Start(self, form): 
     self.form = form
+
+    self.connections = self.GetAvailableConnections()
+    self.connectionName = None
+    self.connection = None
+    self.datasources = None
+    self.datasource = None
+    self.datasourceName = None 
+    self.fields = None
+
 
-    print self.GetAvailableConnections()
 
-    self.pages = { 
-            '0':  # Step #1 / Get Title, et al
-               { 'title': 'Basic Form Information', 
+  ###############
+  #
+  # Return the markup for a specific page 
+  #
+  def GetStep(self, stepCode):
+
+    #
+    # Step #1 / Get Title, et al
+    #
+    if stepCode == '0':
+      return   { 'title': 'Basic Form Information', 
                  'content': (WizardText('Welcome to the sample form wizard.'),
                              WizardText('To create your form, I need to know 
some basic information. \n'
                                         'First, what shall I call your form? 
This name will appear in \n'
@@ -62,39 +90,71 @@
                                          size=40), 
                              WizardText('What connection should this form use 
to connect to the \ndatabase?'), 
                              WizardInput('connection',label='Connection:', 
required=1, 
-                                         set=self.GetAvailableConnections()),
- 
-                 ), #formTemplateGetSource(variables,multple=0), 
+                                         set=self.connections),
+                             WizardText('You may be asked to login to this 
connection.'), 
+                            ), 
                  'prev': None, 
-                 'next': '1' },
-            '1':  # Step #2 / Get Base Table
-               { 'title': 'Select Base Table/Source', 
+                 'next': '1' }
+
+
+    #
+    # Step #2 / Get Base Table
+    #
+    elif stepCode == '1':  
+        
+      return   { 'title': 'Select Base Table/Source', 
                  'content': (WizardText('Now, please select the base table for 
your form.'),
-                             WizardInput('table', label='Base Table:', 
required=1, 
-                                         size=40), ), 
+                             WizardInput('table', label='Base Table:', 
required=1, lines=5, 
+                                         
set=self.GetAvailableSources(self.variables['connection'])), ), 
                  'prev': '0', 
-                 'next': '2' }, 
-            '2':  # Step #3 / Get Columns to Include
-               { 'title': 'Basic Form Information', 
+                 'next': '2' }
+
+
+    #
+    # Step #3 / Get Columns to Include
+    #
+    elif stepCode == '2':  
+
+      return   { 'title': 'Select Fields to Include', 
+                 'content': (WizardText('Which fields shall I include in your 
form?'),
+                             WizardInput('fields', label='Columns:', 
required=1, 
+                                         maxSelections=-1, orderable=1, 
+                                         set=self.GetAvailableFields( \
+                                                self.variables['connection'], 
+                                                self.variables['table'])), ), 
                  'prev': '1', 
-                 'content': (WizardText('This is\nText'),), 
-                 'next': None } }
-  
+                 'next': None }
 
 
-  # Return the markup for a specific page 
-  def GetStep(self, stepCode):
-    return self.pages[stepCode]
 
+  ###############
+  #
+  # Verify contents of current step
+  # Return None if no problems, otherwise
+  # return a tuple of error message strings
+  #
+  def ValidateStep(self, stepCode): 
 
-  # We have all the data, so generate our form
-  # This is called 
+    # The Simple wizard uses basic "required" 
+    # settings in the page markup, so doesn't
+    # need any special validation.
+    return None
+
+
+
+  ###############
+  #
+  # We have all the data, so generate our form. This 
+  # is called after the user clicks the "Finish" button.
+  # No more user input is allowed at this point. 
+  #
   def GetFinal(self): 
 
-#    self.
     return 1
     
 
+
+############
 #
 # Basic information about this template
 #
Index: gnue/gnue-common/src/GConnections.py
diff -u gnue/gnue-common/src/GConnections.py:1.15 
gnue/gnue-common/src/GConnections.py:1.16
--- gnue/gnue-common/src/GConnections.py:1.15   Thu Sep 13 18:39:21 2001
+++ gnue/gnue-common/src/GConnections.py        Fri Sep 14 19:10:14 2001
@@ -199,11 +199,13 @@
   if sys.platform == 'win32':
     os.putenv('PYTHONCASEOK','1')
 
-#  try: 
-  dbdriver = __import__("gnue/common/dbdrivers/%s/DBdriver" % (driver))
-#  except ImportError: 
-#    raise GDataObjects.ProviderNotSupportedError, \
-#       "No drivers found for provider '%s'" % driver
+  try: 
+    dbdriver = __import__("gnue/common/dbdrivers/%s/DBdriver" % (driver))
+  except ImportError, err: 
+    GDebug.printMesg(1,'ImportError importing driver %s' % (driver))
+    GDebug.printMesg(1,err)
+    raise GDataObjects.ProviderNotSupportedError, \
+       "No drivers found for provider '%s'" % driver
 
   try: 
     dd = dbdriver.supportedDataObjects[type]()
Index: gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.15 
gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.16
--- gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.15  Thu Sep 13 
18:39:22 2001
+++ gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py       Fri Sep 14 
19:10:15 2001
@@ -31,7 +31,7 @@
 
 import pg, pgdb
 
-from string import lower
+from string import lower, join
 import sys
 from gnue.common import GDebug, GDataObjects
 from gnue.common.dbdrivers._dbsig.DBdriver \
@@ -132,16 +132,18 @@
     if includeViews: 
       inClause.append ("'v'")
 
-    statement = 'select relname from pg_class ' + \
-            'where reltype in (%s) order by relname' % \
-            (string.join(inClause,','))
+    # TODO: This excludes any system tables and views. Should it?
+    statement = "select relname, relkind from pg_class " + \
+            "where relkind in (%s) " % (join(inClause,',')) + \
+            "and relname not like 'pg_%' " + \
+            "order by relname" 
 
     cursor = self._dataConnection.cursor()
     cursor.execute(statement)
     
     list = []
     for rs in cursor.fetchall(): 
-      list.append(GDataObjects.Schema(id=string.lower(rs[0]), name=rs[0],
+      list.append(GDataObjects.Schema(id=lower(rs[0]), name=rs[0],
                          type=rs[1] == 'v' and 'view' or 'table'))
 
     cursor.close()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]