dabo Commit
Revision 3211
Date: 2007-06-26 09:31:25 -0700 (Tue, 26 Jun 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3211
Changed:
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Fixed a bug in __onWxGridSelectCell() that can throw an error if the grid is
not yet constructed.
Diff:
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2007-06-23 19:12:27 UTC (rev 3210)
+++ trunk/dabo/ui/uiwx/dGrid.py 2007-06-26 16:31:25 UTC (rev 3211)
@@ -21,9 +21,9 @@
from dabo.dObject import dObject
from dabo.ui import makeDynamicProperty
-# See if the new decimal module is present. This is necessary
+# See if the new decimal module is present. This is necessary
# because if running under Python 2.4 or later and using MySQLdb,
-# some values will be returned as decimals, and we need to
+# some values will be returned as decimals, and we need to
# conditionally convert them for display.
_USE_DECIMAL = True
try:
@@ -48,15 +48,15 @@
def GetAttr(self, row, col, kind=0):
- ## dColumn maintains one attribute object that applies to every
row
+ ## dColumn maintains one attribute object that applies to every
row
## in the column. This can be extended later with optional
cell-specific
## attributes to override the column-specific ones, but I'll
wait for
## the need to present itself... perhaps we can implement a
VFP-inspired
## DynamicBackColor, DynamicFont..., etc.
# I have no idea what the kind arg is for. It is sent by wxGrid
to this
- # function, it always seems to be either 0 or 4, and it isn't
documented in the
- # wxWidgets docs (but it does appear in the wxPython method
signature
+ # function, it always seems to be either 0 or 4, and it isn't
documented in the
+ # wxWidgets docs (but it does appear in the wxPython method
signature
# but still isn't documented there.)
# if kind not in (0, 4):
# # I'd like to know when kind isn't 0, to make sure I've
covered all the
@@ -72,7 +72,7 @@
# has columns, but self.grid.Columns doesn't know about
it yet. Just return
# the default:
return self.grid._defaultGridColAttr.Clone()
- # (further testing reveals that this really isn't a
problem: the grid is
+ # (further testing reveals that this really isn't a
problem: the grid is
# just empty - no columns or rows added yet)
# If a cell attr is set up, use it. Else, use the one set up
for the column.
@@ -101,16 +101,16 @@
return self.grid.RowLabels[row]
except:
return ""
-
+
def GetColLabelValue(self, col):
# The column headers are painted when the wxGrid queries this
method, as
- # this is the most appropriate time to do so. We return "" so
that wx
+ # this is the most appropriate time to do so. We return "" so
that wx
# doesn't draw the string itself.
self.grid._paintHeader(col)
return ""
-
-
+
+
def setColumns(self, colDefs):
"""Create columns based on passed list of column definitions."""
if colDefs == self.colDefs:
@@ -134,14 +134,14 @@
# them to common strings.
if isinstance(col.DataType, type):
typeDict = {
- str : "string",
- unicode : "unicode",
+ str : "string",
+ unicode : "unicode",
bool : "bool",
int : "integer",
- float : "float",
- long : "long",
- datetime.date : "date",
- datetime.datetime : "datetime",
+ float : "float",
+ long : "long",
+ datetime.date : "date",
+ datetime.datetime : "datetime",
datetime.time : "time" }
if _USE_DECIMAL:
typeDict[Decimal] = "decimal"
@@ -157,7 +157,7 @@
dabo.errorLog.write("Unknown
data type found in setColumns(): %s"
% col.DataType)
col.DataType = str(col.DataType)
-
+
# Make sure that all cols have an Order set
for num in range(len(colDefs)):
col = colDefs[num]
@@ -165,13 +165,13 @@
col.Order = num
colDefs.sort(self.orderSort)
self.colDefs = copy.copy(colDefs)
-
+
def orderSort(self, col1, col2):
return cmp(col1.Order, col2.Order)
-
-
+
+
def convertType(self, typ):
- """Convert common types, names and abbreviations for
+ """Convert common types, names and abbreviations for
data types into the constants needed by the wx.grid.
"""
# Default
@@ -191,12 +191,12 @@
ret = wx.grid.GRID_VALUE_STRING
elif lowtyp in (float, "float", "f", "decimal"):
ret = wx.grid.GRID_VALUE_FLOAT
- elif lowtyp in (datetime.date, datetime.datetime,
datetime.time,
+ elif lowtyp in (datetime.date, datetime.datetime, datetime.time,
"date", "datetime", "time", "d", "t"):
ret = wx.grid.GRID_VALUE_DATETIME
return ret
-
+
def CanGetValueAs(self, row, col, typ):
if self.grid.useCustomGetValue:
return self.grid.customCanGetValueAs(row, col, typ)
@@ -204,6 +204,7 @@
dcol = self.grid.Columns[col]
return typ == self.convertType(dcol.DataType)
+
def CanSetValueAs(self, row, col, typ):
if self.grid.useCustomSetValue:
return self.grid.customCanSetValueAs(row, col, typ)
@@ -211,7 +212,7 @@
dcol = self.grid.Columns[col]
return typ == self.convertType(dcol.DataType)
-
+
def fillTable(self, force=False):
""" Fill the grid's data table to match the data set."""
_oldRowCount = self._oldRowCount
@@ -239,7 +240,7 @@
self.grid._syncRowCount()
# Column widths come from multiple places. In decreasing
precedence:
- # 1) dApp user settings,
+ # 1) dApp user settings,
# 2) col.Width (as set by the Width prop or by the fieldspecs)
# 3) have the grid autosize
@@ -259,7 +260,7 @@
self.grid.autoSizeCol(gridCol)
else:
col.Width = width
-
+
# Show the row labels, if any
for idx, label in enumerate(self.grid.RowLabels):
self.SetRowLabelValue(idx, label)
@@ -267,9 +268,9 @@
self._oldRowCount = _newRowCount
-
+
# The following methods are required by the grid, to find out certain
- # important details about the underlying table.
+ # important details about the underlying table.
def GetNumberRows(self):
bizobj = self.grid.getBizobj()
if bizobj:
@@ -318,7 +319,7 @@
dabo.ui.callAfterInterval(200, col_obj._updateDynamicProps)
dabo.ui.callAfterInterval(200, col_obj._updateCellDynamicProps,
row)
-
+
if bizobj:
if field:
ret = bizobj.getFieldVal(field, row)
@@ -348,32 +349,35 @@
-
class GridListEditor(wx.grid.GridCellChoiceEditor):
def __init__(self, *args, **kwargs):
dabo.infoLog.write("GridListEditor: Init ")
dabo.infoLog.write(str(args))
dabo.infoLog.write(str(kwargs))
super(GridListEditor, self).__init__(*args, **kwargs)
-
- def Create(self, parent, id, evtHandler, *args, **kwargs):
+
+
+ def Create(self, parent, id, evtHandler, *args, **kwargs):
dabo.infoLog.write("GridListEditor: Create")
dabo.infoLog.write(str(args))
dabo.infoLog.write(str(kwargs))
- self.control = dabo.ui.dDropdownList(parent=parent, id=id,
- ValueMode="String")
- self.SetControl(self.control)
- if evtHandler:
- self.control.PushEventHandler(evtHandler)
+ self.control = dabo.ui.dDropdownList(parent=parent, id=id,
+ ValueMode="String")
+ self.SetControl(self.control)
+ if evtHandler:
+ self.control.PushEventHandler(evtHandler)
# super(GridListEditor, self).Create(parent, id, evtHandler)
+
def Clone(self):
- return self.__class__()
+ return self.__class__()
+
def SetParameters(self, paramStr):
dabo.infoLog.write("GridListEditor: SetParameters: %s" %
paramStr)
self.control.Choices = eval(paramStr)
-
+
+
def BeginEdit(self, row, col, grid):
dabo.infoLog.write("GridListEditor: BeginEdit (%d,%d)" % (row,
col))
self.value = grid.GetTable().GetValue(row, col)
@@ -381,10 +385,11 @@
dabo.infoLog.write("GridListEditor: Choices=%s" %
self.control.Choices)
try:
self.control.Value = self.value
- except ValueError:
+ except ValueError:
dabo.infoLog.write("GridListEditor: Value not in
Choices")
self.control.SetFocus()
+
def EndEdit(self, row, col, grid):
dabo.infoLog.write("GridListEditor: EndEdit (%d,%d)" % (row,
col))
changed = False
@@ -397,6 +402,7 @@
self.control.Value = self.value
return changed
+
def Reset(self):
dabo.infoLog.write("GridListEditor: Reset")
self.control.Value = self.value
@@ -465,29 +471,29 @@
self.longEditorClass = wx.grid.GridCellNumberEditor
self.decimalEditorClass = wx.grid.GridCellNumberEditor
self.floatEditorClass = wx.grid.GridCellFloatEditor
- self.listEditorClass = wx.grid.GridCellChoiceEditor
+ self.listEditorClass = wx.grid.GridCellChoiceEditor
# self.listEditorClass = GridListEditor
-
+
self.defaultRenderers = {
- "str" : self.stringRendererClass,
- "string" : self.stringRendererClass,
- "bool" : self.boolRendererClass,
- "int" : self.intRendererClass,
- "long" : self.longRendererClass,
+ "str" : self.stringRendererClass,
+ "string" : self.stringRendererClass,
+ "bool" : self.boolRendererClass,
+ "int" : self.intRendererClass,
+ "long" : self.longRendererClass,
"decimal" : self.decimalRendererClass,
- "float" : self.floatRendererClass,
+ "float" : self.floatRendererClass,
"list" : self.listRendererClass }
self.defaultEditors = {
- "str" : self.stringEditorClass,
- "string" : self.stringEditorClass,
- "bool" : self.boolEditorClass,
- "int" : self.intEditorClass,
- "long" : self.longEditorClass,
+ "str" : self.stringEditorClass,
+ "string" : self.stringEditorClass,
+ "bool" : self.boolEditorClass,
+ "int" : self.intEditorClass,
+ "long" : self.longEditorClass,
"decimal" : self.decimalEditorClass,
- "float" : self.floatEditorClass,
+ "float" : self.floatEditorClass,
"list" : self.listEditorClass }
-
+
def _afterInit(self):
self._isConstructed = True
super(dColumn, self)._afterInit()
@@ -503,8 +509,8 @@
else:
args = ()
setattr(self, prop, func(*args))
-
+
def _updateCellDynamicProps(self, row):
kwargs = {"row": row}
self._cellDynamicRow = row
@@ -526,15 +532,15 @@
if needRefresh:
dabo.ui.callAfterInterval(200, self._refreshGrid)
del self._cellDynamicRow
-
+
def _restoreFontZoom(self):
if self.Form and self.Form.SaveRestorePosition:
self.super()
-
+
def _getDefaultFont(self):
- ret = dabo.ui.dFont(Size=10, Bold=False, Italic=False,
+ ret = dabo.ui.dFont(Size=10, Bold=False, Italic=False,
Underline=False)
if sys.platform.startswith("win"):
# The wx default is quite ugly
@@ -545,17 +551,18 @@
def _constructed(self):
return self._isConstructed
-
-
+
+
def release(self):
- """Usually don't need this, but it helps to keep this in
+ """Usually don't need this, but it helps to keep this in
line with other Dabo objects.
"""
try:
self.Parent.removeColumn(self)
except:
pass
-
+
+
def _setAbsoluteFontZoom(self, newZoom):
origFontSize = self._origFontSize = getattr(self,
"_origFontSize", self.FontSize)
origHeaderFontSize = self._origHeaderFontSize = getattr(self,
"_origHeaderFontSize", self.HeaderFontSize)
@@ -642,8 +649,8 @@
if self.Parent:
# This will trigger wx to query GetColLabelValue(),
which will in turn
# call paintHeader() on just this column. It's
roundabout, but gives the
- # best overall results, but risks relying on wx
implementation details.
- # Other options, in case this starts to fail, are:
+ # best overall results, but risks relying on wx
implementation details.
+ # Other options, in case this starts to fail, are:
# self.Parent.Header.Refresh()
#
self.Parent._paintHeader(self._GridColumnIndex)
self.Parent.SetColLabelValue(self._GridColumnIndex, "")
@@ -704,7 +711,7 @@
break
return gridCol
-
+
def _updateEditor(self):
"""The Field, DataType, or CustomEditor has changed: set in the
attr"""
editorClass = self.EditorClass
@@ -726,13 +733,14 @@
else:
renderer = rendClass()
self._gridColAttr.SetRenderer(renderer)
-
+
def _onFontPropsChanged(self, evt):
# Sent by the dFont object when any props changed. Wx needs to
be notified:
self._gridColAttr.SetFont(self.Font._nativeFont)
self._refreshGrid()
+
def _onHeaderFontPropsChanged(self, evt):
# Sent by the dFont object when any props changed. Wx needs to
be notified:
self._refreshHeader()
@@ -745,8 +753,8 @@
cellAttr = self._gridCellAttrs.get(row,
self._gridColAttr.Clone())
getattr(cellAttr, wxPropName)(*args, **kwargs)
self._gridCellAttrs[row] = cellAttr
-
+
def _getBackColor(self):
return self._gridColAttr.GetBackgroundColour()
@@ -759,7 +767,7 @@
else:
self._properties["BackColor"] = val
-
+
def _getCaption(self):
try:
v = self._caption
@@ -881,7 +889,7 @@
if self.Parent:
self.Parent.refresh(sort=False)
else:
- self._properties["Editable"] = val
+ self._properties["Editable"] = val
def _getEditorClass(self):
@@ -925,7 +933,7 @@
else:
v = self.Font =
dabo.ui.dFont(_nativeFont=self._gridColAttr.GetFont())
return v
-
+
def _setFont(self, val):
assert isinstance(val, dabo.ui.dFont)
if self._constructed():
@@ -936,10 +944,10 @@
else:
self._properties["Font"] = val
-
+
def _getFontBold(self):
return self.Font.Bold
-
+
def _setFontBold(self, val):
if self._constructed():
self.Font.Bold = val
@@ -949,22 +957,22 @@
def _getFontDescription(self):
return self.Font.Description
-
-
+
+
def _getFontInfo(self):
return self.Font._nativeFont.GetNativeFontInfoDesc()
-
+
def _getFontItalic(self):
return self.Font.Italic
-
+
def _setFontItalic(self, val):
if self._constructed():
self.Font.Italic = val
else:
self._properties["FontItalic"] = val
-
+
def _getFontFace(self):
return self.Font.Face
@@ -974,20 +982,20 @@
else:
self._properties["FontFace"] = val
-
+
def _getFontSize(self):
return self.Font.Size
-
+
def _setFontSize(self, val):
if self._constructed():
self.Font.Size = val
else:
self._properties["FontSize"] = val
-
+
def _getFontUnderline(self):
return self.Font.Underline
-
+
def _setFontUnderline(self, val):
if self._constructed():
self.Font.Underline = val
@@ -1007,7 +1015,7 @@
else:
self._properties["ForeColor"] = val
-
+
def _getHeaderFont(self):
if hasattr(self, "_headerFont"):
v = self._headerFont
@@ -1015,7 +1023,7 @@
v = self.HeaderFont = self._getDefaultFont()
v.Bold = True
return v
-
+
def _setHeaderFont(self, val):
assert isinstance(val, dabo.ui.dFont)
if self._constructed():
@@ -1024,10 +1032,10 @@
else:
self._properties["HeaderFont"] = val
-
+
def _getHeaderFontBold(self):
return self.HeaderFont.Bold
-
+
def _setHeaderFontBold(self, val):
if self._constructed():
self.HeaderFont.Bold = val
@@ -1038,21 +1046,21 @@
def _getHeaderFontDescription(self):
return self.HeaderFont.Description
-
+
def _getHeaderFontInfo(self):
return self.HeaderFont._nativeFont.GetNativeFontInfoDesc()
-
+
def _getHeaderFontItalic(self):
return self.HeaderFont.Italic
-
+
def _setHeaderFontItalic(self, val):
if self._constructed():
self.HeaderFont.Italic = val
else:
self._properties["HeaderFontItalic"] = val
-
+
def _getHeaderFontFace(self):
return self.HeaderFont.Face
@@ -1062,20 +1070,20 @@
else:
self._properties["HeaderFontFace"] = val
-
+
def _getHeaderFontSize(self):
return self.HeaderFont.Size
-
+
def _setHeaderFontSize(self, val):
if self._constructed():
self.HeaderFont.Size = val
else:
self._properties["HeaderFontSize"] = val
-
-
+
+
def _getHeaderFontUnderline(self):
return self.HeaderFont.Underline
-
+
def _setHeaderFontUnderline(self, val):
if self._constructed():
self.HeaderFont.Underline = val
@@ -1099,7 +1107,7 @@
else:
self._properties["HeaderBackColor"] = val
-
+
def _getHeaderForeColor(self):
try:
v = self._headerForeColor
@@ -1116,7 +1124,7 @@
else:
self._properties["HeaderForeColor"] = val
-
+
def _getHeaderHorizontalAlignment(self):
try:
val = self._headerHorizontalAlignment
@@ -1170,7 +1178,7 @@
if isinstance(dt, basestring):
if dt in ("decimal", "float", "long", "integer"):
self._setHorizontalAlignment("Right",
_autoAlign=True)
-
+
def _setHorizontalAlignment(self, val, _autoAlign=False):
if self._constructed():
val = self._expandPropStringValue(val, ("Automatic",
"Left", "Right", "Center"))
@@ -1193,7 +1201,7 @@
else:
self._properties["HorizontalAlignment"] = val
-
+
def _getListEditorChoices(self):
try:
v = self._listEditorChoices
@@ -1332,8 +1340,8 @@
self.Parent.refresh(sort=False)
else:
self._properties["Width"] = val
-
+
def _getWordWrap(self):
return self._wordWrap
@@ -1360,40 +1368,40 @@
CellForeColor = property(_getCellForeColor, _setCellForeColor, None,
_("Color for the foreground (text) of the current cell
in the column."))
- CustomEditorClass = property(_getCustomEditorClass,
+ CustomEditorClass = property(_getCustomEditorClass,
_setCustomEditorClass, None,
- _("""Custom Editor class for this column. Default:
None.
+ _("""Custom Editor class for this column. Default: None.
- Set this to override the default editor class, which
Dabo will
+ Set this to override the default editor class, which
Dabo will
select based on the data type of the field."""))
CustomEditors = property(_getCustomEditors, _setCustomEditors, None,
- _("""Dictionary of custom editors for this column.
Default: {}.
+ _("""Dictionary of custom editors for this column.
Default: {}.
- Set this to override the default editor class on a
row-by-row basis.
- If there is no custom editor class for a given row in
CustomEditors,
+ Set this to override the default editor class on a
row-by-row basis.
+ If there is no custom editor class for a given row in
CustomEditors,
the CustomEditor property setting will apply."""))
- CustomListEditorChoices = property(_getCustomListEditorChoices,
+ CustomListEditorChoices = property(_getCustomListEditorChoices,
_setCustomListEditorChoices, None,
- _("""Dictionary of custom list choices for this column.
Default: {}.
+ _("""Dictionary of custom list choices for this column.
Default: {}.
- Set this to override the default list choices on a
row-by-row basis.
- If there is no custom entry for a given row in
CustomListEditorChoices,
+ Set this to override the default list choices on a
row-by-row basis.
+ If there is no custom entry for a given row in
CustomListEditorChoices,
the ListEditorChoices property setting will apply."""))
- CustomRendererClass = property(_getCustomRendererClass,
+ CustomRendererClass = property(_getCustomRendererClass,
_setCustomRendererClass, None,
- _("""Custom Renderer class for this column. Default:
None.
+ _("""Custom Renderer class for this column. Default:
None.
- Set this to override the default renderer class, which
Dabo will select based
+ Set this to override the default renderer class, which
Dabo will select based
on the data type of the field."""))
CustomRenderers = property(_getCustomRenderers, _setCustomRenderers,
None,
- _("""Dictionary of custom renderers for this column.
Default: {}.
+ _("""Dictionary of custom renderers for this column.
Default: {}.
- Set this to override the default renderer class on a
row-by-row basis.
- If there is no custom renderer for a given row in
CustomRenderers, the
+ Set this to override the default renderer class on a
row-by-row basis.
+ If there is no custom renderer for a given row in
CustomRenderers, the
CustomRendererClass property setting will apply."""))
DataType = property(_getDataType, _setDataType, None,
@@ -1401,44 +1409,44 @@
Editable = property(_getEditable, _setEditable, None,
_("""If True, and if the grid is set as Editable, the
cell values in this
- column are editable by the user. If False, the
cells in this column
- cannot be edited no matter what the grid
setting is. When editable,
- incremental searching will not be enabled,
regardless of the
+ column are editable by the user. If False, the
cells in this column
+ cannot be edited no matter what the grid
setting is. When editable,
+ incremental searching will not be enabled,
regardless of the
Searchable property setting. (bool)""") )
EditorClass = property(_getEditorClass, None, None,
- _("""Returns the editor class used for cells in the
column. This
- will be self.CustomEditorClass if set, or the
default editor for the
+ _("""Returns the editor class used for cells in the
column. This
+ will be self.CustomEditorClass if set, or the
default editor for the
datatype of the field. (varies)"""))
Expand = property(_getExpand, _setExpand, None,
- _("""Does this column expand/shrink as the grid width
changes?
+ _("""Does this column expand/shrink as the grid width
changes?
Default=False (bool)"""))
-
+
DataField = property(_getDataField, _setDataField, None,
_("Field key in the data set to which this column is
bound. (str)") )
Font = property(_getFont, _setFont, None,
_("The font properties of the column's cells. (dFont)")
)
-
+
FontBold = property(_getFontBold, _setFontBold, None,
_("Specifies if the cell font is bold-faced. (bool)") )
-
- FontDescription = property(_getFontDescription, None, None,
+
+ FontDescription = property(_getFontDescription, None, None,
_("Human-readable description of the column's cell font
settings. (str)") )
-
+
FontFace = property(_getFontFace, _setFontFace, None,
_("Specifies the font face for the column cells.
(str)") )
-
+
FontInfo = property(_getFontInfo, None, None,
_("Specifies the platform-native font info string for
the column cells. Read-only. (str)") )
-
+
FontItalic = property(_getFontItalic, _setFontItalic, None,
_("Specifies whether the column's cell font is
italicized. (bool)") )
-
+
FontSize = property(_getFontSize, _setFontSize, None,
_("Specifies the point size of the column's cell font.
(int)") )
-
+
FontUnderline = property(_getFontUnderline, _setFontUnderline, None,
_("Specifies whether cell text is underlined. (bool)") )
@@ -1450,25 +1458,25 @@
HeaderFont = property(_getHeaderFont, _setHeaderFont, None,
_("The font properties of the column's header.
(dFont)") )
-
+
HeaderFontBold = property(_getHeaderFontBold, _setHeaderFontBold, None,
_("Specifies if the header font is bold-faced. (bool)")
)
-
- HeaderFontDescription = property(_getHeaderFontDescription, None, None,
+
+ HeaderFontDescription = property(_getHeaderFontDescription, None, None,
_("Human-readable description of the current header
font settings. (str)") )
-
+
HeaderFontFace = property(_getHeaderFontFace, _setHeaderFontFace, None,
_("Specifies the font face for the column header.
(str)") )
-
+
HeaderFontInfo = property(_getHeaderFontInfo, None, None,
_("Specifies the platform-native font info string for
the column header. Read-only. (str)") )
-
+
HeaderFontItalic = property(_getHeaderFontItalic, _setHeaderFontItalic,
None,
_("Specifies whether the header font is italicized.
(bool)") )
-
+
HeaderFontSize = property(_getHeaderFontSize, _setHeaderFontSize, None,
_("Specifies the point size of the header font. (int)")
)
-
+
HeaderFontUnderline = property(_getHeaderFontUnderline,
_setHeaderFontUnderline, None,
_("Specifies whether column header text is underlined.
(bool)") )
@@ -1490,7 +1498,7 @@
'Right' """))
ListEditorChoices = property(_getListEditorChoices,
_setListEditorChoices, None,
- _("""Specifies the list of choices that will appear in the
list. Only applies
+ _("""Specifies the list of choices that will appear in the
list. Only applies
if the DataType is set as "list". (list)"""))
Order = property(_getOrder, _setOrder, None,
@@ -1499,35 +1507,35 @@
Precision = property(_getPrecision, _setPrecision, None,
_("Number of decimal places to display for float values
(int)"))
-
+
RendererClass = property(_getRendererClass, None, None,
- _("""Returns the renderer class used for cells in the
column. This will be
- self.CustomRendererClass if set, or the default
renderer class for the
+ _("""Returns the renderer class used for cells in the
column. This will be
+ self.CustomRendererClass if set, or the default
renderer class for the
datatype of the field. (varies)"""))
Searchable = property(_getSearchable, _setSearchable, None,
- _("""Specifies whether this column's incremental search
is enabled.
+ _("""Specifies whether this column's incremental search
is enabled.
Default: True. The grid's Searchable property will
override this setting.
(bool)"""))
Sortable = property(_getSortable, _setSortable, None,
- _("""Specifies whether this column can be sorted.
Default: True. The grid's
+ _("""Specifies whether this column can be sorted.
Default: True. The grid's
Sortable property will override this setting.
(bool)"""))
VerticalAlignment = property(_getVerticalAlignment,
_setVerticalAlignment, None,
- _("""Vertical alignment for all cells in this column.
Acceptable values
+ _("""Vertical alignment for all cells in this column.
Acceptable values
are 'Top', 'Center', and 'Bottom'. (str)"""))
Visible = property(_getVisible, _setVisible, None,
_("Controls whether the column is shown or not
(bool)"))
-
+
Width = property(_getWidth, _setWidth, None,
_("Width of this column (int)") )
-
+
WordWrap = property(_getWordWrap, _setWordWrap, None,
_("When True, text longer than the column width will
wrap to the next line (bool)"))
-
-
+
+
_GridColumnIndex = property(_getGridColumnIndex)
@@ -1574,42 +1582,42 @@
class dGrid(cm.dControlMixin, wx.grid.Grid):
"""Creates a grid, with rows and columns to represent records and
fields.
- Grids are powerful controls for allowing reading and writing of data. A
+ Grids are powerful controls for allowing reading and writing of data. A
grid can have any number of dColumns, which themselves have lots of
properties
to manipulate. The grid is virtual, meaning that large amounts of data
can
- be accessed efficiently: only the data that needs to be shown on the
current
+ be accessed efficiently: only the data that needs to be shown on the
current
screen is copied and displayed.
"""
def __init__(self, parent, properties=None, attProperties=None, *args,
**kwargs):
self._baseClass = dGrid
preClass = wx.grid.Grid
-
+
# Internal flag to determine if the prior sort order needs to
be restored:
self._sortRestored = False
# Internal flag to determine if refresh should be called after
sorting.
self._refreshAfterSort = True
-
+
# Used to provide 'data' when the DataSet is empty.
self.emptyRowsToAdd = 0
# dColumn maintains its own cell attribute object, but this is
the default:
self._defaultGridColAttr = self._getDefaultGridColAttr()
-
+
# Some applications (I'm thinking the UI Designer here) need to
be able
# to set Editing = True, but still disallow editing. This
attribute does that.
self._vetoAllEditing = False
-
+
# Can the user move the columns around?
self._movableColumns = True
# Can the user re-size the columns or rows?
self._resizableColumns = True
self._resizableRows = True
-
+
# Flag to indicate we are auto-sizing all columns
self._inAutoSizeLoop = False
# Flag to indicate we are in a range selection event
self._inRangeSelect = False
-
+
# These hold the values that affect row/col hiliting
self._selectionForeColor = "black"
self._selectionBackColor = "yellow"
@@ -1622,9 +1630,9 @@
self._rowColorEven = "white"
self._rowColorOdd = (212, 255, 212) # very light
green
- cm.dControlMixin.__init__(self, preClass, parent, properties,
attProperties,
+ cm.dControlMixin.__init__(self, preClass, parent, properties,
attProperties,
*args, **kwargs)
-
+
# Need to sync the size reported by wx to the size reported by
Dabo:
self.RowHeight = self.RowHeight
self.ShowRowLabels = self.ShowRowLabels
@@ -1643,7 +1651,7 @@
self.searchCaseSensitive = False
# How many characters of strings do we display?
self.stringDisplayLen = 64
-
+
self.currSearchStr = ""
self.incSearchTimer = dabo.ui.dTimer(self)
self.incSearchTimer.bindEvent(dEvents.Hit,
self.onIncSearchTimer)
@@ -1658,7 +1666,7 @@
# if a grid with variable types in a single column is used.
self.useCustomGetValue = False
self.useCustomSetValue = False
-
+
# What color/size should the little sort indicator arrow be?
self.sortIndicatorColor = "DarkSlateGrey"
self.sortIndicatorSize = 6
@@ -1678,7 +1686,7 @@
self.customSort = False
super(dGrid, self)._afterInit()
-
+
# Set the header props/events
self.initHeader()
# Make sure that the columns are sized properly
@@ -1724,8 +1732,8 @@
# self.bindEvent(dEvents.GridContextMenu, self._onContextMenu)
self.bindEvent(dEvents.GridMouseRightClick,
self._onGridMouseRightClick)
self.bindEvent(dEvents.Resize, self._onGridResize)
-
-
+
+
def initHeader(self):
""" Initialize behavior for the grid header region."""
header = self._getWxHeader()
@@ -1797,33 +1805,33 @@
if isinstance(ret, str):
ret = ret.decode(self.Encoding)
return ret
-
+
def setValue(self, row, col, val):
return self.SetValue(row, col, val)
# These two methods need to be customized if a grid has columns
- # with more than one type of data in them.
+ # with more than one type of data in them.
def customCanGetValueAs(self, row, col, typ): pass
def customCanSetValueAs(self, row, col, typ): pass
# Wrap the native wx methods
def setEditorForCell(self, row, col, edt):
- ## dColumn maintains a dict of overriding editor mappings, but
keep this
+ ## dColumn maintains a dict of overriding editor mappings, but
keep this
## function for convenience.
dcol = self.Columns[col]
dcol.CustomEditors[row] = edt
#self.SetCellEditor(row, col, edt)
-
+
def setRendererForCell(self, row, col, rnd):
## dColumn maintains a dict of overriding renderer mappings,
but keep this
## function for convenience.
dcol = self.Columns[col]
dcol.CustomRenderers[row] = rnd
#self.SetCellRenderer(row, col, rnd)
-
-
+
+
def setTableAttributes(self, tbl=None):
"""Set the attributes for table display"""
if tbl is None:
@@ -1838,13 +1846,13 @@
tbl.alternateRowColoring = self.AlternateRowColoring
tbl.rowColorOdd = self._getWxColour(self.RowColorOdd)
tbl.rowColorEven = self._getWxColour(self.RowColorEven)
-
+
def afterCellEdit(self, row, col):
"""Called after a cell has been edited by the user."""
pass
-
+
def fillGrid(self, force=False):
""" Refresh the grid to match the data in the data set."""
# Get the default row size from dApp's user settings
@@ -1852,14 +1860,14 @@
if rowSize:
self.SetDefaultRowSize(rowSize)
tbl = self._Table
-
+
if self.emptyRowsToAdd and self.Columns:
# Used for display purposes when no data is present.
self._addEmptyRows()
tbl.setColumns(self.Columns)
tbl.fillTable(force)
- if not self._sortRestored:
+ if not self._sortRestored:
dabo.ui.callAfter(self._restoreSort)
self._sortRestored = True
@@ -1877,7 +1885,7 @@
def _restoreSort(self):
self.sortedColumn = self._getUserSetting("sortedColumn")
self.sortOrder = self._getUserSetting("sortOrder")
-
+
if self.sortedColumn is not None:
sortCol = None
for idx, col in enumerate(self.Columns):
@@ -1888,7 +1896,7 @@
if self.RowCount > 0:
self.processSort(sortCol,
toggleSort=False)
-
+
def _addEmptyRows(self):
"""Adds blank rows of data to the grid. Used mostly by
the Designer to display a grid that actually looks like a grid.
@@ -1913,9 +1921,9 @@
self.emptyRowsToAdd = 0
self.DataSet = ds
-
-
- def buildFromDataSet(self, ds, keyCaption=None,
+
+
+ def buildFromDataSet(self, ds, keyCaption=None,
includeFields=None, colOrder=None, colWidths=None,
colTypes=None,
autoSizeCols=True):
"""Add columns with properties set based on the passed dataset.
@@ -1924,18 +1932,18 @@
+ a sequence of dicts, containing fieldname/fieldvalue
pairs.
+ a string, which maps to a bizobj on the form.
- The columns will be taken from the first record of the dataset,
with each
- column header caption being set to the field name, unless
the optional
- keyCaption parameter is passed. This parameter is a 1:1 dict
containing
- the data set keys as its keys, and the desired caption as the
+ The columns will be taken from the first record of the dataset,
with each
+ column header caption being set to the field name, unless
the optional
+ keyCaption parameter is passed. This parameter is a 1:1 dict
containing
+ the data set keys as its keys, and the desired caption as the
corresponding value.
- If the includeFields parameter is a sequence, the only columns
added will
- be the fieldnames included in the includeFields sequence. If
the
+ If the includeFields parameter is a sequence, the only columns
added will
+ be the fieldnames included in the includeFields sequence. If the
includeFields parameter is None, all fields will be added to
the grid.
- The columns will be in the order returned by ds.keys(), unless
the
- optional colOrder parameter is passed. Like the keyCaption
property,
+ The columns will be in the order returned by ds.keys(), unless
the
+ optional colOrder parameter is passed. Like the keyCaption
property,
this is a 1:1 dict containing key:order.
"""
if not ds:
@@ -1969,7 +1977,7 @@
try:
structure =
bizobj.getDataStructureFromDescription()
except:
- # Well, that call failed... seems that
sqlite doesn't define a cursor
+ # Well, that call failed... seems that
sqlite doesn't define a cursor
# description? I need to test this out.
For now, fall back to the old
# code that gets the data structure by
executing "select * from table
# where 1=0". The downside to this is
that no derived fields will be
@@ -1999,7 +2007,7 @@
col.DataField = colKey
## pkm: Get the datatype from what is specified in
fieldspecs, not from
- ## the actual type of the record.
+ ## the actual type of the record.
try:
dt = colTypes[colKey]
except KeyError:
@@ -2023,7 +2031,7 @@
if dt is type(None):
# Default to string type
dt = col.DataType = str
-
+
# See if any order was specified
if colOrder.has_key(colKey):
col.Order = colOrder[colKey]
@@ -2044,8 +2052,8 @@
def _onGridResize(self, evt):
dabo.ui.callAfter(self._updateColumnWidths)
-
-
+
+
def _updateColumnWidths(self):
"""See if there are any dynamically-sized columns, and resize
them
accordingly.
@@ -2053,7 +2061,7 @@
if not self:
# This can be called in a callAfter(), and perhaps we
are already dead.
return
- dynCols = [col for col in self.Columns
+ dynCols = [col for col in self.Columns
if col.Expand]
if not dynCols:
return
@@ -2072,14 +2080,14 @@
mod -= 1
else:
col.Width += adj
-
+
def autoSizeCol(self, colNum, persist=False):
"""Set the column to the minimum width necessary to display its
data.
Set colNum='all' to auto-size all columns. Set persist=True to
persist the
new width to the user settings table.
- """
+ """
if isinstance(colNum, str):
self.lockDisplay()
self._inAutoSizeLoop = True
@@ -2093,7 +2101,7 @@
# lock the screen
self.lockDisplay()
# We need to account for header caption width, too. Add
- # a row to the data set containing the header captions, and
+ # a row to the data set containing the header captions, and
# then remove the row afterwards.
capRow = {}
for col in self.Columns:
@@ -2107,9 +2115,9 @@
capBuffer += ((2*self.sortIndicatorSize) +
(2*self.sortIndicatorBuffer))
colObj = self.Columns[idx]
autoWidth = self.GetColSize(idx)
-
+
# Account for the width of the header caption:
- cw = dabo.ui.fontMetricFromFont(colObj.Caption,
+ cw = dabo.ui.fontMetricFromFont(colObj.Caption,
colObj.HeaderFont._nativeFont)[0] +
capBuffer
w = max(autoWidth, cw)
w = min(w, maxWidth)
@@ -2124,7 +2132,7 @@
if not self._inAutoSizeLoop:
self.refresh()
- self.unlockDisplay()
+ self.unlockDisplay()
def _paintHeader(self, col=None):
@@ -2158,20 +2166,20 @@
holdBrush = dc.GetBrush()
holdPen = dc.GetPen()
-
+
if bcolor is not None:
dc.SetBrush(wx.Brush(bcolor, wx.SOLID))
dc.SetPen(wx.Pen(None, width=0))
- dc.DrawRectangle(rect[0] - (col != 0 and 1 or
0),
- rect[1],
- rect[2] + (col != 0 and 1 or 0),
+ dc.DrawRectangle(rect[0] - (col != 0 and 1 or
0),
+ rect[1],
+ rect[2] + (col != 0 and 1 or 0),
rect[3])
dc.SetPen(holdPen)
dc.SetBrush(holdBrush)
if self.Columns[col].DataField == self.sortedColumn:
sortIndicator = True
- # draw a triangle, pointed up or down, at the
top left
+ # draw a triangle, pointed up or down, at the
top left
# of the column. TODO: Perhaps replace with
prettier icons
left = rect[0] + self.sortIndicatorBuffer
top = rect[1] + self.sortIndicatorBuffer
@@ -2180,12 +2188,12 @@
dc.SetBrush(wx.Brush(brushColor, wx.SOLID))
if self.sortOrder == "DESC":
# Down arrow
- dc.DrawPolygon([(left, top),
(left+self.sortIndicatorSize, top),
+ dc.DrawPolygon([(left, top),
(left+self.sortIndicatorSize, top),
(left+self.sortIndicatorBuffer, top+self.sortIndicatorSize)])
elif self.sortOrder == "ASC":
# Up arrow
-
dc.DrawPolygon([(left+self.sortIndicatorBuffer, top),
-
(left+self.sortIndicatorSize, top+self.sortIndicatorSize),
+
dc.DrawPolygon([(left+self.sortIndicatorBuffer, top),
+
(left+self.sortIndicatorSize, top+self.sortIndicatorSize),
(left,
top+self.sortIndicatorSize)])
else:
# Column is not sorted, so don't draw.
@@ -2203,16 +2211,16 @@
if av is None:
av = "Center"
- wxah = {"Center": wx.ALIGN_CENTRE_HORIZONTAL,
- "Left": wx.ALIGN_LEFT,
+ wxah = {"Center": wx.ALIGN_CENTRE_HORIZONTAL,
+ "Left": wx.ALIGN_LEFT,
"Right": wx.ALIGN_RIGHT}[ah]
- wxav = {"Center": wx.ALIGN_CENTRE_VERTICAL,
+ wxav = {"Center": wx.ALIGN_CENTRE_VERTICAL,
"Top": wx.ALIGN_TOP,
"Bottom": wx.ALIGN_BOTTOM}[av]
# Give some more space around the rect - some platforms
use a 3d look
- # and anyway it looks better if left/right aligned text
isn't right on
+ # and anyway it looks better if left/right aligned text
isn't right on
# the line.
horBuffer = 3
vertBuffer = 2
@@ -2225,7 +2233,7 @@
trect[1] = trect[1] + vertBuffer
if ah == "Center":
trect[2] = trect[2] - (2*sortBuffer)
- else:
+ else:
trect[2] = trect[2] - (horBuffer+sortBuffer)
trect[3] = trect[3] - (2*vertBuffer)
trect = wx.Rect(*trect)
@@ -2251,8 +2259,8 @@
else:
if col in self.Columns:
self.removeColumn(col)
-
-
+
+
def moveColumn(self, colNum, toNum):
""" Move the column to a new position."""
oldCol = self.Columns[colNum]
@@ -2277,8 +2285,8 @@
if scrollBarFudge:
fudge = 18
self.Width = reduce(operator.add, [col.Width for col in
self.Columns]) + fudge
-
+
def sizeToRows(self, maxHeight=500, scrollBarFudge=True):
"""Set the height of the grid equal to the sum of the heights
of the rows.
@@ -2289,10 +2297,10 @@
if scrollBarFudge:
fudge = 18
self.Height = min(self.RowHeight * self.RowCount, maxHeight) +
fudge
-
+
def o
(32422 bytes were truncated as it was too long for the email (max 40000 bytes.)
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]