dabo Commit
Revision 7021
Date: 2011-12-10 10:48:40 -0800 (Sat, 10 Dec 2011)
Author: Ed
Trac: http://trac.dabodev.com/changeset/7021
Changed:
U trunk/dabo/settings.py
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Added basic copy functionality to grids. By default strings are enclosed in
double quotes, values in the same row are separated by tabs, and rows are
separated by newlines. These are all configurable as settings, though.
Diff:
Modified: trunk/dabo/settings.py
===================================================================
--- trunk/dabo/settings.py 2011-12-10 18:46:02 UTC (rev 7020)
+++ trunk/dabo/settings.py 2011-12-10 18:48:40 UTC (rev 7021)
@@ -230,6 +230,11 @@
dTextBox_NumericBlankToZero = False
+# When we copy values from a grid, we need to define the following values for
the copied text:
+copyValueSeparator = "\t"
+copyStringSeparator= '"'
+copyLineSeparator = "\n"
+
### Settings - end
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2011-12-10 18:46:02 UTC (rev 7020)
+++ trunk/dabo/ui/uiwx/dGrid.py 2011-12-10 18:48:40 UTC (rev 7021)
@@ -3321,17 +3321,60 @@
def copy(self):
- if self.RowCount > 0:
- coln = self.CurrentColumn
- dtyp = self.Columns[coln].DataType
- val = ustr(self.getValue(col=coln))
- if dtyp in (Decimal, float, "decimal", "float", "f"):
- # We need to convert decimal point accordingly
to the locale.
- val = val.replace(".", decimalPoint)
- self.Application.copyToClipboard(val)
- return True
+ valSep = dabo.copyValueSeparator
+ strSep = dabo.copyStringSeparator
+ lnSep = dabo.copyLineSeparator
+ def valEscape(val):
+ if isinstance(val, basestring):
+ # Need to escape tabs and newlines
+ escval = val.replace("\t", "\\t").replace("\n",
"\\n")
+ if strSep:
+ # Also escape the string separator
+ escval = escval.replace(strSep, "\\%s"
% strSep)
+ return "%s%s%s" % (strSep, escval, strSep)
+ else:
+ ret = val.__repr__()
+ if isinstance(val, (Decimal, float)):
+ # We need to convert decimal point
accordingly to the locale.
+ ret = ret.replace(".", decimalPoint)
+ return ret
+ def valuesForRange(rowrange, colrange):
+ allvals = []
+ for row in rowrange:
+ rowvals = []
+ for col in colrange:
+ val = self.getValue(row, col)
+ rowvals.append(valEscape(val))
+ allvals.append(valSep.join(rowvals))
+ return lnSep.join(allvals)
+
+ sel = self.Selection
+ if not sel:
+ return None
+ selmode = self.SelectionMode
+ copied = []
+ txtToCopy = ""
+ if selmode == "Cell":
+ copySections = []
+ for rangeTuple in sel:
+ zrow, zcol = zip(*rangeTuple)
+ rowrange = range(zrow[0], zrow[1] + 1)
+ colrange = range(zcol[0], zcol[1] + 1)
+ copySections.append(valuesForRange(rowrange,
colrange))
+ txtToCopy = lnSep.join(copySections)
+ else:
+ if selmode == "Row":
+ rowrange = sel
+ colrange = range(0, self.ColumnCount)
+ else:
+ rowrange = range(0, self.RowCount)
+ colrange = sel
+ txtToCopy = valuesForRange(rowrange, colrange)
+ self.Application.copyToClipboard(txtToCopy)
+
+
def getBizobj(self):
ds = self.DataSource
if isinstance(ds, dabo.biz.dBizobj):
_______________________________________________
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/[email protected]