main logo
Subject: [dabo-dev] dabo Commit 983
Author: Ed Leafe
Posted: 2005/03/31 20:08:45
 
View Entire Thread
New Search


dabo Commit
Revision 983
Date: 2005-03-31 17:08:43 -0800 (Thu, 31 Mar 2005)
Author: ed

Changed:
U trunk/lib/datanav/Form.py
U trunk/lib/datanav/Grid.py
U trunk/lib/datanav/Page.py
U trunk/ui/uiwx/dGridX.py
U trunk/ui/uiwx/dPanel.py
U trunk/ui/uiwx/dPemMixin.py
U trunk/ui/uiwx/dSizerMixin.py

Log:
Updated the datanav classes to use the dGridX class instead of creating its own grid from wx classes.

Added many updates to the dGridX class to accomodate the workflow when creating a bizobj-driven grid. Also enhanced the buildFromDataSet() method so that you can pass along a list of columns from the data set *not* to include as columns; a dict containing field:order pairs to control column ordering; and a flag to turn off auto-sizing of the columns.
Added evt.stop() calls in the key processing code. Turns out that without them, pressing 'Enter' advanced the selected cell as well as triggered the onEnterAction() code.
Added the ability to defer the sorting to a custom method. This is necessary with bizobj-driven grids, since the sorting needs to be done in the cursor for it to 'stick'.
Added a 'CurrField' property that returns the bound Field for the currently selected column.

Added some methods to dPemMixin that deal with getting sizer information for the given control. This allows for introspection, so that a control can find out how it's being sized. This will be necessary for the Designer; it may have other applications, too.

Added a minor tweak to the layout() method of dPanel. It seems to have helped with some resizing issues.

Modified the parameters sent to the sizers. Now you can specify 'halign' and 'valign', instead of having to pass a single tuple for 'alignment'. You can use either way, but if alignment is passed, halign and valign are ignored.
Added Height and Width properties to sizers. These are read-only, and allow you to determine the current size of the sizer.


Diff:
Modified: trunk/lib/datanav/Form.py
===================================================================
--- trunk/lib/datanav/Form.py 2005-03-30 19:56:04 UTC (rev 982)
+++ trunk/lib/datanav/Form.py 2005-04-01 01:08:43 UTC (rev 983)
@@ -262,7 +262,7 @@
except: pass

if self.beforeSetupPageFrame():
- self.lockScreen()
+# self.lockScreen()
self.pageFrame = PageFrame.PageFrame(self)
self.Sizer.append(self.pageFrame, "expand", 1)
self.pageFrame.addSelectPage()
@@ -274,7 +274,7 @@
self.addEditPages(ds)
self.pageFrame.SetSelection(currPage)
self.afterSetupPageFrame()
- self.unlockScreen()
+# self.unlockScreen()
self.Sizer.layout()
self.refresh()


Modified: trunk/lib/datanav/Grid.py
===================================================================
--- trunk/lib/datanav/Grid.py 2005-03-30 19:56:04 UTC (rev 982)
+++ trunk/lib/datanav/Grid.py 2005-04-01 01:08:43 UTC (rev 983)
@@ -10,731 +10,111 @@
import dabo
import dabo.ui
import dabo.dException as dException
-
dabo.ui.loadUI("wx")
+from dabo.dLocalize import _, n_

-class dGridDataTable(wx.grid.PyGridTableBase):
- def __init__(self, parent):
- wx.grid.PyGridTableBase.__init__(self)

- self.grid = parent
- self.preview = self.grid.Form.preview
- self.bizobj = None #self.grid.Form.getBizobj(parent.DataSource)
- # Holds a copy of the current data to prevent unnecessary re-drawing
- self.__currData = ()
+class Grid(dabo.ui.dGridX):
+ def _afterInit(self):
+ super(Grid, self)._afterInit()
+ self.bizobj = None
+ self._fldSpecs = None
+ self.skipFields = []
+ self.fieldCaptions = {}
+ self.colOrders = {}
+ self.built = False
+ self.customSort = True

- self.initTable()

-
- def initTable(self):
- self.relativeColumns = []
- self.colLabels = []
- self.colNames = []
- self.dataTypes = []
- self.imageBaseThumbnails = []
- self.imageLists = {}
- self.data = []
-
- fs = self.grid.fieldSpecs
-
- self.showCols = [ (fld, int(fs[fld]["listOrder"]) )
- for fld in fs.keys()
- if fld[:5] != "_join" and fs[fld]["listInclude"] == "1"]
-
- # Column order will already be in the field specs. If there is a custom
- # setting by the user, override it.
- for col in self.showCols:
- nm = col[0]
- column = fs[nm]
- colName = "Column_%s" % nm
- pos = self.grid.Application.getUserSetting("%s.%s.%s.%s" % (
- self.grid.Form.Name,
- self.grid.Name,
- colName,
- "ColumnOrder"))
- if pos is not None:
- self.showCols[self.showCols.index(col)] = (col[0], pos)
-
- self.showCols.sort(lambda x, y: cmp(x[1], y[1]))
- self.setColumnLabels()
+ def getDataSet(self):
+ ret = self.dataSet
+ if not self.inAutoSizeCalc:
+ if self.bizobj:
+ ret = self.bizobj.getDataSet()
+ return ret

-
- def setColumnLabels(self):
- self.colLabels = []
- self.colNames = []
- self.dataTypes = []
- fs = self.grid.fieldSpecs
- for col in self.showCols:
- fldInfo = fs[col[0]]
- self.colLabels.append(fldInfo["caption"])
- self.colNames.append(col[0])
- self.dataTypes.append(self.getWxGridType(fldInfo["type"]))
-
-
- def fillTable(self):
- """ Fill the grid's data table to match the bizobj.
- """
- rows = self.GetNumberRows()
- if self.preview:
- oldRow = 0
- else:
- oldRow = self.bizobj.RowNumber # current row per the bizobj
- oldCol = self.grid.GetGridCursorCol() # current column per the grid
- if not oldCol:
- oldCol = 0

- if not self.preview:
- # Fill self.data based on bizobj records
- dataSet = self.bizobj.getDataSet()
+ def populate(self):
+ if not self.built:
+ self.buildFromDataSet(self.getDataSet(),
+ keyCaption=self.fieldCaptions,
+ columnsToSkip=self.skipFields,
+ colOrder=self.colOrders)
+ self.built = True
else:
- # Create a single empty row for the data set
- dataRec = {}
- for fld in self.grid.fieldSpecs.keys():
- fldInfo = self.grid.fieldSpecs[fld]
- if bool(int(fldInfo["listInclude"])):
- typ = fldInfo["type"]
- if typ == "int":
- val = 0
- elif typ == "float":
- val = 0.0
- elif typ[:4] == "date":
- val = "2000-12-21"
- else:
- val = "test data"
- dataRec[fld] = val
- # Add 100 rows
- dataSet = []
- for i in range(100):
- dataSet.append(dataRec)
- # update the form
- self.grid.Form.rowNumber = 0
- self.grid.Form.rowCount = 100
+ self.fillGrid()

- if self.__currData == dataSet:
- # Nothing's changed; no need to re-fill the table
- return
- else:
- self.__currData = dataSet
-
- self.Clear()
- self.data = []
- for record in dataSet:
- recordDict = []
- for col in self.showCols:
- nm = col[0]
- column = self.grid.fieldSpecs[nm]
- recordVal = record[nm]
- if type(recordVal) == type(""):
- # Limit to first 64 chars...
- recordVal = str(recordVal)[:64]
- elif column["type"] == "bool":
- # coerce to bool (could have been 0/1)
- if type(recordVal) == type(""):
- recordVal = bool(int(recordVal))
- else:
- recordVal = bool(recordVal)
- recordDict.append(recordVal)
- self.data.append(recordDict)
- grdView = self.GetView()
- grdView.BeginBatch()
- # The data table is now current, but the grid needs to be
- # notified.
- if len(self.data) > rows:
- # tell the grid we've added row(s)
- num = len(self.data) - rows
- msg = wx.grid.GridTableMessage(self, # The table
- wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
- num) # how many
-
- elif rows > len(self.data):
- # tell the grid we've deleted row(s)
- num = rows - len(self.data)
- msg = wx.grid.GridTableMessage(self, # The table
- wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, # what we did to it
- 0, # position
- num) # how many
- else:
- msg = None
- if msg:
- grdView.ProcessTableMessage(msg)

- # Column widths come from dApp user settings, the fieldSpecs, or get sensible
- # defaults based on field type.
- index = 0
- for col in self.showCols:
- nm = col[0]
- column = self.grid.fieldSpecs[nm]
- colName = "Column_%s" % nm
- gridCol = index
- fieldType = column["type"]
-
- # 1)
[excessive length snipped]
 
©2005 Ed Leafe
<-- Prior Message New Search Next Message -->