dabo Commit
Revision 2214
Date: 2006-06-15 09:05:37 -0700 (Thu, 15 Jun 2006)
Author: ed
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/dApp.py
U trunk/dabo/db/dBackend.py
U trunk/dabo/lib/datanav/Form.py
U trunk/dabo/lib/reportWriter.py
U trunk/dabo/lib/xmltodict.py
U trunk/dabo/ui/uiwx/dEditor.py
U trunk/dabo/ui/uiwx/dGrid.py
Log:
Revamped the handling of unicode encoding. There is now an Encoding property
of the dApp object, and all classes that previously defined their own
encoding source now get it from the Application object.
The dApp Encoding defaults to the value in locale.getlocale()[1] if it is
set, and if not, returns 'utf-8'.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/biz/dBizobj.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -1386,14 +1386,18 @@
def _getEncoding(self):
- ret = "utf-8"
+ ret = None
cursor = self._CurrentCursor
if cursor is not None:
ret = cursor.Encoding
+ if ret is None:
+ ret = self.Application.Encoding
return ret
def _setEncoding(self, val):
- self._CurrentCursor.Encoding = val
+ cursor = self._CurrentCursor
+ if cursor is not None:
+ cursor.Encoding = val
def _getFillLinkFromParent(self):
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/dApp.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -39,6 +39,7 @@
"""
import sys
import os
+import locale
import warnings
import glob
import tempfile
@@ -568,6 +569,13 @@
self.uiApp.DrawSizerOutlines = val
+ def _getEncoding(self):
+ ret = locale.getlocale()[1]
+ if ret is None:
+ ret = "utf-8"
+ return ret
+
+
def _getHomeDirectory(self):
try:
hd = self._homeDirectory
@@ -736,6 +744,9 @@
DrawSizerOutlines = property(_getDrawSizerOutlines,
_setDrawSizerOutlines, None,
_("Determines if sizer outlines are drawn on the
ActiveForm. (bool)"))
+ Encoding = property(_getEncoding, None, None,
+ _("Name of encoding to use for unicode (str)") )
+
HomeDirectory = property(_getHomeDirectory, _setHomeDirectory, None,
_("""Specifies the application's home directory.
(string)
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/db/dBackend.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -21,7 +21,7 @@
super(dBackend, self).__init__()
self.dbModuleName = None
self._connection = None
- self._encoding = "utf-8"
+ self._encoding = self.Application.Encoding
def isValidModule(self):
Modified: trunk/dabo/lib/datanav/Form.py
===================================================================
--- trunk/dabo/lib/datanav/Form.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/lib/datanav/Form.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -805,7 +805,7 @@
ep = self.PageFrame.Pages[2]
objects = self._getAllChildObjects(ep)
- rfxml = """<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+ rfxml = """<?xml version="1.0" encoding="utf-8"
standalone="yes"?>
<report>
<title>"""
Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/lib/reportWriter.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -1539,7 +1539,7 @@
def _getXmlHeader(self):
"""Returns the XML header for the rfxml document."""
- header = """<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+ header = """<?xml version="1.0" encoding="utf-8"
standalone="yes"?>
<!--
This is a Dabo report form xml (rfxml) document, describing a
@@ -1639,10 +1639,7 @@
v = self._bands = {}
return v
- Bands = property(_getBands, None, None,
- """Provides runtime access to bands of the currently running
report.""")
-
def _getCanvas(self):
try:
v = self._canvas
@@ -1650,10 +1647,7 @@
v = self._canvas = None
return v
- Canvas = property(_getCanvas, None, None,
- """Returns a reference to the reportlab canvas object.""")
-
def _getCursor(self):
if self.UseTestCursor:
try:
@@ -1678,25 +1672,18 @@
self._cursor = val
self.UseTestCursor = False
- Cursor = property(_getCursor, _setCursor, None,
- """Specifies the data cursor that the report runs against.""")
-
def _getEncoding(self):
try:
v = self._encoding
except AttributeError:
- v = self._encoding = "utf-8"
- #v = self._encoding = sys.getdefaultencoding()
+ v = self._encoding =self.Application.Encoding
return v
def _setEncoding(self, val):
self._encoding = val
- Encoding = property(_getEncoding, _setEncoding, None,
- """Specifies the encoding for unicode strings.""")
-
def _getHomeDirectory(self):
try:
v = self._homeDirectory
@@ -1707,17 +1694,7 @@
def _setHomeDirectory(self, val):
self._homeDirectory = val
- HomeDirectory = property(_getHomeDirectory, _setHomeDirectory, None,
- """Specifies the home directory for the report.
- Resources on disk (image files, etc.) will be looked for
relative to the
- HomeDirectory if specified with relative pathing. The
HomeDirectory should
- be the directory that contains the report form file. If you set
- self.ReportFormFile, HomeDirectory will be set for you
automatically.
- Otherwise, HomeDirectory will be set to
self.Application.HomeDirectory.
- """)
-
-
def _getOutputFile(self):
try:
v = self._outputFile
@@ -1735,10 +1712,7 @@
else:
raise ValueError, "Path '%s' doesn't exist." %
s[0]
- OutputFile = property(_getOutputFile, _setOutputFile, None,
- """Specifies the output PDF file (name or file object).""")
-
def _getRecord(self):
try:
v = self._record
@@ -1752,16 +1726,7 @@
# allow access from the live report object:
self.ReportForm._liveRecord = val
- Record = property(_getRecord, _setRecord, None,
- """Specifies the dictionary that represents the current record.
- The report writer will automatically fill this in during the
running
- of the report. Allows expressions in the report form like:
-
- self.Record['cFirst']
- """)
-
-
def _getRecordNumber(self):
try:
v = self._recordNumber
@@ -1769,10 +1734,7 @@
v = self._recordNumber = None
return v
- RecordNumber = property(_getRecordNumber, None, None,
- """Returns the current record number of Cursor.""")
-
def _getReportForm(self):
try:
v = self._reportForm
@@ -1786,9 +1748,6 @@
self._reportFormXML = None
self._reportFormFile = None
- ReportForm = property(_getReportForm, _setReportForm, None,
- """Specifies the python report form data dictionary.""")
-
def _getReportFormFile(self):
try:
@@ -1829,9 +1788,6 @@
else:
raise ValueError, "Specified file does not exist."
- ReportFormFile = property(_getReportFormFile, _setReportFormFile, None,
- """Specifies the path and filename of the report form spec
file.""")
-
def _getReportFormXML(self):
try:
@@ -1846,10 +1802,7 @@
self._reportForm = self._getFormFromXML(self._reportFormXML)
self._setMemento()
- ReportFormXML = property(_getReportFormXML, _setReportFormXML, None,
- """Specifies the report format xml.""")
-
def _getShowBandOutlines(self):
try:
v = self._showBandOutlines
@@ -1861,12 +1814,6 @@
self._showBandOutlines = bool(val)
- ShowBandOutlines = property(_getShowBandOutlines, _setShowBandOutlines,
None,
- """Specifies whether the report bands are printed with outlines
for
- debugging and informational purposes. In addition to the band,
there is also
- a caption with the band name at the x,y origin point for the
band.""")
-
-
def _getUseTestCursor(self):
try:
v = self._useTestCursor
@@ -1879,8 +1826,58 @@
if val:
self._cursor = None
+ Bands = property(_getBands, None, None,
+ _("Provides runtime access to bands of the currently running
report."))
+
+ Canvas = property(_getCanvas, None, None,
+ _("Returns a reference to the reportlab canvas object."))
+
+ Cursor = property(_getCursor, _setCursor, None,
+ _("Specifies the data cursor that the report runs against."))
+
+ Encoding = property(_getEncoding, _setEncoding, None,
+ _("Specifies the encoding for unicode strings. (str)"))
+
+ HomeDirectory = property(_getHomeDirectory, _setHomeDirectory, None,
+ _("""Specifies the home directory for the report.
+
+ Resources on disk (image files, etc.) will be looked for
relative to the
+ HomeDirectory if specified with relative pathing. The
HomeDirectory should
+ be the directory that contains the report form file. If you set
+ self.ReportFormFile, HomeDirectory will be set for you
automatically.
+ Otherwise, HomeDirectory will be set to
self.Application.HomeDirectory."""))
+
+ OutputFile = property(_getOutputFile, _setOutputFile, None,
+ _("Specifies the output PDF file (name or file object)."))
+
+ Record = property(_getRecord, _setRecord, None,
+ _("""Specifies the dictionary that represents the current
record.
+
+ The report writer will automatically fill this in during the
running
+ of the report. Allows expressions in the report form like:
+
+ self.Record["cFirst"]
+ """))
+
+ RecordNumber = property(_getRecordNumber, None, None,
+ _("Returns the current record number of Cursor."))
+
+ ReportForm = property(_getReportForm, _setReportForm, None,
+ _("Specifies the python report form data dictionary."))
+
+ ReportFormFile = property(_getReportFormFile, _setReportFormFile, None,
+ _("Specifies the path and filename of the report form spec
file.")
+
+ ReportFormXML = property(_getReportFormXML, _setReportFormXML, None,
+ _("Specifies the report format xml."))
+
+ ShowBandOutlines = property(_getShowBandOutlines, _setShowBandOutlines,
None,
+ _("""Specifies whether the report bands are printed with
outlines for
+ debugging and informational purposes. In addition to the band,
there is also
+ a caption with the band name at the x,y origin point for the
band."""))
+
UseTestCursor = property(_getUseTestCursor, _setUseTestCursor, None,
- """Specifies whether the TestCursor in the spec file is
used.""")
+ _("Specifies whether the TestCursor in the spec file is used."))
if __name__ == "__main__":
Modified: trunk/dabo/lib/xmltodict.py
===================================================================
--- trunk/dabo/lib/xmltodict.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/lib/xmltodict.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -7,6 +7,17 @@
import string
from xml.parsers import expat
+# If we're in Dabo, get the default encoding.
+import dabo
+app = dabo.dAppRef
+if app is not None:
+ default_encoding = app.Encoding
+else:
+ enc = locale.getlocale()[1]
+ if enc is None:
+ enc = "utf-8"
+ default_encoding = enc
+
# Python seems to need to compile code with \n linesep:
code_linesep = "\n"
eol = os.linesep
@@ -161,7 +172,7 @@
if not isinstance(val, basestring):
val = str(val)
if not isinstance(val, unicode):
- val = unicode(val, "utf-8")
+ val = unicode(val, default_encoding)
if noQuote:
qt = ''
else:
@@ -260,8 +271,8 @@
if level == 0:
if header is None:
- header = '<?xml version="1.0" encoding="utf-8"
standalone="no"?>%s' \
- % eol
+ header = '<?xml version="1.0" encoding="%s"
standalone="no"?>%s' \
+ % (default_encoding, eol)
ret = header + ret
return ret
Modified: trunk/dabo/ui/uiwx/dEditor.py
===================================================================
--- trunk/dabo/ui/uiwx/dEditor.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/ui/uiwx/dEditor.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -6,6 +6,7 @@
import keyword
import code
import inspect
+import compiler
import wx
import wx.stc as stc
import wx.gizmos as gizmos
@@ -81,7 +82,7 @@
self._bufferedDrawing = True
self._hiliteCharsBeyondLimit = False
self._hiliteLimitColumn = 79
- self._encoding = "utf-8"
+ self._encoding = self.Application.Encoding
self._useAntiAliasing = True
self._codeFolding = True
self._showLineNumbers = True
@@ -267,10 +268,84 @@
return self._bookmarks.keys()
- def getFunctionList(self, sorted=False):
+ def getFunctionList(self):
"""Returns a list of all 'class' and 'def' statements, along
with their starting positions in the text.
"""
+ ret = []
+ def _lister(nd):
+ strNd = str(nd)
+ isClass = strNd.startswith("Class(")
+ isFunc = strNd.startswith("Function(")
+ kidlist = []
+ txt = ""
+ try:
+ kids = nd.getChildren()
+ if isClass or isFunc:
+ txt = "%s %s" % (("class",
"def")[isFunc], kids[isFunc])
+
+ for kid in kids:
+ if isinstance(kid, compiler.ast.Node):
+ kidStuff = _lister(kid)
+ if kidStuff:
+ if isinstance(kidStuff,
list):
+ kidlist +=
kidStuff
+ else:
+
kidlist.append(kidStuff)
+ if txt:
+ return {txt: kidlist}
+ else:
+ return kidlist
+ except: pass
+
+ needPosAdd = False
+ try:
+ prsTxt = compiler.parse(self.GetText())
+ needPosAdd = True
+ except SyntaxError:
+ # The text is not compilable.
+ ret = self._bruteForceFuncList()
+ if needPosAdd:
+ nmKids = []
+ for chNode in prsTxt:
+ chRet = _lister(chNode)
+ if chRet:
+ nmKids += _lister(chNode)
+ # OK, at this point we have a list of class/func names.
Now we have to
+ # convert that to a dict where each element has a 'pos'
property that
+ # contains the offset from top of the file, and a
'children' prop that contains
+ # any nested class/funcs.
+ self._classFuncPos = 0
+ ret = self._addPos(nmKids)
+
+ return ret
+
+
+ def _addPos(self, lst):
+ """Go through each entry, finding where that text occurs in the
text.
+ Then add that to the return list.
+ """
+ ret = []
+ for itm in lst:
+ # Find the pos in the text
+ key = itm.keys()[0]
+ pat = "^\s*%s" % key
+ mtch = re.search(pat,
self.GetText()[self._classFuncPos:], re.S | re.M)
+ pos = mtch.start(0)
+ self._classFuncPos += pos
+ itmDict = {key: {"pos": self._classFuncPos}}
+ kids = itm[key]
+ itmDict[key]["children"] = self._addPos(kids)
+ ret.append(itmDict)
+ return ret
+
+
+ def _bruteForceFuncList(self, sorted=False):
+ """Returns a list of all 'class' and 'def' statements, along
+ with their starting positions in the text. This is used
+ when the source cannot be compiled, and thus the
+ compiler module is not usable.
+ """
it = self._pat.finditer(self.GetText())
ret = [(m.groups()[0], m.start()) for m in it]
if sorted:
@@ -298,6 +373,10 @@
mthds = dct[cls]
mthds.sort()
ret += mthds
+
+ print "BRUTE"
+ print ret
+ print
return ret
@@ -1660,7 +1739,7 @@
_("String used to prefix lines that are commented out
(str)"))
Encoding = property(_getEncoding, _setEncoding, None,
- _("Type of encoding to use. Default='utf-8' (str)"))
+ _("Type of encoding to use. Defaults to the
application's default encoding. (str)"))
FileName = property(_getFileName, None, None,
_("Name of the file being edited (without path info)
(str)"))
Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2006-06-13 19:28:10 UTC (rev 2213)
+++ trunk/dabo/ui/uiwx/dGrid.py 2006-06-15 16:05:37 UTC (rev 2214)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import sys
import datetime
import locale
@@ -29,6 +30,7 @@
_USE_DECIMAL = False
+
class dGridDataTable(wx.grid.PyGridTableBase):
def __init__(self, parent):
super(dGridDataTable, self).__init__()
@@ -1620,7 +1622,10 @@
row = self.CurrentRow
if col is None:
col = self.CurrentColumn
- return self.GetValue(row, col)
+ ret = self.GetValue(row, col)
+ if isinstance(ret, str):
+ ret = ret.decode(self.Encoding)
+ return ret
def setValue(self, row, col, val):
return self.SetValue(row, col, val)
@@ -3322,11 +3327,7 @@
if bo is not None:
ret = bo.Encoding
else:
- try:
- ret = wx.GetDefaultPyEncoding()
- except AttributeError:
- # wx versions < 2.6 don't have the
GetDefaultPyEncoding function
- ret = "utf-8"
+ ret = self.Application.Encoding
return ret
@@ -3976,7 +3977,7 @@
class _dGrid_test(dGrid):
def initProperties(self):
- self.DataSet = [{"name" : "Ed Leafe", "age" : 47, "coder" :
True, "color": "brown"},
+ self.DataSet = [{"name" : "Ed Lfe", "age" : 47, "coder" :
True, "color": "brown"},
{"name" : "Mike Leafe", "age" : 18, "coder" :
False, "color": "purple"},
{"name" : "Dan Leafe", "age" : 13, "coder" :
False, "color": "green"}]
self.Width = 360
@@ -4000,7 +4001,7 @@
col = dColumn(self, Name="Person", Order=20, DataField="name",
DataType="string", Width=200, Caption="Customer
Name",
- Sortable=True, Searchable=True, Editable=False,
Expand=True)
+ Sortable=True, Searchable=True, Editable=True,
Expand=True)
self.addColumn(col)
col.HeaderFontItalic = True
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev