commit-gnue
[Top][All Lists]
Advanced

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

gnue/designer/src/templates/forms FormBuilder.py


From: Jason Cater
Subject: gnue/designer/src/templates/forms FormBuilder.py
Date: Sun, 22 Dec 2002 21:43:00 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/12/22 21:43:00

Modified files:
        designer/src/templates/forms: FormBuilder.py 

Log message:
        more work on converting wizards

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/templates/forms/FormBuilder.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text

Patches:
Index: gnue/designer/src/templates/forms/FormBuilder.py
diff -c gnue/designer/src/templates/forms/FormBuilder.py:1.10 
gnue/designer/src/templates/forms/FormBuilder.py:1.11
*** gnue/designer/src/templates/forms/FormBuilder.py:1.10       Sun Dec 22 
20:31:38 2002
--- gnue/designer/src/templates/forms/FormBuilder.py    Sun Dec 22 21:42:59 2002
***************
*** 62,67 ****
--- 62,68 ----
    #
    def Start(self, form, current):
      self.form = form
+     self.current = current
  
      # The first table can never have a master
      self.variables['hasmaster0'] = '0'
***************
*** 351,414 ****
    # No more user input is allowed at this point.
    #
    def Finalize(self):
-     # Create a single page on which to place blocks and labels
-     pageCounter = 1
-     page = None
-     for child in self.form._children:
-       if child._type == 'GFPage':
-         page = child
-         break
-                             
-     if not page:
-       page = self.AddElement('page', self.form,
-        {  'name': 'pg%s' % pageCounter })
  
!     #
!     # Add datasources
!     #
      basey = 0
!     dataSourceArray = []
      for count in range(self.variables['iterations']):
!       if self.variables['newPage%s' % count] == '1':
          pageCounter += 1
!         page = self.AddElement('page', self.form,
                                 {  'name': 'pg%s' % pageCounter })
          basey=0
  
        tableKey = string.upper(self.variables['table%s' % count])
        datasource = self.AddElement('datasource', self.form,
!                                    {  'database': 
self.variables['connection%s' % count],
                                        'table': self.variables['table%s' % 
count],
                                        'type': 'object',
                                        'name': 'dts%s%s' %  (tableKey,count) })
  
!       # Is this a grid style block?
        multirecord = self.variables['tablearrangement%s' % count] == 'grid'
  
        # Will labels appear above or to the left of the entries?
        # Note: this results in false for both "grid" and "above"
        leftlabels = self.variables['tablearrangement%s' % count] == 'left'
  
        # The basic attributes for a block
!       attrs = {'name' : 'blk%s%s' % (tableKey,count),
!                'datasource': datasource.name}
  
        # If this is a multirecord form, set rows at the block level.
        if multirecord:
          attrs['rows'] = 10
  
        # Create the block
!       block = self.AddElement('block', page, attrs)
  
-       tableSchema = self.GetSourceSchema(self.variables['connection%s' % 
count],
-                          self.variables['table%s' % count])
  
        # Make a map of all the field schemas we will need
        # We will not actually create the entries at this point
        # because we want to keep in the order that the user
        # specified
        fields = {}
!       for field in tableSchema.getChildSchema(tableSchema):
          if field.name in self.variables['tablefields%s' % count]:
            fields[field.name] = field
  
--- 352,418 ----
    # No more user input is allowed at this point.
    #
    def Finalize(self):
  
!     logic = self.current['logic']
!     layout = self.current['layout']
!     page = self.current['page']
! 
!     formwidth = 0
!     formheight = 0
      basey = 0
!     dataSourceArray = {}
!     pageCounter = 1
! 
! 
      for count in range(self.variables['iterations']):
!       if not page or self.variables['newPage%s' % count] == '1':
          pageCounter += 1
!         page = self.AddElement('page', layout,
                                 {  'name': 'pg%s' % pageCounter })
          basey=0
  
        tableKey = string.upper(self.variables['table%s' % count])
        datasource = self.AddElement('datasource', self.form,
!                                    {  'connection': 
self.variables['connection%s' % count],
                                        'table': self.variables['table%s' % 
count],
                                        'type': 'object',
                                        'name': 'dts%s%s' %  (tableKey,count) })
  
! 
!       # Is this a grid style form?
        multirecord = self.variables['tablearrangement%s' % count] == 'grid'
  
        # Will labels appear above or to the left of the entries?
        # Note: this results in false for both "grid" and "above"
        leftlabels = self.variables['tablearrangement%s' % count] == 'left'
  
+ 
+       # We will need a block to hold our entries...
+ 
        # The basic attributes for a block
!       attrs = {'name' : 'blk%s' % tableKey,
!                'datasource': datasource['name']}
  
        # If this is a multirecord form, set rows at the block level.
        if multirecord:
          attrs['rows'] = 10
  
        # Create the block
