git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31004
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
self.name = name
self.buffer = ''
def write(self, data):
self.name = name
self.buffer = ''
def write(self, data):
- self.buffer += data.encode()
+ self.buffer += data.encode(g.currentEncoding)
def close(self):
wxMemoryFSHandler_AddFile(self.name, self.buffer)
def close(self):
wxMemoryFSHandler_AddFile(self.name, self.buffer)
try:
f = open(path)
self.Clear()
try:
f = open(path)
self.Clear()
- # Parse first line to get encoding (!! hack, I don't know a better way)
- line = f.readline()
- mo = re.match(r'^<\?xml ([^<>]* )?encoding="(?P<encd>[^<>].*)"\?>', line)
- # Build wx tree
- f.seek(0)
- # Set encoding global variable and document encoding property
- if mo:
- dom.encoding = g.currentEncoding = mo.group('encd')
- if dom.encoding not in ['ascii', sys.getdefaultencoding()]:
- wxLogWarning('Encoding is different from system default')
- else:
- g.currentEncoding = 'ascii'
- dom.encoding = ''
+ # Set encoding global variable
+ g.currentEncoding = dom.encoding
# Change dir
dir = os.path.dirname(path)
if dir: os.chdir(dir)
# Change dir
dir = os.path.dirname(path)
if dir: os.chdir(dir)
def Save(self, path):
try:
def Save(self, path):
try:
# Apply changes
if tree.selection and panel.IsModified():
self.OnRefresh(wxCommandEvent())
# Apply changes
if tree.selection and panel.IsModified():
self.OnRefresh(wxCommandEvent())
+ f = codecs.open(path, 'w', g.currentEncoding)
# Make temporary copy for formatting it
# !!! We can't clone dom node, it works only once
#self.domCopy = tree.dom.cloneNode(True)
self.domCopy = MyDocument()
mainNode = self.domCopy.appendChild(tree.mainNode.cloneNode(True))
self.Indent(mainNode)
# Make temporary copy for formatting it
# !!! We can't clone dom node, it works only once
#self.domCopy = tree.dom.cloneNode(True)
self.domCopy = MyDocument()
mainNode = self.domCopy.appendChild(tree.mainNode.cloneNode(True))
self.Indent(mainNode)
- self.domCopy.writexml(f, encoding=tree.rootObj.params['encoding'].value())
+ self.domCopy.writexml(f, encoding = g.currentEncoding)
f.close()
self.domCopy.unlink()
self.domCopy = None
f.close()
self.domCopy.unlink()
self.domCopy = None
# Simulate normal parameter for encoding
class xxxEncoding:
# Simulate normal parameter for encoding
class xxxEncoding:
- def __init__(self, val):
- self.encd = val
+ return g.currentEncoding
+ g.currentEncoding = val
# Special class for root node
class xxxMainNode(xxxContainer):
# Special class for root node
class xxxMainNode(xxxContainer):
# Reset required parameters after processing XML, because encoding is
# a little special
self.required = ['encoding']
# Reset required parameters after processing XML, because encoding is
# a little special
self.required = ['encoding']
- self.params['encoding'] = xxxEncoding(dom.encoding)
+ self.params['encoding'] = xxxEncoding()
################################################################################
# Top-level windwows
################################################################################
# Top-level windwows