Richtext updates
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46289 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -176,15 +176,17 @@ class RichTextFrame(wx.Frame):
|
|||||||
|
|
||||||
|
|
||||||
def OnFileOpen(self, evt):
|
def OnFileOpen(self, evt):
|
||||||
# TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
|
# This gives us a string suitable for the file dialog based on
|
||||||
|
# the file handlers that are loaded
|
||||||
|
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=False)
|
||||||
dlg = wx.FileDialog(self, "Choose a filename",
|
dlg = wx.FileDialog(self, "Choose a filename",
|
||||||
wildcard="All files (*.*)|*.*",
|
wildcard=wildcard,
|
||||||
style=wx.OPEN)
|
style=wx.OPEN)
|
||||||
if dlg.ShowModal() == wx.ID_OK:
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
path = dlg.GetPath()
|
path = dlg.GetPath()
|
||||||
if path:
|
if path:
|
||||||
# TODO: use the filter index to determine what file type to use
|
fileType = types[dlg.GetFilterIndex()]
|
||||||
self.rtc.LoadFile(path, rt.RICHTEXT_TYPE_TEXT)
|
self.rtc.LoadFile(path, fileType)
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
|
|
||||||
@@ -194,19 +196,52 @@ class RichTextFrame(wx.Frame):
|
|||||||
return
|
return
|
||||||
self.rtc.SaveFile()
|
self.rtc.SaveFile()
|
||||||
|
|
||||||
|
|
||||||
def OnFileSaveAs(self, evt):
|
def OnFileSaveAs(self, evt):
|
||||||
# TODO: Use RichTextBuffer.GetExtWildcard to get the wildcard string
|
wildcard, types = rt.RichTextBuffer.GetExtWildcard(save=True)
|
||||||
|
|
||||||
dlg = wx.FileDialog(self, "Choose a filename",
|
dlg = wx.FileDialog(self, "Choose a filename",
|
||||||
wildcard="All files (*.*)|*.*",
|
wildcard=wildcard,
|
||||||
style=wx.SAVE)
|
style=wx.SAVE)
|
||||||
if dlg.ShowModal() == wx.ID_OK:
|
if dlg.ShowModal() == wx.ID_OK:
|
||||||
path = dlg.GetPath()
|
path = dlg.GetPath()
|
||||||
if path:
|
if path:
|
||||||
self.rtc.SaveFile(path)
|
fileType = types[dlg.GetFilterIndex()]
|
||||||
|
ext = rt.RichTextBuffer.FindHandlerByType(fileType).GetExtension()
|
||||||
|
if not path.endswith(ext):
|
||||||
|
path += '.' + ext
|
||||||
|
self.rtc.SaveFile(path, fileType)
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
|
|
||||||
def OnFileViewHTML(self, evt): pass
|
def OnFileViewHTML(self, evt):
|
||||||
|
# Get an instance of the html file handler, use it to save the
|
||||||
|
# document to a StringIO stream, and then display the
|
||||||
|
# resulting html text in a dialog with a HtmlWindow.
|
||||||
|
handler = rt.RichTextHTMLHandler()
|
||||||
|
handler.SetFlags(rt.RICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY)
|
||||||
|
handler.SetFontSizeMapping([7,9,11,12,14,22,100])
|
||||||
|
|
||||||
|
import cStringIO
|
||||||
|
stream = cStringIO.StringIO()
|
||||||
|
if not handler.SaveStream(self.rtc.GetBuffer(), stream):
|
||||||
|
return
|
||||||
|
|
||||||
|
import wx.html
|
||||||
|
dlg = wx.Dialog(self, title="HTML", style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
|
||||||
|
html = wx.html.HtmlWindow(dlg, size=(500,400), style=wx.BORDER_SUNKEN)
|
||||||
|
html.SetPage(stream.getvalue())
|
||||||
|
btn = wx.Button(dlg, wx.ID_CANCEL)
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
sizer.Add(html, 1, wx.ALL|wx.EXPAND, 5)
|
||||||
|
sizer.Add(btn, 0, wx.ALL|wx.CENTER, 10)
|
||||||
|
dlg.SetSizer(sizer)
|
||||||
|
sizer.Fit(dlg)
|
||||||
|
|
||||||
|
dlg.ShowModal()
|
||||||
|
|
||||||
|
handler.DeleteTemporaryImages()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def OnFileExit(self, evt):
|
def OnFileExit(self, evt):
|
||||||
@@ -533,6 +568,7 @@ class RichTextFrame(wx.Frame):
|
|||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
class TestPanel(wx.Panel):
|
class TestPanel(wx.Panel):
|
||||||
def __init__(self, parent, log):
|
def __init__(self, parent, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
@@ -541,6 +577,30 @@ class TestPanel(wx.Panel):
|
|||||||
b = wx.Button(self, -1, "Show the RichTextCtrl sample", (50,50))
|
b = wx.Button(self, -1, "Show the RichTextCtrl sample", (50,50))
|
||||||
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
|
||||||
|
|
||||||
|
self.AddRTCHandlers()
|
||||||
|
|
||||||
|
|
||||||
|
def AddRTCHandlers(self):
|
||||||
|
# make sure we haven't already added them.
|
||||||
|
if rt.RichTextBuffer.FindHandlerByType(rt.RICHTEXT_TYPE_HTML) is not None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# This would normally go in your app's OnInit method. I'm
|
||||||
|
# not sure why these file handlers are not loaded by
|
||||||
|
# default by the C++ richtext code, I guess it's so you
|
||||||
|
# can change the name or extension if you wanted...
|
||||||
|
rt.RichTextBuffer.AddHandler(rt.RichTextHTMLHandler())
|
||||||
|
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler())
|
||||||
|
|
||||||
|
# ...like this
|
||||||
|
rt.RichTextBuffer.AddHandler(rt.RichTextXMLHandler(name="Other XML",
|
||||||
|
ext="ox",
|
||||||
|
type=99))
|
||||||
|
|
||||||
|
# This is needed for the view as HTML option since we tell it
|
||||||
|
# to store the images in the memory file system.
|
||||||
|
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
|
||||||
|
|
||||||
|
|
||||||
def OnButton(self, evt):
|
def OnButton(self, evt):
|
||||||
win = RichTextFrame(self, -1, "wx.richtext.RichTextCtrl",
|
win = RichTextFrame(self, -1, "wx.richtext.RichTextCtrl",
|
||||||
@@ -548,10 +608,12 @@ class TestPanel(wx.Panel):
|
|||||||
style = wx.DEFAULT_FRAME_STYLE)
|
style = wx.DEFAULT_FRAME_STYLE)
|
||||||
win.Show(True)
|
win.Show(True)
|
||||||
|
|
||||||
# give easy access to PyShell if it's running
|
# give easy access to the demo's PyShell if it's running
|
||||||
self.rtfrm = win
|
self.rtfrm = win
|
||||||
self.rtc = win.rtc
|
self.rtc = win.rtc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
def runTest(frame, nb, log):
|
def runTest(frame, nb, log):
|
||||||
|
@@ -482,7 +482,12 @@ wxpExtensions.append(ext)
|
|||||||
|
|
||||||
|
|
||||||
swig_sources = run_swig(['richtext.i'], 'src', GENDIR, PKGDIR,
|
swig_sources = run_swig(['richtext.i'], 'src', GENDIR, PKGDIR,
|
||||||
USE_SWIG, swig_force, swig_args, swig_deps)
|
USE_SWIG, swig_force, swig_args,
|
||||||
|
swig_deps + [ 'src/_richtextbuffer.i',
|
||||||
|
'src/_richtextctrl.i',
|
||||||
|
'src/_richtexthtml.i',
|
||||||
|
'src/_richtextxml.i',
|
||||||
|
])
|
||||||
if not MONOLITHIC and findLib('richtext', libdirs):
|
if not MONOLITHIC and findLib('richtext', libdirs):
|
||||||
richLib = makeLibName('richtext')
|
richLib = makeLibName('richtext')
|
||||||
else:
|
else:
|
||||||
|
1968
wxPython/src/_richtextbuffer.i
Normal file
1968
wxPython/src/_richtextbuffer.i
Normal file
File diff suppressed because it is too large
Load Diff
1237
wxPython/src/_richtextctrl.i
Normal file
1237
wxPython/src/_richtextctrl.i
Normal file
File diff suppressed because it is too large
Load Diff
102
wxPython/src/_richtexthtml.i
Normal file
102
wxPython/src/_richtexthtml.i
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: _richtexthtml
|
||||||
|
// Purpose: wxRichTextHTMLHandler
|
||||||
|
//
|
||||||
|
// Author: Robin Dunn
|
||||||
|
//
|
||||||
|
// Created: 18-May-2007
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2007 by Total Control Software
|
||||||
|
// Licence: wxWindows license
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Not a %module
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <wx/richtext/richtexthtml.h>
|
||||||
|
%}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
%newgroup
|
||||||
|
|
||||||
|
MAKE_CONST_WXSTRING2(HtmlName, wxT("HTML"));
|
||||||
|
MAKE_CONST_WXSTRING2(HtmlExt, wxT("html"));
|
||||||
|
|
||||||
|
class wxRichTextHTMLHandler: public wxRichTextFileHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxRichTextHTMLHandler(const wxString& name = wxPyHtmlName,
|
||||||
|
const wxString& ext = wxPyHtmlExt,
|
||||||
|
int type = wxRICHTEXT_TYPE_HTML);
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
virtual bool , CanSave() const,
|
||||||
|
"Can we save using this handler?", "");
|
||||||
|
DocDeclStr(
|
||||||
|
virtual bool , CanLoad() const,
|
||||||
|
"Can we load using this handler?", "");
|
||||||
|
DocDeclStr(
|
||||||
|
virtual bool , CanHandle(const wxString& filename) const,
|
||||||
|
"Can we handle this filename (if using files)? By default, checks the
|
||||||
|
extension.", "");
|
||||||
|
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
void , SetTemporaryImageLocations(const wxArrayString& locations),
|
||||||
|
"Set the list of image locations generated by the last operation", "");
|
||||||
|
DocDeclStr(
|
||||||
|
const wxArrayString& , GetTemporaryImageLocations() const,
|
||||||
|
"Get the list of image locations generated by the last operation", "");
|
||||||
|
%property(TemporaryImageLocations, GetTemporaryImageLocations, SetTemporaryImageLocations);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
void , ClearTemporaryImageLocations(),
|
||||||
|
"Clear the image locations generated by the last operation", "");
|
||||||
|
DocDeclStr(
|
||||||
|
bool , DeleteTemporaryImages(),
|
||||||
|
"Delete the in-memory or temporary files generated by the last operation", "");
|
||||||
|
|
||||||
|
|
||||||
|
// DocDeclStr(
|
||||||
|
// static bool , DeleteTemporaryImages(int flags, const wxArrayString& imageLocations),
|
||||||
|
// "Delete the in-memory or temporary files generated by the last operation. This
|
||||||
|
// is a static function that can be used to delete the saved locations from an
|
||||||
|
// earlier operation, for example after the user has viewed the HTML file.", "");
|
||||||
|
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
static void , SetFileCounter(int counter),
|
||||||
|
"Reset the file counter, in case, for example, the same names are required each
|
||||||
|
time", "");
|
||||||
|
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
void , SetTempDir(const wxString& tempDir),
|
||||||
|
"Set the directory for storing temporary files. If empty, the system temporary
|
||||||
|
directory will be used.", "");
|
||||||
|
DocDeclStr(
|
||||||
|
const wxString& , GetTempDir() const,
|
||||||
|
"Get the directory for storing temporary files. If empty, the system temporary
|
||||||
|
directory will be used.", "");
|
||||||
|
%property(TempDir, GetTempDir, SetTempDir);
|
||||||
|
|
||||||
|
|
||||||
|
DocDeclStr(
|
||||||
|
void , SetFontSizeMapping(const wxArrayInt& fontSizeMapping),
|
||||||
|
"Set mapping from point size to HTML font size. There should be 7 elements, one
|
||||||
|
for each HTML font size, each element specifying the maximum point size for
|
||||||
|
that HTML font size. E.g. 8, 10, 13, 17, 22, 29, 100
|
||||||
|
", "");
|
||||||
|
DocDeclStr(
|
||||||
|
wxArrayInt , GetFontSizeMapping() const,
|
||||||
|
"Get mapping deom point size to HTML font size.", "");
|
||||||
|
%property(FontSizeMapping, GetFontSizeMapping, SetFontSizeMapping);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
67
wxPython/src/_richtextxml.i
Normal file
67
wxPython/src/_richtextxml.i
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: _richtextxml
|
||||||
|
// Purpose: wxRichTextXMLHandler
|
||||||
|
//
|
||||||
|
// Author: Robin Dunn
|
||||||
|
//
|
||||||
|
// Created: 18-May-2007
|
||||||
|
// RCS-ID: $Id$
|
||||||
|
// Copyright: (c) 2007 by Total Control Software
|
||||||
|
// Licence: wxWindows license
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Not a %module
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <wx/richtext/richtextxml.h>
|
||||||
|
%}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
%newgroup
|
||||||
|
|
||||||
|
MAKE_CONST_WXSTRING2(XmlName, wxT("XML"));
|
||||||
|
MAKE_CONST_WXSTRING2(XmlExt, wxT("xml"));
|
||||||
|
|
||||||
|
|
||||||
|
class wxRichTextXMLHandler: public wxRichTextFileHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxRichTextXMLHandler(const wxString& name = wxPyXmlName,
|
||||||
|
const wxString& ext = wxPyXmlExt,
|
||||||
|
int type = wxRICHTEXT_TYPE_XML);
|
||||||
|
|
||||||
|
// #if wxUSE_STREAMS
|
||||||
|
// /// Recursively export an object
|
||||||
|
// bool ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int level);
|
||||||
|
// bool ExportStyleDefinition(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextStyleDefinition* def, int level);
|
||||||
|
|
||||||
|
// /// Recursively import an object
|
||||||
|
// bool ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node);
|
||||||
|
// bool ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node);
|
||||||
|
|
||||||
|
// /// Create style parameters
|
||||||
|
// wxString CreateStyle(const wxTextAttrEx& attr, bool isPara = false);
|
||||||
|
|
||||||
|
// /// Get style parameters
|
||||||
|
// bool GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool isPara = false);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
/// Can we save using this handler?
|
||||||
|
virtual bool CanSave() const { return true; }
|
||||||
|
|
||||||
|
/// Can we load using this handler?
|
||||||
|
virtual bool CanLoad() const { return true; }
|
||||||
|
|
||||||
|
|
||||||
|
// bool HasParam(wxXmlNode* node, const wxString& param);
|
||||||
|
// wxXmlNode *GetParamNode(wxXmlNode* node, const wxString& param);
|
||||||
|
// wxString GetNodeContent(wxXmlNode *node);
|
||||||
|
// wxString GetParamValue(wxXmlNode *node, const wxString& param);
|
||||||
|
// wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user