Added Python methods to wxStyledTextCtrl that allow to get/set text in
UTF8 in either unicode or ansi builds git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33678 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a1d2d6b1e8
commit
1ce1bd84ea
@ -2947,7 +2947,9 @@ public:
|
||||
// Append a string to the end of the document without changing the selection.
|
||||
void AppendTextRaw(const char* text);
|
||||
|
||||
|
||||
#ifdef SWIG
|
||||
%pythoncode "_stc_utf8_methods.py"
|
||||
#endif
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -259,6 +259,9 @@ public:
|
||||
void AppendTextRaw(const char* text);
|
||||
|
||||
|
||||
#ifdef SWIG
|
||||
%pythoncode "_stc_utf8_methods.py"
|
||||
#endif
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -2947,7 +2947,9 @@ public:
|
||||
// Append a string to the end of the document without changing the selection.
|
||||
void AppendTextRaw(const char* text);
|
||||
|
||||
|
||||
#ifdef SWIG
|
||||
%pythoncode "_stc_utf8_methods.py"
|
||||
#endif
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@ -259,6 +259,9 @@ public:
|
||||
void AppendTextRaw(const char* text);
|
||||
|
||||
|
||||
#ifdef SWIG
|
||||
%pythoncode "_stc_utf8_methods.py"
|
||||
#endif
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
117
wxPython/contrib/stc/_stc_utf8_methods.py
Normal file
117
wxPython/contrib/stc/_stc_utf8_methods.py
Normal file
@ -0,0 +1,117 @@
|
||||
|
||||
def AddTextUTF8(self, text):
|
||||
"""
|
||||
Add UTF8 encoded text to the document at the current position.
|
||||
Works 'natively' in a unicode build of wxPython, and will also work
|
||||
in an ansi build if the UTF8 text is compatible with the current
|
||||
encoding.
|
||||
"""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.AddTextRaw(text)
|
||||
|
||||
|
||||
def InsertTextUTF8(self, pos, text):
|
||||
"""
|
||||
Insert UTF8 encoded text at a position. Works 'natively' in a
|
||||
unicode build of wxPython, and will also work in an ansi build if
|
||||
the UTF8 text is compatible with the current encoding.
|
||||
"""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.InsertTextRaw(pos, text)
|
||||
|
||||
|
||||
def GetCurLineUTF8(self):
|
||||
"""
|
||||
Retrieve the UTF8 text of the line containing the caret, and also
|
||||
the index of the caret on the line. In an ansi build of wxPython
|
||||
the text retrieved from the document is assumed to be in the
|
||||
current default encoding.
|
||||
"""
|
||||
text, pos = self.GetCurLineRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text, pos
|
||||
|
||||
|
||||
def GetLineUTF8(self, line):
|
||||
"""
|
||||
Retrieve the contents of a line as UTF8. In an ansi build of wxPython
|
||||
the text retrieved from the document is assumed to be in the
|
||||
current default encoding.
|
||||
"""
|
||||
text = self.GetLineRaw(line)
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def GetSelectedTextUTF8(self):
|
||||
"""
|
||||
Retrieve the selected text as UTF8. In an ansi build of wxPython
|
||||
the text retrieved from the document is assumed to be in the
|
||||
current default encoding.
|
||||
"""
|
||||
text = self.GetSelectedTextRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def GetTextRangeUTF8(self, startPos, endPos):
|
||||
"""
|
||||
Retrieve a range of text as UTF8. In an ansi build of wxPython
|
||||
the text retrieved from the document is assumed to be in the
|
||||
current default encoding.
|
||||
"""
|
||||
text = self.GetTextRangeRaw(startPos, endPos)
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def SetTextUTF8(self, text):
|
||||
"""
|
||||
Replace the contents of the document with the UTF8 text given.
|
||||
Works 'natively' in a unicode build of wxPython, and will also
|
||||
work in an ansi build if the UTF8 text is compatible with the
|
||||
current encoding.
|
||||
"""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.SetTextRaw(text)
|
||||
|
||||
|
||||
def GetTextUTF8(self):
|
||||
"""
|
||||
Retrieve all the text in the document as UTF8. In an ansi build
|
||||
of wxPython the text retrieved from the document is assumed to be
|
||||
in the current default encoding.
|
||||
"""
|
||||
text = self.GetTextRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def AppendTextUTF8(self, text):
|
||||
"""
|
||||
Append a UTF8 string to the end of the document without changing
|
||||
the selection. Works 'natively' in a unicode build of wxPython,
|
||||
and will also work in an ansi build if the UTF8 text is compatible
|
||||
with the current encoding.
|
||||
"""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.AppendTextRaw(text)
|
||||
|
@ -2884,6 +2884,90 @@ class StyledTextCtrl(_core.Control):
|
||||
"""AppendTextRaw(self, char text)"""
|
||||
return _stc.StyledTextCtrl_AppendTextRaw(*args, **kwargs)
|
||||
|
||||
# These functions are inserted as methods in to the Python StyleTextCtrl class
|
||||
|
||||
|
||||
|
||||
def AddTextUTF8(self, text):
|
||||
"""Add UTF8 encoded text to the document at the current position."""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.AddTextRaw(text)
|
||||
|
||||
|
||||
def InsertTextUTF8(self, pos, text):
|
||||
"""Insert UTF8 encoded text at a position."""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.InsertTextRaw(pos, text)
|
||||
|
||||
|
||||
def GetCurLineUTF8(self):
|
||||
"""
|
||||
Retrieve the text of the line containing the caret, and also the
|
||||
index of the caret on the line.
|
||||
"""
|
||||
text, pos = self.GetCurLineRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text, pos
|
||||
|
||||
|
||||
def GetLineUTF8(self, line):
|
||||
"""Retrieve the contents of a line."""
|
||||
text = self.GetLineRaw(line)
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def GetSelectedTextUTF8(self):
|
||||
"""Retrieve the selected text."""
|
||||
text = self.GetSelectedTextRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def GetTextRangeUTF8(self, startPos, endPos):
|
||||
"""Retrieve a range of text."""
|
||||
text = self.GetTextRangeRaw(startPos, endPos)
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def SetTextUTF8(self, text):
|
||||
"""Replace the contents of the document with the argument text."""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.SetTextRaw(text)
|
||||
|
||||
|
||||
def GetTextUTF8(self):
|
||||
"""Retrieve all the text in the document."""
|
||||
text = self.GetTextRaw()
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode(wx.GetDefaultPyEncoding())
|
||||
text = u.encode('utf-8')
|
||||
return text
|
||||
|
||||
|
||||
def AppendTextUTF8(self, text):
|
||||
"""Append a string to the end of the document without changing the selection."""
|
||||
if not wx.USE_UNICODE:
|
||||
u = text.decode('utf-8')
|
||||
text = u.encode(wx.GetDefaultPyEncoding())
|
||||
self.AppendTextRaw(text)
|
||||
|
||||
|
||||
|
||||
class StyledTextCtrlPtr(StyledTextCtrl):
|
||||
def __init__(self, this):
|
||||
|
@ -4,9 +4,38 @@ Recent Changes for wxPython
|
||||
2.6.0.0
|
||||
-------
|
||||
|
||||
wxGTK: wx.StaticText can wrap text if the width is set to an explicit
|
||||
value.
|
||||
wxMSW: Fixed wx.TransientPopupWindow (and therefore wx.TipWindow) to
|
||||
auto-dismiss when the mouse is clicked outside of the popup like it is
|
||||
supposed to.
|
||||
|
||||
wxMSW: Fixed bug #1167891 wx.Notebook display problem with wx.NB_MULTILINE.
|
||||
|
||||
wxMSW: Fixed bad cliping of hidden windows inside of wx.StaticBox.
|
||||
|
||||
wxGTK: The configure flags for selecting GTK+ 1.2.x or 2.x has
|
||||
changed slightly. It is now --with-gtk[=VERSION] where VERSION is
|
||||
either '1', '2' or 'any'. The default is '2'.
|
||||
|
||||
wx.stc.StyledTextCtrl: Added the following methods for alternate ways
|
||||
to set and fetch text from the document buffer. They work similarly
|
||||
to the existing methods of the same name, except that they don't go
|
||||
through the same string/unicode <--> wxString conversions. The "Raw"
|
||||
methods will do no conversions at all and in a unicode build of wxPython
|
||||
the strings will be in the utf-8 encoding and in an ansi build no
|
||||
assumption is made about the encoding. The "UTF8" functions will
|
||||
attempt to always get/set utf-8 text, which will always be true in a
|
||||
unicode build, and in an ansi build will also be true as long as the
|
||||
utf-8 used is compatible with the current encoding.
|
||||
|
||||
AddTextRaw AddTextUTF8
|
||||
InsertTextRaw InsertTextUTF8
|
||||
GetCurLineRaw GetCurLineUTF8
|
||||
GetLineRaw GetLineUTF8
|
||||
GetSelectedTextRaw GetSelectedTextUTF8
|
||||
GetTextRangeRaw GetTextRangeUTF8
|
||||
SetTextRaw SetTextUTF8
|
||||
GetTextRaw GetTextUTF8
|
||||
AppendTextRaw AppendTextUTF8
|
||||
|
||||
|
||||
|
||||
|
@ -538,7 +538,9 @@ if BUILD_STC:
|
||||
swig_sources = run_swig(['stc.i'], location, GENDIR, PKGDIR,
|
||||
USE_SWIG, swig_force,
|
||||
swig_args + ['-I'+STC_H, '-I'+location],
|
||||
[opj(STC_H, 'stc.h')] + swig_deps)
|
||||
[opj(STC_H, 'stc.h'),
|
||||
opj(location, "_stc_utf8_methods.py"),
|
||||
] + swig_deps)
|
||||
|
||||
ext = Extension('_stc',
|
||||
swig_sources,
|
||||
|
Loading…
Reference in New Issue
Block a user