!       block = self.AddElement('block', logic, attrs)
! 
!       schema = self.GetSourceSchema(self.variables['connection%s' % count],
!                            self.variables['table%s' % count])
! 
! 
!       # Create the entries and labels...
  
  
        # Make a map of all the field schemas we will need
        # We will not actually create the entries at this point
        # because we want to keep in the order that the user
        # specified
        fields = {}
!       for field in schema.getChildSchema(schema):
          if field.name in self.variables['tablefields%s' % count]:
            fields[field.name] = field
  
***************
*** 417,426 ****
        largestField = 0
        largestLabel = 0
  
!       # Now, let's make all the entries
        for name in self.variables['tablefields%s' % count]:
  
          field = fields[name]
          # We will use the field name as the basis for all our
          # entry and label names.  Capitalize the first letter
          # and strip all spaces...
--- 421,431 ----
        largestField = 0
        largestLabel = 0
  
!       # First, let's make all the fields
        for name in self.variables['tablefields%s' % count]:
  
          field = fields[name]
+ 
          # We will use the field name as the basis for all our
          # entry and label names.  Capitalize the first letter
          # and strip all spaces...
***************
*** 436,481 ****
          text = hasattr(field,'label') and label or \
                 string.capwords(string.replace(field.name,'_',' ')) + ':'
  
!         labelQueue.append(self.AddElement('label', page,
!                     {'Char:x':1, 'Char:y': 1,
!                      'name': "lbl%s" % fieldKey,
!                      'text': text,
!                      'Char:width': len(text)}))
  
          # Keep track of the greatest label width
!         largestLabel = largestLabel < len(text) and len(text) or largestLabel
! 
  
          # Create an entry for this field.
  
!         attrs={'Char:x':1, 'Char:y': 1,
!                'name': "inp%s" % fieldKey,
!                'field': field.name,
!                'typecast': field.datatype,
!                'Char:width': 10}
  
          # If we have a length for the field, use this as the max_length
          # for the entry. Also, adjust the display width if necessary.
          if hasattr(field,'length'):
!           attrs['max_length'] = field.length
!           if field.length < 25:
!             attrs['Char:width'] = field.length
!           else:
!             attrs['Char:width'] = 25
! 
!         # Keep track of the greatest field width
!         largestField = largestField < attrs['Char:width'] and \
!                attrs['Char:width'] or largestField
  
          # Create the entry element
!         entryQueue.append(self.AddElement('entry', block, attrs))
  
  
        # Rearrange the fields and labels to snugly fit the screen
        # based on the layout arrangement selected by the user.
! 
!       height = 0
!       width = 0
  
        # Grid/multirecord layout
        if multirecord:
--- 441,479 ----
          text = hasattr(field,'label') and label or \
                 string.capwords(string.replace(field.name,'_',' ')) + ':'
  
!         # Add text, x, y to labelQueue
!         # The x,y will be replaced by logic later on...
!         labelQueue.append([text,0,0])
  
          # Keep track of the greatest label width
!         largestLabel = max(len(text),largestLabel)
  
          # Create an entry for this field.
  
!         attrs={ 'name': "fld%s" % fieldKey,
!                 'field': field.name,
!                 'typecast': field.datatype }
  
          # If we have a length for the field, use this as the max_length
          # for the entry. Also, adjust the display width if necessary.
          if hasattr(field,'length'):
!           ln = min(field.length, 25)
!           attrs['max_length'] = ln
!           largestField = max(largestField, ln)
!         else:
!           largestField = max(largestField, 10)
  
          # Create the entry element
!         fld = self.AddElement('field', block, attrs)
  
+         # and queue it so we can create entry's later
+         entryQueue.append([fld, 0, 0] )
  
+ 
+       #
        # Rearrange the fields and labels to snugly fit the screen
        # based on the layout arrangement selected by the user.
!       #
  
        # Grid/multirecord layout
        if multirecord:
***************
*** 485,508 ****
          x = 1
  
          for i in range(len(entryQueue)):
!           labelQueue[i].x = x
!           labelQueue[i].y = basey + 1
!           entryQueue[i].x = x
!           entryQueue[i].y = basey + 2
  
            # If label width is larger than entry width, center the entry
!           if entryQueue[i].width < labelQueue[i].width:
!             entryQueue[i].x = entryQueue[i].x + \
!                 int((labelQueue[i].width - entryQueue[i].width)/2)
! 
  
            # Calculate the starting x for the next label/entry
!           dx = (entryQueue[i].width < labelQueue[i].width and \
!                 labelQueue[i].width or entryQueue[i].width) + 1
  
            # Increase the form width accordingly
            width += dx
!           x = x + dx
  
        # Single Record layout (regardless of label location)
        else:
--- 483,511 ----
          x = 1
  
          for i in range(len(entryQueue)):
!           field = entryQueue[i][0]
!           text = labelQueue[i][0]
!           textLen = len(text)
! 
!           labelQueue[i][1] = x
!           labelQueue[i][2] = 1
!           entryQueue[i][1] = x
!           entryQueue[i][2] = 2
  
            # If label width is larger than entry width, center the entry
!           try:
!             entryWidth = min(field['max_length'],25)
!           except KeyError:
!             entryWidth = 10
!           if entryWidth < textLen:
!             entryQueue[i][1] += int((textLen - entryWidth)/2)
  
            # Calculate the starting x for the next label/entry
!           dx = max(entryWidth, textLen) + 1
  
            # Increase the form width accordingly
            width += dx
!           x += dx
  
        # Single Record layout (regardless of label location)
        else:
***************
*** 511,566 ****
          # as well as the delta (x,y) values.
          if leftlabels:
            # Labels to the left of the entries
!           lx, ly, ldx, ldy = (1, basey + 1, 0, 1)
!           fx, fy, fdx, fdy = (largestLabel + 2, basey + 1, 0, 1)
  
            # Set form width
            width = largestField + largestLabel + 3
  
          else:
            # Labels above the entries
!           lx, ly, ldx, ldy = (1, basey +1, 0, 3)
!           fx, fy, fdx, fdy = (1, basey +2, 0, 3)
  
            # Set the form width
!           width = 2 + (largestField > largestLabel and largestField \
!                                  or largestLabel)
  
          # Rearrange
!         if height < fy+2-fdy:
!           height = fy+2-fdy
! 
          for i in range(len(entryQueue)):
!           entryQueue[i].x = fx
!           entryQueue[i].y = fy
!           labelQueue[i].x = lx
!           labelQueue[i].y = ly
            ly = ly + ldy
            lx = lx + ldx
            fy = fy + fdy
            fx = fx + fdx
  
!           if height < height + fdy:
!             height += fdy
  
-       basey = height - 1
  
!       dataSourceArray.append(datasource)
  
-       ####
-       #### Set detail datasource to point towards master
-       ####
-       if self.variables['hasmaster%s' % count] == '1':
-         master = int(self.variables['mastertable%s' % count])
-         datasource.master = dataSourceArray[master].name # 
masterDataSource.name
-         datasource.masterlink = 
string.join(self.variables['masterkeys%s'%count],',')
-         datasource.detaillink = 
string.join(self.variables['detailkeys%s'%count],',')
  
      #
      # Set the basic attributes of the form
      #
!     self.ModifyElement(self.form, title=self.variables['title'],
!                        width=width, height=height)
  
      return 1
  
--- 514,596 ----
          # as well as the delta (x,y) values.
          if leftlabels:
            # Labels to the left of the entries
!           lx, ly, ldx, ldy = (1, 1, 0, 1)
!           fx, fy, fdx, fdy = (largestLabel + 2, 1, 0, 1)
  
            # Set form width
            width = largestField + largestLabel + 3
  
          else:
            # Labels above the entries
!           lx, ly, ldx, ldy = (1, 1, 0, 3)
!           fx, fy, fdx, fdy = (1, 2, 0, 3)
  
            # Set the form width
!           width = 2 + max(largestField, largestLabel)
  
          # Rearrange
!         height = fy+2-fdy
          for i in range(len(entryQueue)):
!           labelQueue[i][1] = lx
!           labelQueue[i][2] = ly
!           entryQueue[i][1] = fx
!           entryQueue[i][2] = fy
! 
            ly = ly + ldy
            lx = lx + ldx
            fy = fy + fdy
            fx = fx + fdx
+           height += fdy
+ 
  
!       #
!       # Finally, add the visual elements...
!       #
!       for i in range(len(entryQueue)):
! 
!         #
!         # First, the label
!         #
!         text, x, y = labelQueue[i]
!         self.AddElement( 'label', page,
!                     {'Char:x': x,
!                      'Char:y': y,
!                      'name': "lbl%s" % fieldKey,
!                      'text': text,
!                      'Char:width': len(text)})
! 
!         #
!         # And the entry...
!         #
!         field, x, y = entryQueue[i]
!         attrs={'name': "ent%s" % field['name'][3:],
!                'field': field['name'],
!                'block': block['name'],
!                'Char:x': x,
!                'Char:y': y,
!                'Char:width': 10 }
! 
!         # If we have a length for the field, use this as the max_length
!         # for the entry. Also, adjust the display width if necessary.
!         try:
!           attrs['Char:width'] = min(field['max_length'], 25)
!         except KeyError:
!           pass
! 
!         # Create the entry element
!         self.AddElement('entry', page, attrs)
  
  
!       formwidth = max(formwidth, width)
!       formheight = max(formheight, height)
  
  
      #
      # Set the basic attributes of the form
      #
!     self.form['title'] = title
!     layout['Char:width'] = formwidth
!     layout['Char:height'] = formheight
  
      return 1
  



reply via email to

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