John Li wrote:
What language is 'my' language?
What OS are you using; are you using a wxPython version that
supports unicode?
Chinese characters also may be displayed when a high-ascii
character--such as letters with diacritics in French or Swedish,
for example--are used, and the wrong locale/character set is
assumed.
John
I'm sorry, I should have thought of that. I'm running Python 2.3/wxPython
2.4.2.4u on WinXP in English. Yes, I believe I installed w/unicode support.
I should probably also not that so far my testing has been limited to
documents of only 1-4 lines in length (just to see if I really could save
and retrieve) and either no or one carriage-return. I have not even begun to
play with setting font or anything else so all wxTextCtrl and wxFont
attributes are whatever happens when you initialize the control.
Also, I think Jean-Michel was on to something because I have noticed (and it
is consistent) that after I "read in" my saved file, if I try to highlight
or select the text - it all just disappears to an empty control. So it
appears there's nothing tangible actually being brought in.
I know after I save a newly written file to disk I can check it by opening
it with any other word-processor in text/ascii mode and it reads in just
fine. So the wxTextCtrl.SaveFile method seems to be working perfectly fine.
It's just that the wxTextCtrl.LoadFile method doesn't seem able to
(correctly) load back in its own file.
I can't help but feel like I'm missing something real basic because this
seems like it should be such a no-brainer. I'm using two methods from the
same control with no further embellishment on my part. The actual text is
seldom more than just the word "test" or maybe one short sentence.
All suggestions gratefully accepted - this has become something of a
show-stopper for me.
File definitions for "New", "Open", "Close", "Save", "Save As" :
def OnFileNew(self, event):
"""File > New"""
try:
self.pages = self.pages + 1
except:
self.pages = 2 #the calling class creates the notebook with 1
page
#named "new (1)" upon initialization - it can't start
#blank and call "New" due to sequence-of-operation problems.
self.notebook_1_pane_1 = wxPanel(self.pane.notebook_1, -1)
self.text_ctrl = wxTextCtrl(self.notebook_1_pane_1, -1, "",
style=wxTE_MULTILINE|wxTE_RICH)
sizer_2 = wxBoxSizer(wxHORIZONTAL)
sizer_2.Add(self.text_ctrl, 1, wxEXPAND, 0)
self.notebook_1_pane_1.SetAutoLayout(1)
self.notebook_1_pane_1.SetSizer(sizer_2)
sizer_2.Fit(self.notebook_1_pane_1)
sizer_2.SetSizeHints(self.notebook_1_pane_1)
self.title = "new (" + repr(self.pages) + ")"
self.pane.notebook_1.AddPage(self.notebook_1_pane_1, self.title)
CTRL[self.title] = self.text_ctrl
DIR[self.title] = "none"
FILE[self.title] = "none"
def OnFileOpen(self, event):
"""File > Open file(s)"""
defaultDir=os.path.join(PROG['root'],"data")
dlg = wxFileDialog(self.frame, "Choose a file",
defaultDir=defaultDir, defaultFile="",
wildcard="Writer Files(*.wtr)|*.wtr|Text
Files(*.txt;*.asc)|*.txt;*.asc|All files (*.*)|*.*",
style=wxOPEN|wxMULTIPLE)
if dlg.ShowModal() == wxID_OK:
self.page = self.pane.notebook_1.GetSelection()
self.tab = self.pane.notebook_1.GetPageText(self.page)
self.ctrl = CTRL[self.tab]
if self.ctrl.GetLastPosition() == 0:
self.pane.notebook_1.RemovePage(self.page)
fileList = dlg.GetPaths()
for f in fileList:
self.notebook_1_pane_1 = wxPanel(self.pane.notebook_1, -1)
self.text_ctrl = wxTextCtrl(self.notebook_1_pane_1, -1, "",
style=wxTE_MULTILINE|wxTE_RICH)
sizer_2 = wxBoxSizer(wxHORIZONTAL)
sizer_2.Add(self.text_ctrl, 1, wxEXPAND, 0)
self.notebook_1_pane_1.SetAutoLayout(1)
self.notebook_1_pane_1.SetSizer(sizer_2)
sizer_2.Fit(self.notebook_1_pane_1)
sizer_2.SetSizeHints(self.notebook_1_pane_1)
self.name, self.ext = os.path.splitext(FILE[self.tab])
self.pane.notebook_1.AddPage(self.notebook_1_pane_1,
self.name)
CTRL[self.name] = self.text_ctrl
DIR[self.name] = dlg.GetDirectory()
FILE[self.name] = dlg.GetFilename()
self.text_ctrl.LoadFile(f)
dlg.Destroy()
self.pane.notebook_1.Refresh()
def OnFileClose(self,event):
"""File > Close file"""
self.page = self.pane.notebook_1.GetSelection()
self.pane.notebook_1.RemovePage(self.page)
def OnFileSave(self, event):
"""File > Save file"""
self.page = self.pane.notebook_1.GetSelection()
self.tab = self.pane.notebook_1.GetPageText(self.page)
if FILE[self.tab]=="none":
self.OnFileSaveAs(event)
else:
path = os.path.join(DIR[self.tab], FILE[self.tab])
self.ctrl = CTRL[self.tab]
self.ctrl.SaveFile(path)
def OnFileSaveAs(self, event):
"""File > Save file as"""
self.page = self.pane.notebook_1.GetSelection()
self.tab = self.pane.notebook_1.GetPageText(self.page)
self.ctrl = CTRL[self.tab]
defaultDir=os.path.join(PROG['root'],"data")
defaultFile=""
dlg = wxFileDialog(self.frame, "Save As",
defaultDir=defaultDir,defaultFile=defaultFile,
wildcard="Writer Files(*.wtr)|*.wtr|Text Files(*.txt)|*.txt|All
files (*.*)|*.*",
style=wxSAVE|wxOVERWRITE_PROMPT|wxCHANGE_DIR)
if dlg.ShowModal() == wxID_OK:
path = dlg.GetPath()
DIR[self.tab] = dlg.GetDirectory()
FILE[self.tab] = dlg.GetFilename()
self.name, self.ext = os.path.splitext(FILE[self.tab])
self.ctrl.SaveFile(path)
self.pane.notebook_1.SetPageText(self.page, self.name)
dlg.Destroy()
self.pane.notebook_1.Refresh()
···
> -----Original Message-----
> From: Jean-Michel Fauth [mailto:jmfauth@bluewin.ch]
> Sent: 2004 01 18 10:24
> To: wxPython-users@lists.wxwindows.org
> Subject: [wxPython-users] What happened to my language?
>
>
> Rick Zoerner wrote:
>
> > Hi all,
>
> > I save a file from a wxTextCtrl using the SaveFile method.
> Then I close the
> > program.
> > I can view that file in Notepad and it is exactly what I
> typed in the
> > wxTextCtrl. Perfect.
> > Then I re-open the program and load in the file to the
> wxTextCtrl using the
> > LoadFile method.
>
> > Chinese.
>
> > Why? And... how do I stop that?
>
> This is probalbly not real Chinese, but an end of line (eol) issue.
> In Python, the 'official' eol is '\n'. On win platform, the eol
> is '\r\n'.
> The wxTextCtrl does not recognize '\r\n', so when you save you
> text, the text will be saved with '\n' instead of '\r\n' eol marks.
>
> Beside this, I should say, that NotePad is still one of the most
> strupid editor around. It can not change the '\n' on the fly.
>
> How to work around
> - replace in the text all '\n' by '\r\n' before you save it
> - make some more tests with Word, OOo, SciTe, ...
> - replace the NotePad application by one another small
> text editor. The web is full of them.