Added wxXmlResourceHandler to wxPython and enabled it's virtuals to be
Python Callbacks. Added a sample to the demo to show how to do it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16721 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -166,6 +166,10 @@ displays the details of the event.
|
|||||||
|
|
||||||
Added wxWizard, wxWizardPage, wxWizardPageSimple and wxPyWizardPage.
|
Added wxWizard, wxWizardPage, wxWizardPageSimple and wxPyWizardPage.
|
||||||
|
|
||||||
|
Added wxXmlResourceHandler which allows you to create custom handlers
|
||||||
|
for nonstandard class types in XRC resources. See the demo for an
|
||||||
|
example.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,3 +2,5 @@
|
|||||||
# The global was removed in favor of static accessor functions. This is for
|
# The global was removed in favor of static accessor functions. This is for
|
||||||
# backwards compatibility:
|
# backwards compatibility:
|
||||||
wxTheXmlResource = wxXmlResource_Get()
|
wxTheXmlResource = wxXmlResource_Get()
|
||||||
|
|
||||||
|
wx.wxXmlNodePtr = wxXmlNodePtr
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
%{
|
%{
|
||||||
#include "wxPython.h"
|
#include "wxPython.h"
|
||||||
|
#include "pyistream.h"
|
||||||
|
#include "wx/xrc/xml.h"
|
||||||
#include "wx/xrc/xmlres.h"
|
#include "wx/xrc/xmlres.h"
|
||||||
#include <wx/filesys.h>
|
#include <wx/filesys.h>
|
||||||
#include <wx/fs_mem.h>
|
#include <wx/fs_mem.h>
|
||||||
@@ -31,7 +33,21 @@
|
|||||||
%extern events.i
|
%extern events.i
|
||||||
%extern controls.i
|
%extern controls.i
|
||||||
|
|
||||||
|
%extern streams.i
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
%{
|
||||||
|
// Put some wx default wxChar* values into wxStrings.
|
||||||
|
static const wxString wxPyEmptyString(wxT(""));
|
||||||
|
static const wxString wxPyUTF8String(wxT("UTF-8"));
|
||||||
|
static const wxString wxPyStyleString(wxT("style"));
|
||||||
|
static const wxString wxPySizeString(wxT("size"));
|
||||||
|
static const wxString wxPyPosString(wxT("pos"));
|
||||||
|
static const wxString wxPyBitmapString(wxT("bitmap"));
|
||||||
|
static const wxString wxPyIconString(wxT("icon"));
|
||||||
|
static const wxString wxPyFontString(wxT("font"));
|
||||||
|
%}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
enum wxXmlResourceFlags
|
enum wxXmlResourceFlags
|
||||||
@@ -104,7 +120,10 @@ public:
|
|||||||
// wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
|
// wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
|
||||||
// (xmlres) can create include file that contains initialization code for
|
// (xmlres) can create include file that contains initialization code for
|
||||||
// all controls used within the resource.
|
// all controls used within the resource.
|
||||||
void AddHandler(wxXmlResourceHandler *handler);
|
void AddHandler(wxPyXmlResourceHandler *handler);
|
||||||
|
|
||||||
|
// Add a new handler at the begining of the handler list
|
||||||
|
void InsertHandler(wxPyXmlResourceHandler *handler);
|
||||||
|
|
||||||
// Removes all handlers
|
// Removes all handlers
|
||||||
void ClearHandlers();
|
void ClearHandlers();
|
||||||
@@ -135,7 +154,20 @@ public:
|
|||||||
wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
|
wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
|
||||||
%name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
|
%name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
|
||||||
|
|
||||||
bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
|
// Load a frame's contents from a resource
|
||||||
|
wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
|
||||||
|
%name(LoadOnFrame)bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
|
||||||
|
|
||||||
|
// Load an object from the resource specifying both the resource name and
|
||||||
|
// the classname. This lets you load nonstandard container windows.
|
||||||
|
wxObject *LoadObject(wxWindow *parent, const wxString& name,
|
||||||
|
const wxString& classname);
|
||||||
|
|
||||||
|
// Load an object from the resource specifying both the resource name and
|
||||||
|
// the classname. This form lets you finish the creation of an existing
|
||||||
|
// instance.
|
||||||
|
%name(LoadOnObject)bool LoadObject(wxObject *instance, wxWindow *parent, const wxString& name,
|
||||||
|
const wxString& classname);
|
||||||
|
|
||||||
// Loads bitmap or icon resource from file:
|
// Loads bitmap or icon resource from file:
|
||||||
wxBitmap LoadBitmap(const wxString& name);
|
wxBitmap LoadBitmap(const wxString& name);
|
||||||
@@ -180,9 +212,448 @@ XMLCTRL = XRCCTRL
|
|||||||
"
|
"
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// In order to provide wrappers for wxXmlResourceHandler we need to also
|
||||||
|
// provide the classes for representing and parsing XML.
|
||||||
|
|
||||||
// TODO: Add wxXmlResourceHandler and allow it to be derived from.
|
|
||||||
|
|
||||||
|
// Represents XML node type.
|
||||||
|
enum wxXmlNodeType
|
||||||
|
{
|
||||||
|
// note: values are synchronized with xmlElementType from libxml
|
||||||
|
wxXML_ELEMENT_NODE,
|
||||||
|
wxXML_ATTRIBUTE_NODE,
|
||||||
|
wxXML_TEXT_NODE,
|
||||||
|
wxXML_CDATA_SECTION_NODE,
|
||||||
|
wxXML_ENTITY_REF_NODE,
|
||||||
|
wxXML_ENTITY_NODE,
|
||||||
|
wxXML_PI_NODE,
|
||||||
|
wxXML_COMMENT_NODE,
|
||||||
|
wxXML_DOCUMENT_NODE,
|
||||||
|
wxXML_DOCUMENT_TYPE_NODE,
|
||||||
|
wxXML_DOCUMENT_FRAG_NODE,
|
||||||
|
wxXML_NOTATION_NODE,
|
||||||
|
wxXML_HTML_DOCUMENT_NODE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Represents node property(ies).
|
||||||
|
// Example: in <img src="hello.gif" id="3"/> "src" is property with value
|
||||||
|
// "hello.gif" and "id" is property with value "3".
|
||||||
|
class wxXmlProperty
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxXmlProperty(const wxString& name = wxPyEmptyString,
|
||||||
|
const wxString& value = wxPyEmptyString,
|
||||||
|
wxXmlProperty *next = NULL);
|
||||||
|
|
||||||
|
wxString GetName() const;
|
||||||
|
wxString GetValue() const;
|
||||||
|
wxXmlProperty *GetNext() const;
|
||||||
|
|
||||||
|
void SetName(const wxString& name);
|
||||||
|
void SetValue(const wxString& value);
|
||||||
|
void SetNext(wxXmlProperty *next);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Represents node in XML document. Node has name and may have content
|
||||||
|
// and properties. Most common node types are wxXML_TEXT_NODE (name and props
|
||||||
|
// are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
|
||||||
|
// element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
|
||||||
|
// with content="hi").
|
||||||
|
//
|
||||||
|
// If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load
|
||||||
|
// (default is UTF-8).
|
||||||
|
class wxXmlNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxXmlNode(wxXmlNode *parent = NULL,
|
||||||
|
wxXmlNodeType type = 0,
|
||||||
|
const wxString& name = wxPyEmptyString,
|
||||||
|
const wxString& content = wxPyEmptyString,
|
||||||
|
wxXmlProperty *props = NULL,
|
||||||
|
wxXmlNode *next = NULL);
|
||||||
|
~wxXmlNode();
|
||||||
|
|
||||||
|
|
||||||
|
// user-friendly creation:
|
||||||
|
%name(wxXmlNodeEasy)wxXmlNode(wxXmlNodeType type, const wxString& name,
|
||||||
|
const wxString& content = wxPyEmptyString);
|
||||||
|
|
||||||
|
void AddChild(wxXmlNode *child);
|
||||||
|
void InsertChild(wxXmlNode *child, wxXmlNode *before_node);
|
||||||
|
bool RemoveChild(wxXmlNode *child);
|
||||||
|
void AddProperty(wxXmlProperty *prop);
|
||||||
|
%name(AddPropertyName)void AddProperty(const wxString& name, const wxString& value);
|
||||||
|
bool DeleteProperty(const wxString& name);
|
||||||
|
|
||||||
|
// access methods:
|
||||||
|
wxXmlNodeType GetType() const;
|
||||||
|
wxString GetName() const;
|
||||||
|
wxString GetContent() const;
|
||||||
|
|
||||||
|
wxXmlNode *GetParent() const;
|
||||||
|
wxXmlNode *GetNext() const;
|
||||||
|
wxXmlNode *GetChildren() const;
|
||||||
|
|
||||||
|
wxXmlProperty *GetProperties() const;
|
||||||
|
wxString GetPropVal(const wxString& propName,
|
||||||
|
const wxString& defaultVal) const;
|
||||||
|
bool HasProp(const wxString& propName) const;
|
||||||
|
|
||||||
|
void SetType(wxXmlNodeType type);
|
||||||
|
void SetName(const wxString& name);
|
||||||
|
void SetContent(const wxString& con);
|
||||||
|
|
||||||
|
void SetParent(wxXmlNode *parent);
|
||||||
|
void SetNext(wxXmlNode *next);
|
||||||
|
void SetChildren(wxXmlNode *child);
|
||||||
|
|
||||||
|
void SetProperties(wxXmlProperty *prop);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// This class holds XML data/document as parsed by XML parser.
|
||||||
|
class wxXmlDocument : public wxObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxXmlDocument(const wxString& filename,
|
||||||
|
const wxString& encoding = wxPyUTF8String);
|
||||||
|
%name(wxXmlDocumentFromStream)wxXmlDocument(wxInputStream& stream,
|
||||||
|
const wxString& encoding = wxPyUTF8String);
|
||||||
|
%name(wxEmptyXmlDocument)wxXmlDocument();
|
||||||
|
|
||||||
|
~wxXmlDocument();
|
||||||
|
|
||||||
|
|
||||||
|
// Parses .xml file and loads data. Returns TRUE on success, FALSE
|
||||||
|
// otherwise.
|
||||||
|
bool Load(const wxString& filename,
|
||||||
|
const wxString& encoding = wxPyUTF8String);
|
||||||
|
%name(LoadFromStream)bool Load(wxInputStream& stream,
|
||||||
|
const wxString& encoding = wxPyUTF8String);
|
||||||
|
|
||||||
|
// Saves document as .xml file.
|
||||||
|
bool Save(const wxString& filename) const;
|
||||||
|
%name(SaveToStream)bool Save(wxOutputStream& stream) const;
|
||||||
|
|
||||||
|
bool IsOk() const;
|
||||||
|
|
||||||
|
// Returns root node of the document.
|
||||||
|
wxXmlNode *GetRoot() const;
|
||||||
|
|
||||||
|
// Returns version of document (may be empty).
|
||||||
|
wxString GetVersion() const;
|
||||||
|
|
||||||
|
// Returns encoding of document (may be empty).
|
||||||
|
// Note: this is the encoding original file was saved in, *not* the
|
||||||
|
// encoding of in-memory representation!
|
||||||
|
wxString GetFileEncoding() const;
|
||||||
|
|
||||||
|
// Write-access methods:
|
||||||
|
void SetRoot(wxXmlNode *node);
|
||||||
|
void SetVersion(const wxString& version);
|
||||||
|
void SetFileEncoding(const wxString& encoding);
|
||||||
|
|
||||||
|
%addmethods {
|
||||||
|
// Returns encoding of in-memory representation of the document (same
|
||||||
|
// as passed to Load or ctor, defaults to UTF-8). NB: this is
|
||||||
|
// meaningless in Unicode build where data are stored as wchar_t*
|
||||||
|
wxString GetEncoding() {
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
return wxPyEmptyString;
|
||||||
|
#else
|
||||||
|
return self->GetEncoding();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// And now for wxXmlResourceHandler...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%{ // C++ version of Python aware wxXmlResourceHandler, for the pure virtual
|
||||||
|
// callbacks, as well as to make some protected things public so they can
|
||||||
|
// be wrapped.
|
||||||
|
class wxPyXmlResourceHandler : public wxXmlResourceHandler {
|
||||||
|
public:
|
||||||
|
wxPyXmlResourceHandler() : wxXmlResourceHandler() {}
|
||||||
|
//~wxPyXmlResourceHandler();
|
||||||
|
|
||||||
|
// Base class virtuals
|
||||||
|
|
||||||
|
DEC_PYCALLBACK_OBJECT__pure(DoCreateResource);
|
||||||
|
DEC_PYCALLBACK_BOOL_NODE_pure(CanHandle);
|
||||||
|
|
||||||
|
// wxObject* DoCreateResource() {
|
||||||
|
// wxObject* rv = NULL;
|
||||||
|
// wxPyBeginBlockThreads();
|
||||||
|
// if (wxPyCBH_findCallback(m_myInst, "DoCreateResource")) {
|
||||||
|
// PyObject* ro;
|
||||||
|
// ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()"));
|
||||||
|
// if (ro) {
|
||||||
|
// SWIG_GetPtrObj(ro, (void **)&rv, "_wxObject_p");
|
||||||
|
// Py_DECREF(ro);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// wxPyEndBlockThreads();
|
||||||
|
// return rv;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// bool CanHandle(wxXmlNode* a) {
|
||||||
|
// bool rv=FALSE;
|
||||||
|
// wxPyBeginBlockThreads();
|
||||||
|
// if (wxPyCBH_findCallback(m_myInst, "CanHandle")) {
|
||||||
|
// PyObject* obj = wxPyConstructObject((void*)a, "wxXmlNode", 0);
|
||||||
|
// rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj));
|
||||||
|
// Py_DECREF(obj);
|
||||||
|
// }
|
||||||
|
// wxPyEndBlockThreads();
|
||||||
|
// return rv;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// accessors for protected members
|
||||||
|
|
||||||
|
wxXmlResource* GetResource() { return m_resource; }
|
||||||
|
wxXmlNode* GetNode() { return m_node; }
|
||||||
|
wxString GetClass() { return m_class; }
|
||||||
|
wxObject* GetParent() { return m_parent; }
|
||||||
|
wxObject* GetInstance() { return m_instance; }
|
||||||
|
wxWindow* GetParentAsWindow() { return m_parentAsWindow; }
|
||||||
|
wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; }
|
||||||
|
|
||||||
|
|
||||||
|
// turn some protected methods into public via delegation
|
||||||
|
|
||||||
|
bool IsOfClass(wxXmlNode *node, const wxString& classname)
|
||||||
|
{ return wxXmlResourceHandler::IsOfClass(node, classname); }
|
||||||
|
|
||||||
|
wxString GetNodeContent(wxXmlNode *node)
|
||||||
|
{ return wxXmlResourceHandler::GetNodeContent(node); }
|
||||||
|
|
||||||
|
bool HasParam(const wxString& param)
|
||||||
|
{ return wxXmlResourceHandler::HasParam(param); }
|
||||||
|
|
||||||
|
wxXmlNode *GetParamNode(const wxString& param)
|
||||||
|
{ return wxXmlResourceHandler::GetParamNode(param); }
|
||||||
|
|
||||||
|
wxString GetParamValue(const wxString& param)
|
||||||
|
{ return wxXmlResourceHandler::GetParamValue(param); }
|
||||||
|
|
||||||
|
void AddStyle(const wxString& name, int value)
|
||||||
|
{ wxXmlResourceHandler::AddStyle(name, value); }
|
||||||
|
|
||||||
|
void AddWindowStyles()
|
||||||
|
{ wxXmlResourceHandler::AddWindowStyles(); }
|
||||||
|
|
||||||
|
int GetStyle(const wxString& param = wxT("style"), int defaults = 0)
|
||||||
|
{ return wxXmlResourceHandler::GetStyle(param, defaults); }
|
||||||
|
|
||||||
|
wxString GetText(const wxString& param, bool translate = TRUE)
|
||||||
|
{ return wxXmlResourceHandler::GetText(param, translate); }
|
||||||
|
|
||||||
|
int GetID()
|
||||||
|
{ return wxXmlResourceHandler::GetID(); }
|
||||||
|
|
||||||
|
wxString GetName()
|
||||||
|
{ return wxXmlResourceHandler::GetName(); }
|
||||||
|
|
||||||
|
bool GetBool(const wxString& param, bool defaultv = FALSE)
|
||||||
|
{ return wxXmlResourceHandler::GetBool(param, defaultv); }
|
||||||
|
|
||||||
|
long GetLong( const wxString& param, long defaultv = 0 )
|
||||||
|
{ return wxXmlResourceHandler::GetLong(param, defaultv); }
|
||||||
|
|
||||||
|
wxColour GetColour(const wxString& param)
|
||||||
|
{ return wxXmlResourceHandler::GetColour(param); }
|
||||||
|
|
||||||
|
wxSize GetSize(const wxString& param = wxT("size"))
|
||||||
|
{ return wxXmlResourceHandler::GetSize(param); }
|
||||||
|
|
||||||
|
wxPoint GetPosition(const wxString& param = wxT("pos"))
|
||||||
|
{ return wxXmlResourceHandler::GetPosition(param); }
|
||||||
|
|
||||||
|
wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0)
|
||||||
|
{ return wxXmlResourceHandler::GetDimension(param, defaultv); }
|
||||||
|
|
||||||
|
wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
|
||||||
|
const wxArtClient& defaultArtClient = wxART_OTHER,
|
||||||
|
wxSize size = wxDefaultSize)
|
||||||
|
{ return wxXmlResourceHandler::GetBitmap(param, defaultArtClient, size); }
|
||||||
|
|
||||||
|
wxIcon GetIcon(const wxString& param = wxT("icon"),
|
||||||
|
const wxArtClient& defaultArtClient = wxART_OTHER,
|
||||||
|
wxSize size = wxDefaultSize)
|
||||||
|
{ return wxXmlResourceHandler::GetIcon(param, defaultArtClient, size); }
|
||||||
|
|
||||||
|
wxFont GetFont(const wxString& param = wxT("font"))
|
||||||
|
{ return wxXmlResourceHandler::GetFont(param); }
|
||||||
|
|
||||||
|
void SetupWindow(wxWindow *wnd)
|
||||||
|
{ wxXmlResourceHandler::SetupWindow(wnd); }
|
||||||
|
|
||||||
|
void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE)
|
||||||
|
{ wxXmlResourceHandler::CreateChildren(parent, this_hnd_only); }
|
||||||
|
|
||||||
|
void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL)
|
||||||
|
{ wxXmlResourceHandler::CreateChildrenPrivately(parent, rootnode); }
|
||||||
|
|
||||||
|
wxObject *CreateResFromNode(wxXmlNode *node,
|
||||||
|
wxObject *parent, wxObject *instance = NULL)
|
||||||
|
{ return wxXmlResourceHandler::CreateResFromNode(node, parent, instance); }
|
||||||
|
|
||||||
|
wxFileSystem& GetCurFileSystem()
|
||||||
|
{ return wxXmlResourceHandler::GetCurFileSystem(); }
|
||||||
|
|
||||||
|
|
||||||
|
PYPRIVATE;
|
||||||
|
};
|
||||||
|
|
||||||
|
IMP_PYCALLBACK_OBJECT__pure(wxPyXmlResourceHandler, wxXmlResourceHandler, DoCreateResource);
|
||||||
|
IMP_PYCALLBACK_BOOL_NODE_pure(wxPyXmlResourceHandler, wxXmlResourceHandler, CanHandle);
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Now the version that will be SWIGged.
|
||||||
|
|
||||||
|
|
||||||
|
%name(wxXmlResourceHandler) class wxPyXmlResourceHandler : public wxObject {
|
||||||
|
public:
|
||||||
|
wxPyXmlResourceHandler() : wxXmlResourceHandler() {}
|
||||||
|
//~wxPyXmlResourceHandler();
|
||||||
|
|
||||||
|
void _setCallbackInfo(PyObject* self, PyObject* _class);
|
||||||
|
%pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxXmlResourceHandler)"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Creates an object (menu, dialog, control, ...) from an XML node.
|
||||||
|
// Should check for validity.
|
||||||
|
// parent is a higher-level object (usually window, dialog or panel)
|
||||||
|
// that is often neccessary to create the resource.
|
||||||
|
// If instance is non-NULL it should not create a new instance via 'new' but
|
||||||
|
// should rather use this one, and call its Create method.
|
||||||
|
wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
|
||||||
|
wxObject *instance);
|
||||||
|
|
||||||
|
// Sets the parent resource.
|
||||||
|
void SetParentResource(wxXmlResource *res);
|
||||||
|
|
||||||
|
|
||||||
|
wxXmlResource* GetResource() { return m_resource; }
|
||||||
|
wxXmlNode* GetNode() { return m_node; }
|
||||||
|
wxString GetClass() { return m_class; }
|
||||||
|
wxObject* GetParent() { return m_parent; }
|
||||||
|
wxObject* GetInstance() { return m_instance; }
|
||||||
|
wxWindow* GetParentAsWindow() { return m_parentAsWindow; }
|
||||||
|
wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; }
|
||||||
|
|
||||||
|
|
||||||
|
// Returns true if the node has a property class equal to classname,
|
||||||
|
// e.g. <object class="wxDialog">.
|
||||||
|
bool IsOfClass(wxXmlNode *node, const wxString& classname);
|
||||||
|
|
||||||
|
// Gets node content from wxXML_ENTITY_NODE
|
||||||
|
// The problem is, <tag>content<tag> is represented as
|
||||||
|
// wxXML_ENTITY_NODE name="tag", content=""
|
||||||
|
// |-- wxXML_TEXT_NODE or
|
||||||
|
// wxXML_CDATA_SECTION_NODE name="" content="content"
|
||||||
|
wxString GetNodeContent(wxXmlNode *node);
|
||||||
|
|
||||||
|
// Check to see if a parameter exists.
|
||||||
|
bool HasParam(const wxString& param);
|
||||||
|
|
||||||
|
// Finds the node or returns NULL.
|
||||||
|
wxXmlNode *GetParamNode(const wxString& param);
|
||||||
|
|
||||||
|
// Finds the parameter value or returns the empty string.
|
||||||
|
wxString GetParamValue(const wxString& param);
|
||||||
|
|
||||||
|
// Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags
|
||||||
|
// understood by this handler.
|
||||||
|
void AddStyle(const wxString& name, int value);
|
||||||
|
|
||||||
|
// Add styles common to all wxWindow-derived classes.
|
||||||
|
void AddWindowStyles();
|
||||||
|
|
||||||
|
// Gets style flags from text in form "flag | flag2| flag3 |..."
|
||||||
|
// Only understads flags added with AddStyle
|
||||||
|
int GetStyle(const wxString& param = wxPyStyleString, int defaults = 0);
|
||||||
|
|
||||||
|
// Gets text from param and does some conversions:
|
||||||
|
// - replaces \n, \r, \t by respective chars (according to C syntax)
|
||||||
|
// - replaces _ by & and __ by _ (needed for _File => &File because of XML)
|
||||||
|
// - calls wxGetTranslations (unless disabled in wxXmlResource)
|
||||||
|
wxString GetText(const wxString& param, bool translate = TRUE);
|
||||||
|
|
||||||
|
// Returns the XRCID.
|
||||||
|
int GetID();
|
||||||
|
|
||||||
|
// Returns the resource name.
|
||||||
|
wxString GetName();
|
||||||
|
|
||||||
|
// Gets a bool flag (1, t, yes, on, true are TRUE, everything else is FALSE).
|
||||||
|
bool GetBool(const wxString& param, bool defaultv = FALSE);
|
||||||
|
|
||||||
|
// Gets the integer value from the parameter.
|
||||||
|
long GetLong( const wxString& param, long defaultv = 0 );
|
||||||
|
|
||||||
|
// Gets colour in HTML syntax (#RRGGBB).
|
||||||
|
wxColour GetColour(const wxString& param);
|
||||||
|
|
||||||
|
// Gets the size (may be in dialog units).
|
||||||
|
wxSize GetSize(const wxString& param = wxPySizeString);
|
||||||
|
|
||||||
|
// Gets the position (may be in dialog units).
|
||||||
|
wxPoint GetPosition(const wxString& param = wxPyPosString);
|
||||||
|
|
||||||
|
// Gets a dimension (may be in dialog units).
|
||||||
|
wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0);
|
||||||
|
|
||||||
|
// Gets a bitmap.
|
||||||
|
wxBitmap GetBitmap(const wxString& param = wxPyBitmapString,
|
||||||
|
const wxArtClient& defaultArtClient = wxART_OTHER,
|
||||||
|
wxSize size = wxDefaultSize);
|
||||||
|
|
||||||
|
// Gets an icon.
|
||||||
|
wxIcon GetIcon(const wxString& param = wxPyIconString,
|
||||||
|
const wxArtClient& defaultArtClient = wxART_OTHER,
|
||||||
|
wxSize size = wxDefaultSize);
|
||||||
|
|
||||||
|
// Gets a font.
|
||||||
|
wxFont GetFont(const wxString& param = wxPyFontString);
|
||||||
|
|
||||||
|
// Sets common window options.
|
||||||
|
void SetupWindow(wxWindow *wnd);
|
||||||
|
|
||||||
|
// Creates children.
|
||||||
|
void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE);
|
||||||
|
|
||||||
|
// Helper function.
|
||||||
|
void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL);
|
||||||
|
|
||||||
|
// Creates a resource from a node.
|
||||||
|
wxObject *CreateResFromNode(wxXmlNode *node,
|
||||||
|
wxObject *parent, wxObject *instance = NULL);
|
||||||
|
|
||||||
|
// helper
|
||||||
|
wxFileSystem& GetCurFileSystem();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
%init %{
|
%init %{
|
||||||
|
@@ -71,6 +71,9 @@ class wxXmlResourcePtr(wxObjectPtr):
|
|||||||
def AddHandler(self, *_args, **_kwargs):
|
def AddHandler(self, *_args, **_kwargs):
|
||||||
val = apply(xrcc.wxXmlResource_AddHandler,(self,) + _args, _kwargs)
|
val = apply(xrcc.wxXmlResource_AddHandler,(self,) + _args, _kwargs)
|
||||||
return val
|
return val
|
||||||
|
def InsertHandler(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResource_InsertHandler,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
def ClearHandlers(self, *_args, **_kwargs):
|
def ClearHandlers(self, *_args, **_kwargs):
|
||||||
val = apply(xrcc.wxXmlResource_ClearHandlers,(self,) + _args, _kwargs)
|
val = apply(xrcc.wxXmlResource_ClearHandlers,(self,) + _args, _kwargs)
|
||||||
return val
|
return val
|
||||||
@@ -103,6 +106,15 @@ class wxXmlResourcePtr(wxObjectPtr):
|
|||||||
def LoadFrame(self, *_args, **_kwargs):
|
def LoadFrame(self, *_args, **_kwargs):
|
||||||
val = apply(xrcc.wxXmlResource_LoadFrame,(self,) + _args, _kwargs)
|
val = apply(xrcc.wxXmlResource_LoadFrame,(self,) + _args, _kwargs)
|
||||||
return val
|
return val
|
||||||
|
def LoadOnFrame(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResource_LoadOnFrame,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def LoadObject(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResource_LoadObject,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def LoadOnObject(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResource_LoadOnObject,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
def LoadBitmap(self, *_args, **_kwargs):
|
def LoadBitmap(self, *_args, **_kwargs):
|
||||||
val = apply(xrcc.wxXmlResource_LoadBitmap,(self,) + _args, _kwargs)
|
val = apply(xrcc.wxXmlResource_LoadBitmap,(self,) + _args, _kwargs)
|
||||||
if val: val = wxBitmapPtr(val) ; val.thisown = 1
|
if val: val = wxBitmapPtr(val) ; val.thisown = 1
|
||||||
@@ -137,6 +149,324 @@ def wxEmptyXmlResource(*_args,**_kwargs):
|
|||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
class wxXmlPropertyPtr :
|
||||||
|
def __init__(self,this):
|
||||||
|
self.this = this
|
||||||
|
self.thisown = 0
|
||||||
|
def GetName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_GetName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetValue(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_GetValue,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetNext(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_GetNext,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlPropertyPtr(val)
|
||||||
|
return val
|
||||||
|
def SetName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_SetName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetValue(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_SetValue,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetNext(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlProperty_SetNext,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def __repr__(self):
|
||||||
|
return "<C wxXmlProperty instance at %s>" % (self.this,)
|
||||||
|
class wxXmlProperty(wxXmlPropertyPtr):
|
||||||
|
def __init__(self,*_args,**_kwargs):
|
||||||
|
self.this = apply(xrcc.new_wxXmlProperty,_args,_kwargs)
|
||||||
|
self.thisown = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class wxXmlNodePtr :
|
||||||
|
def __init__(self,this):
|
||||||
|
self.this = this
|
||||||
|
self.thisown = 0
|
||||||
|
def __del__(self,xrcc=xrcc):
|
||||||
|
if self.thisown == 1 :
|
||||||
|
xrcc.delete_wxXmlNode(self)
|
||||||
|
def AddChild(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_AddChild,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def InsertChild(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_InsertChild,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def RemoveChild(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_RemoveChild,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def AddProperty(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_AddProperty,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def AddPropertyName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_AddPropertyName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def DeleteProperty(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_DeleteProperty,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetType(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetType,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetContent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetContent,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetParent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetParent,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetNext(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetNext,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetChildren(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetChildren,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetProperties(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetProperties,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlPropertyPtr(val)
|
||||||
|
return val
|
||||||
|
def GetPropVal(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_GetPropVal,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def HasProp(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_HasProp,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetType(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetType,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetContent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetContent,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetParent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetParent,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetNext(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetNext,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetChildren(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetChildren,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetProperties(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlNode_SetProperties,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def __repr__(self):
|
||||||
|
return "<C wxXmlNode instance at %s>" % (self.this,)
|
||||||
|
class wxXmlNode(wxXmlNodePtr):
|
||||||
|
def __init__(self,*_args,**_kwargs):
|
||||||
|
self.this = apply(xrcc.new_wxXmlNode,_args,_kwargs)
|
||||||
|
self.thisown = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def wxXmlNodeEasy(*_args,**_kwargs):
|
||||||
|
val = wxXmlNodePtr(apply(xrcc.new_wxXmlNodeEasy,_args,_kwargs))
|
||||||
|
val.thisown = 1
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
class wxXmlDocumentPtr(wxObjectPtr):
|
||||||
|
def __init__(self,this):
|
||||||
|
self.this = this
|
||||||
|
self.thisown = 0
|
||||||
|
def __del__(self,xrcc=xrcc):
|
||||||
|
if self.thisown == 1 :
|
||||||
|
xrcc.delete_wxXmlDocument(self)
|
||||||
|
def Load(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_Load,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def LoadFromStream(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_LoadFromStream,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def Save(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_Save,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SaveToStream(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_SaveToStream,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def IsOk(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_IsOk,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetRoot(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_GetRoot,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetVersion(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_GetVersion,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetFileEncoding(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_GetFileEncoding,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetRoot(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_SetRoot,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetVersion(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_SetVersion,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetFileEncoding(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_SetFileEncoding,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetEncoding(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlDocument_GetEncoding,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def __repr__(self):
|
||||||
|
return "<C wxXmlDocument instance at %s>" % (self.this,)
|
||||||
|
class wxXmlDocument(wxXmlDocumentPtr):
|
||||||
|
def __init__(self,*_args,**_kwargs):
|
||||||
|
self.this = apply(xrcc.new_wxXmlDocument,_args,_kwargs)
|
||||||
|
self.thisown = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def wxXmlDocumentFromStream(*_args,**_kwargs):
|
||||||
|
val = wxXmlDocumentPtr(apply(xrcc.new_wxXmlDocumentFromStream,_args,_kwargs))
|
||||||
|
val.thisown = 1
|
||||||
|
return val
|
||||||
|
|
||||||
|
def wxEmptyXmlDocument(*_args,**_kwargs):
|
||||||
|
val = wxXmlDocumentPtr(apply(xrcc.new_wxEmptyXmlDocument,_args,_kwargs))
|
||||||
|
val.thisown = 1
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
class wxXmlResourceHandlerPtr(wxObjectPtr):
|
||||||
|
def __init__(self,this):
|
||||||
|
self.this = this
|
||||||
|
self.thisown = 0
|
||||||
|
def _setCallbackInfo(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler__setCallbackInfo,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def CreateResource(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_CreateResource,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def SetParentResource(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_SetParentResource,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetResource(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetResource,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlResourcePtr(val)
|
||||||
|
return val
|
||||||
|
def GetNode(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetNode,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetClass(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetClass,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetParent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetParent,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetInstance(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetInstance,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetParentAsWindow(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetParentAsWindow,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetInstanceAsWindow(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetInstanceAsWindow,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def IsOfClass(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_IsOfClass,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetNodeContent(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetNodeContent,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def HasParam(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_HasParam,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetParamNode(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetParamNode,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxXmlNodePtr(val)
|
||||||
|
return val
|
||||||
|
def GetParamValue(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetParamValue,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def AddStyle(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_AddStyle,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def AddWindowStyles(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_AddWindowStyles,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetStyle(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetStyle,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetText(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetText,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetID(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetID,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetName(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetName,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetBool(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetBool,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetLong(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetLong,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetColour(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetColour,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxColourPtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def GetSize(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetSize,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxSizePtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def GetPosition(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetPosition,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxPointPtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def GetDimension(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetDimension,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetBitmap(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetBitmap,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxBitmapPtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def GetIcon(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetIcon,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxIconPtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def GetFont(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetFont,(self,) + _args, _kwargs)
|
||||||
|
if val: val = wxFontPtr(val) ; val.thisown = 1
|
||||||
|
return val
|
||||||
|
def SetupWindow(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_SetupWindow,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def CreateChildren(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_CreateChildren,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def CreateChildrenPrivately(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_CreateChildrenPrivately,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def CreateResFromNode(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_CreateResFromNode,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def GetCurFileSystem(self, *_args, **_kwargs):
|
||||||
|
val = apply(xrcc.wxXmlResourceHandler_GetCurFileSystem,(self,) + _args, _kwargs)
|
||||||
|
return val
|
||||||
|
def __repr__(self):
|
||||||
|
return "<C wxXmlResourceHandler instance at %s>" % (self.this,)
|
||||||
|
class wxXmlResourceHandler(wxXmlResourceHandlerPtr):
|
||||||
|
def __init__(self,*_args,**_kwargs):
|
||||||
|
self.this = apply(xrcc.new_wxXmlResourceHandler,_args,_kwargs)
|
||||||
|
self.thisown = 1
|
||||||
|
self._setCallbackInfo(self, wxXmlResourceHandler)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-------------- FUNCTION WRAPPERS ------------------
|
#-------------- FUNCTION WRAPPERS ------------------
|
||||||
@@ -159,6 +489,19 @@ def wxXmlResource_Set(*_args, **_kwargs):
|
|||||||
|
|
||||||
wxXRC_USE_LOCALE = xrcc.wxXRC_USE_LOCALE
|
wxXRC_USE_LOCALE = xrcc.wxXRC_USE_LOCALE
|
||||||
wxXRC_NO_SUBCLASSING = xrcc.wxXRC_NO_SUBCLASSING
|
wxXRC_NO_SUBCLASSING = xrcc.wxXRC_NO_SUBCLASSING
|
||||||
|
wxXML_ELEMENT_NODE = xrcc.wxXML_ELEMENT_NODE
|
||||||
|
wxXML_ATTRIBUTE_NODE = xrcc.wxXML_ATTRIBUTE_NODE
|
||||||
|
wxXML_TEXT_NODE = xrcc.wxXML_TEXT_NODE
|
||||||
|
wxXML_CDATA_SECTION_NODE = xrcc.wxXML_CDATA_SECTION_NODE
|
||||||
|
wxXML_ENTITY_REF_NODE = xrcc.wxXML_ENTITY_REF_NODE
|
||||||
|
wxXML_ENTITY_NODE = xrcc.wxXML_ENTITY_NODE
|
||||||
|
wxXML_PI_NODE = xrcc.wxXML_PI_NODE
|
||||||
|
wxXML_COMMENT_NODE = xrcc.wxXML_COMMENT_NODE
|
||||||
|
wxXML_DOCUMENT_NODE = xrcc.wxXML_DOCUMENT_NODE
|
||||||
|
wxXML_DOCUMENT_TYPE_NODE = xrcc.wxXML_DOCUMENT_TYPE_NODE
|
||||||
|
wxXML_DOCUMENT_FRAG_NODE = xrcc.wxXML_DOCUMENT_FRAG_NODE
|
||||||
|
wxXML_NOTATION_NODE = xrcc.wxXML_NOTATION_NODE
|
||||||
|
wxXML_HTML_DOCUMENT_NODE = xrcc.wxXML_HTML_DOCUMENT_NODE
|
||||||
|
|
||||||
|
|
||||||
#-------------- USER INCLUDE -----------------------
|
#-------------- USER INCLUDE -----------------------
|
||||||
@@ -167,3 +510,5 @@ wxXRC_NO_SUBCLASSING = xrcc.wxXRC_NO_SUBCLASSING
|
|||||||
# The global was removed in favor of static accessor functions. This is for
|
# The global was removed in favor of static accessor functions. This is for
|
||||||
# backwards compatibility:
|
# backwards compatibility:
|
||||||
wxTheXmlResource = wxXmlResource_Get()
|
wxTheXmlResource = wxXmlResource_Get()
|
||||||
|
|
||||||
|
wx.wxXmlNodePtr = wxXmlNodePtr
|
||||||
|
@@ -36,6 +36,7 @@ _treeList = [
|
|||||||
'wxIEHtmlWin',
|
'wxIEHtmlWin',
|
||||||
'wxKeyEvents',
|
'wxKeyEvents',
|
||||||
'wxWizard',
|
'wxWizard',
|
||||||
|
'wxXmlResourceHandler',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# managed windows == things with a caption you can close
|
# managed windows == things with a caption you can close
|
||||||
@@ -138,7 +139,8 @@ _treeList = [
|
|||||||
'ScrolledPanel',
|
'ScrolledPanel',
|
||||||
'Sizers',
|
'Sizers',
|
||||||
'wxLayoutConstraints',
|
'wxLayoutConstraints',
|
||||||
'XML_Resource',
|
'wxXmlResource',
|
||||||
|
'wxXmlResourceHandler',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# ditto
|
# ditto
|
||||||
|
182
wxPython/demo/wxXmlResourceHandler.py
Normal file
182
wxPython/demo/wxXmlResourceHandler.py
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
|
||||||
|
from wxPython.wx import *
|
||||||
|
from wxPython.xrc import *
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
resourceText = r'''<?xml version="1.0"?>
|
||||||
|
<resource>
|
||||||
|
|
||||||
|
<!-- Notice that the class is NOT a standard wx class -->
|
||||||
|
|
||||||
|
<object class="MyBluePanel" name="MyPanel">
|
||||||
|
<size>200,100</size>
|
||||||
|
<object class="wxStaticText" name="lable1">
|
||||||
|
<label>This blue panel is a class derived from wxPanel,\nand is loaded by a custom wxXmlResourceHandler.</label>
|
||||||
|
<pos>10,10</pos>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
</resource>
|
||||||
|
'''
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MyBluePanel(wxPanel):
|
||||||
|
def __init__(self, parent, id, pos, size, style, name):
|
||||||
|
wxPanel.__init__(self, parent, id, pos, size, style, name)
|
||||||
|
|
||||||
|
# This is the little bit of customization that we do for this
|
||||||
|
# silly example. It could just as easily have been done in
|
||||||
|
# the resource.
|
||||||
|
self.SetBackgroundColour("BLUE")
|
||||||
|
|
||||||
|
|
||||||
|
# To do it the more complex way, (see below) we need to write the
|
||||||
|
# class a little differently... This could obviously be done with a
|
||||||
|
# single class, but I wanted to make separate ones to make clear what
|
||||||
|
# the different requirements are.
|
||||||
|
class PreMyBluePanel(wxPanel):
|
||||||
|
def __init__(self):
|
||||||
|
p = wxPrePanel()
|
||||||
|
self.this = p.this
|
||||||
|
|
||||||
|
def Create(self, parent, id, pos, size, style, name):
|
||||||
|
wxPanel.Create(self, parent, id, pos, size, style, name)
|
||||||
|
self.SetBackgroundColour("BLUE")
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MyBluePanelXmlHandler(wxXmlResourceHandler):
|
||||||
|
def __init__(self):
|
||||||
|
wxXmlResourceHandler.__init__(self)
|
||||||
|
# Specify the styles recognized by objects of this type
|
||||||
|
self.AddStyle("wxNO_3D", wxNO_3D);
|
||||||
|
self.AddStyle("wxTAB_TRAVERSAL", wxTAB_TRAVERSAL);
|
||||||
|
self.AddStyle("wxWS_EX_VALIDATE_RECURSIVELY", wxWS_EX_VALIDATE_RECURSIVELY);
|
||||||
|
self.AddStyle("wxCLIP_CHILDREN", wxCLIP_CHILDREN);
|
||||||
|
self.AddWindowStyles();
|
||||||
|
|
||||||
|
# This method and the next one are required for XmlResourceHandlers
|
||||||
|
def CanHandle(self, node):
|
||||||
|
return self.IsOfClass(node, "MyBluePanel")
|
||||||
|
|
||||||
|
def DoCreateResource(self):
|
||||||
|
# NOTE: wxWindows can be created in either a single-phase or
|
||||||
|
# in a two-phase way. Single phase is what you normally do,
|
||||||
|
# and two-phase creates the instnace first, and then later
|
||||||
|
# creates the actual window when the Create method is called.
|
||||||
|
# (In wxPython the first phase is done using the wxPre*
|
||||||
|
# function, for example, wxPreFrame, wxPrePanel, etc.)
|
||||||
|
#
|
||||||
|
# wxXmlResource supports either method, a premade instance can
|
||||||
|
# be created and populated by xrc using the appropriate
|
||||||
|
# LoadOn* method (such as LoadOnPanel) or xrc can create the
|
||||||
|
# instance too, using the Load* method. However this makes
|
||||||
|
# the handlers a bit more complex. If you can be sure that a
|
||||||
|
# particular class will never be loaded using a pre-existing
|
||||||
|
# instance, then you can make the handle much simpler. I'll
|
||||||
|
# show both methods below.
|
||||||
|
|
||||||
|
if 0:
|
||||||
|
# The simple method assumes that there is no existing
|
||||||
|
# instance. Be sure of that with an assert.
|
||||||
|
assert self.GetInstance() is None
|
||||||
|
|
||||||
|
# Now create the object
|
||||||
|
panel = MyBluePanel(self.GetParentAsWindow(),
|
||||||
|
self.GetID(),
|
||||||
|
self.GetPosition(),
|
||||||
|
self.GetSize(),
|
||||||
|
self.GetStyle("style", wxTAB_TRAVERSAL),
|
||||||
|
self.GetName()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# When using the more complex (but more flexible) method
|
||||||
|
# the instance may already have been created, check for it
|
||||||
|
panel = self.GetInstance()
|
||||||
|
if panel is None:
|
||||||
|
# if not, then create the instance (but not the window)
|
||||||
|
panel = PreMyBluePanel()
|
||||||
|
|
||||||
|
# Now call the panel's Create method to actually create the window
|
||||||
|
panel.Create(self.GetParentAsWindow(),
|
||||||
|
self.GetID(),
|
||||||
|
self.GetPosition(),
|
||||||
|
self.GetSize(),
|
||||||
|
self.GetStyle("style", wxTAB_TRAVERSAL),
|
||||||
|
self.GetName()
|
||||||
|
)
|
||||||
|
|
||||||
|
# These two things should be done in either case:
|
||||||
|
# Set standard window attributes
|
||||||
|
self.SetupWindow(panel)
|
||||||
|
# Create any child windows of this node
|
||||||
|
self.CreateChildren(panel)
|
||||||
|
|
||||||
|
return panel
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
class TestPanel(wxPanel):
|
||||||
|
def __init__(self, parent, log):
|
||||||
|
self.log = log
|
||||||
|
wxPanel.__init__(self, parent, -1)
|
||||||
|
|
||||||
|
# make the components
|
||||||
|
label = wxStaticText(self, -1, "The lower panel was built from this XML:")
|
||||||
|
label.SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD))
|
||||||
|
|
||||||
|
text = wxTextCtrl(self, -1, resourceText,
|
||||||
|
style=wxTE_READONLY|wxTE_MULTILINE)
|
||||||
|
text.SetInsertionPoint(0)
|
||||||
|
|
||||||
|
line = wxStaticLine(self, -1)
|
||||||
|
|
||||||
|
# Load the resource
|
||||||
|
res = wxEmptyXmlResource()
|
||||||
|
res.InsertHandler(MyBluePanelXmlHandler())
|
||||||
|
res.LoadFromString(resourceText)
|
||||||
|
|
||||||
|
# Now create a panel from the resource data
|
||||||
|
panel = res.LoadObject(self, "MyPanel", "MyBluePanel")
|
||||||
|
|
||||||
|
# and do the layout
|
||||||
|
sizer = wxBoxSizer(wxVERTICAL)
|
||||||
|
sizer.Add(label, 0, wxEXPAND|wxTOP|wxLEFT, 5)
|
||||||
|
sizer.Add(text, 1, wxEXPAND|wxALL, 5)
|
||||||
|
sizer.Add(line, 0, wxEXPAND)
|
||||||
|
sizer.Add(panel, 1, wxEXPAND|wxALL, 5)
|
||||||
|
|
||||||
|
self.SetSizer(sizer)
|
||||||
|
self.SetAutoLayout(true)
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
def runTest(frame, nb, log):
|
||||||
|
win = TestPanel(nb, log)
|
||||||
|
return win
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
overview = """<html><body>
|
||||||
|
<h2><center>wxXmlResourceHandler</center></h2>
|
||||||
|
|
||||||
|
Deriving a class from wxXmlResourceHandler allows you to specify your
|
||||||
|
own classes in XRC resources, and your handler class will then be used
|
||||||
|
to create instances of that class when the resource is loaded.
|
||||||
|
|
||||||
|
</body></html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys,os
|
||||||
|
import run
|
||||||
|
run.main(['', os.path.basename(sys.argv[0])])
|
||||||
|
|
@@ -1620,6 +1620,25 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define DEC_PYCALLBACK_bool_anypure(CBNAME, Type) \
|
||||||
|
bool CBNAME(Type& a);
|
||||||
|
|
||||||
|
|
||||||
|
#define IMP_PYCALLBACK_bool_anypure(CLASS, PCLASS, CBNAME, Type) \
|
||||||
|
bool CLASS::CBNAME(Type& a) { \
|
||||||
|
bool rv=FALSE; \
|
||||||
|
wxPyBeginBlockThreads(); \
|
||||||
|
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
|
||||||
|
PyObject* obj = wxPyConstructObject((void*)&a, #Type, 0); \
|
||||||
|
rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
|
||||||
|
Py_DECREF(obj); \
|
||||||
|
} \
|
||||||
|
wxPyEndBlockThreads(); \
|
||||||
|
return rv; \
|
||||||
|
} \
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
#define DEC_PYCALLBACK_STRING_LONGLONG(CBNAME) \
|
#define DEC_PYCALLBACK_STRING_LONGLONG(CBNAME) \
|
||||||
wxString CBNAME(long a, long b) const; \
|
wxString CBNAME(long a, long b) const; \
|
||||||
wxString base_##CBNAME(long a, long b)const ;
|
wxString base_##CBNAME(long a, long b)const ;
|
||||||
@@ -1746,9 +1765,8 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
|
|||||||
#define IMP_PYCALLBACK_WIZPG__pure(CLASS, PCLASS, CBNAME) \
|
#define IMP_PYCALLBACK_WIZPG__pure(CLASS, PCLASS, CBNAME) \
|
||||||
wxWizardPage* CLASS::CBNAME() const { \
|
wxWizardPage* CLASS::CBNAME() const { \
|
||||||
wxWizardPage* rv = NULL; \
|
wxWizardPage* rv = NULL; \
|
||||||
bool found; \
|
|
||||||
wxPyBeginBlockThreads(); \
|
wxPyBeginBlockThreads(); \
|
||||||
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
|
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
|
||||||
PyObject* ro; \
|
PyObject* ro; \
|
||||||
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
|
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
|
||||||
if (ro) { \
|
if (ro) { \
|
||||||
@@ -1768,9 +1786,8 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
|
|||||||
#define IMP_PYCALLBACK_BITMAP__pure(CLASS, PCLASS, CBNAME) \
|
#define IMP_PYCALLBACK_BITMAP__pure(CLASS, PCLASS, CBNAME) \
|
||||||
wxBitmap CLASS::CBNAME() const { \
|
wxBitmap CLASS::CBNAME() const { \
|
||||||
wxBitmap rv; \
|
wxBitmap rv; \
|
||||||
bool found; \
|
|
||||||
wxPyBeginBlockThreads(); \
|
wxPyBeginBlockThreads(); \
|
||||||
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
|
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
|
||||||
PyObject* ro; \
|
PyObject* ro; \
|
||||||
wxBitmap* ptr; \
|
wxBitmap* ptr; \
|
||||||
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
|
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
|
||||||
@@ -1786,4 +1803,43 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define DEC_PYCALLBACK_OBJECT__pure(CBNAME) \
|
||||||
|
wxObject* CBNAME();
|
||||||
|
|
||||||
|
#define IMP_PYCALLBACK_OBJECT__pure(CLASS, PCLASS, CBNAME) \
|
||||||
|
wxObject* CLASS::CBNAME() { \
|
||||||
|
wxObject* rv = NULL; \
|
||||||
|
wxPyBeginBlockThreads(); \
|
||||||
|
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
|
||||||
|
PyObject* ro; \
|
||||||
|
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
|
||||||
|
if (ro) { \
|
||||||
|
SWIG_GetPtrObj(ro, (void **)&rv, "_wxObject_p"); \
|
||||||
|
Py_DECREF(ro); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
wxPyEndBlockThreads(); \
|
||||||
|
return rv; \
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define DEC_PYCALLBACK_BOOL_NODE_pure(CBNAME) \
|
||||||
|
bool CBNAME(wxXmlNode* a);
|
||||||
|
|
||||||
|
|
||||||
|
#define IMP_PYCALLBACK_BOOL_NODE_pure(CLASS, PCLASS, CBNAME) \
|
||||||
|
bool CLASS::CBNAME(wxXmlNode* a) { \
|
||||||
|
bool rv=FALSE; \
|
||||||
|
wxPyBeginBlockThreads(); \
|
||||||
|
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
|
||||||
|
PyObject* obj = wxPyConstructObject((void*)a, "wxXmlNode", 0); \
|
||||||
|
rv = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(O)", obj)); \
|
||||||
|
Py_DECREF(obj); \
|
||||||
|
} \
|
||||||
|
wxPyEndBlockThreads(); \
|
||||||
|
return rv; \
|
||||||
|
} \
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user