This is the main class for interacting with the XML-based resource system.
The class holds XML
resources from one or more .xml files, binary files or zip archive files.
Note that this is a singleton class and you’ll never allocate/deallocate it. Just use the static wx.xrc.XmlResource.Get
getter.
See also
XML Based Resource System , XRC File Format
Constructor. |
|
Initializes only a specific handler (or custom handler). |
|
Registers subclasses factory for use in |
|
Attaches an unknown control to the given panel/window/dialog. |
|
Removes all handlers and deletes them (this means that any handlers added using |
|
Compares the |
|
Returns a string |
|
Gets the global resources object or creates one if none exists. |
|
Returns the domain (message catalog) that will be used to load translatable strings in the |
|
Returns flags, which may be a bitlist of wx.xrc.XmlResourceFlags enumeration values. |
|
Returns the wx.xml.XmlNode containing the definition of the object with the given name or |
|
Returns version information (a.b.c.d = d + 256c + 2562b + 2563a). |
|
Returns a numeric |
|
Initializes handlers for all supported controls/windows. |
|
Add a new handler at the beginning of the handler list. |
|
Loads resources from |
|
Loads all .xrc files from directory dirname. |
|
Loads a bitmap resource from a file. |
|
Loads a dialog. |
|
Load resources from the |
|
Simpler form of |
|
Loads a frame from the resource. |
|
Load the resource from a bytes string or other data buffer compatible object. |
|
Loads an icon resource from a file. |
|
Loads menu from resource. |
|
Loads a menubar from resource. |
|
Load an object from the resource specifying both the resource name and the class name. |
|
Load an object from anywhere in the resource tree. |
|
Loads a panel. |
|
Loads a toolbar. |
|
Sets the global resources object and returns a pointer to the previous one (may be |
|
Sets the domain (message catalog) that will be used to load translatable strings in the |
|
Sets flags (bitlist of wx.xrc.XmlResourceFlags enumeration values). |
|
This function unloads a resource previously loaded by |
See |
wx.xrc.
XmlResource
(Object)¶Possible constructors:
XmlResource(filemask, flags=XRC_USE_LOCALE, domain="")
XmlResource(flags=XRC_USE_LOCALE, domain="")
This is the main class for interacting with the XML-based resource system.
__init__
(self, *args, **kw)¶__init__ (self, filemask, flags=XRC_USE_LOCALE, domain=””)
Constructor.
filemask (string) – The XRC
file, archive file, or wildcard specification that will be used to load all resource files inside a zip archive.
flags (int) – One or more value of the wx.xrc.XmlResourceFlags enumeration.
domain (string) – The name of the gettext catalog to search for translatable strings. By default all loaded catalogs will be searched. This provides a way to allow the strings to only come from a specific catalog.
__init__ (self, flags=XRC_USE_LOCALE, domain=””)
Constructor.
flags (int) – One or more value of the wx.xrc.XmlResourceFlags enumeration.
domain (string) – The name of the gettext catalog to search for translatable strings. By default all loaded catalogs will be searched. This provides a way to allow the strings to only come from a specific catalog.
AddHandler
(self, handler)¶Initializes only a specific handler (or custom handler).
Convention says that the handler name is equal to the control’s name plus ‘XmlHandler’, for example TextCtrlXmlHandler, HtmlWindowXmlHandler.
The XML
resource compiler (wxxrc) can create include file that contains initialization code for all controls used within the resource. Note that this handler must be allocated on the heap, since it will be deleted by ClearHandlers
later.
handler (wx.xrc.XmlResourceHandler) –
AddSubclassFactory
(factory)¶Registers subclasses factory for use in XRC
.
This is useful only for language bindings developers who need a way to implement subclassing in wxWidgets ports that don’t support RTTI
(e.g. wxPython).
factory (wx.xrc.XmlSubclassFactory) –
AttachUnknownControl
(self, name, control, parent=None)¶Attaches an unknown control to the given panel/window/dialog.
Unknown controls are used in conjunction with <object class=”unknown”>.
ClearHandlers
(self)¶Removes all handlers and deletes them (this means that any handlers added using AddHandler
must be allocated on the heap).
CompareVersion
(self, major, minor, release, revision)¶Compares the XRC
version to the argument.
Returns -1 if the XRC
version is less than the argument, +1 if greater, and 0 if they are equal.
major (int) –
minor (int) –
release (int) –
revision (int) –
int
FindXRCIDById
(numId)¶Returns a string ID
corresponding to the given numeric ID
.
The string returned is such that calling GetXRCID
with it as parameter yields numId. If there is no string identifier corresponding to the given numeric one, an empty string is returned.
Notice that, unlike GetXRCID
, this function is slow as it checks all of the identifiers used in XRC
.
numId (int) –
string
New in version 2.9.0.
Get
()¶Gets the global resources object or creates one if none exists.
GetDomain
(self)¶Returns the domain (message catalog) that will be used to load translatable strings in the XRC
.
string
GetFlags
(self)¶Returns flags, which may be a bitlist of wx.xrc.XmlResourceFlags enumeration values.
int
GetResourceNode
(self, name)¶Returns the wx.xml.XmlNode containing the definition of the object with the given name or None
.
This function recursively searches all the loaded XRC
files for an object with the specified name. If the object is found, the wx.xml.XmlNode corresponding to it is returned, so this function can be used to access additional information defined in the XRC
file and not used by wx.xrc.XmlResource itself, e.g. contents of application-specific XML
tags.
name (string) – The name of the resource which must be unique for this function to work correctly, if there is more than one resource with the given name the choice of the one returned by this function is undefined.
The node corresponding to the resource with the given name or None
.
GetVersion
(self)¶Returns version information (a.b.c.d = d + 256c + 2562b + 2563a).
long
GetXRCID
(str_id, value_if_not_found=ID_NONE)¶Returns a numeric ID
that is equivalent to the string ID
used in an XML
resource.
If an unknown str_id is requested (i.e. other than ID_XXX
or integer), a new record is created which associates the given string with a number.
If value_if_not_found is ID_NONE
, the number is obtained via wx.NewId
. Otherwise value_if_not_found is used.
Macro XRCID(name)
is provided for convenient use in event tables.
str_id (string) –
value_if_not_found (int) –
int
Note
IDs returned by XRCID() cannot be used with the EVT_*_RANGE
macros, because the order in which they are assigned to symbolic name values is not guaranteed.
InitAllHandlers
(self)¶Initializes handlers for all supported controls/windows.
This will make the executable quite big because it forces linking against most of the wxWidgets library.
InsertHandler
(self, handler)¶Add a new handler at the beginning of the handler list.
handler (wx.xrc.XmlResourceHandler) –
Load
(self, filemask)¶Loads resources from XML
files that match given filemask.
Example:
if not wx.xml.XmlResource.Get().Load("rc/*.xrc"):
wx.LogError("Couldn't load resources!")
filemask (string) –
bool
Note
If USE_FILESYS
is enabled, this method understands wx.FileSystem URLs (see wx.FileSystem.FindFirst
).
Note
If you are sure that the argument is name of single XRC
file (rather than an URL or a wildcard), use LoadFile
instead.
See also
LoadAllFiles
(self, dirname)¶Loads all .xrc files from directory dirname.
Tries to load as many files as possible; if there’s an error while loading one file, it still attempts to load other files.
dirname (string) –
bool
New in version 2.9.0.
LoadBitmap
(self, name)¶Loads a bitmap resource from a file.
name (string) –
LoadDialog
(self, *args, **kw)¶LoadDialog (self, parent, name)
Loads a dialog.
parent points to parent window (if any).
LoadDialog (self, dlg, parent, name)
Loads a dialog.
parent points to parent window (if any).
This form is used to finish creation of an already existing instance (the main reason for this is that you may want to use derived class with a new event table). Example:
# Without a class
dlg = wx.Dialog()
wx.xml.XmlResource.Get().LoadDialog(dlg, mainFrame, "my_dialog")
dlg.ShowModal()
# Or, as a class
class MyDialog(wx.Dialog):
def __init__(self, parent):
super().__init__()
wx.xml.XmlResource.Get().LoadDialog(self, parent, "my_dialog")
LoadDocument
(self, doc, name="")¶Load resources from the XML
document containing them.
This can be useful when XRC
contents comes from some place other than a file or, more generally, an URL, as it can still be read into a MemoryInputStream and then wx.xml.XmlDocument can be created from this stream and used with this function.
For example:
xrc_data = ... # Retrieve it from wherever.
xmlDoc = wx.xml.XmlDocument(io.BytesIO(xrc_data))
if not xmlDoc.IsOk():
... handle invalid XML here ...
return
if not wx.XmlResource.Get().LoadDocument(xmlDoc):
... handle invalid XRC here ...
return
... use the just loaded XRC as usual ...
doc (wx.xml.XmlDocument) – A valid, i.e. non-null, document pointer ownership of which is passed to wx.xrc.XmlResource, i.e. this pointer can’t be used after this function returns.
name (string) – The name argument is optional, but may be provided if you plan to call Unload
later. It doesn’t need to be an existing file or even conform to the usual form of file names as it is not interpreted in any way by wx.xrc.XmlResource, but it should be unique among the other documents and file names used if specified.
bool
True
on success, False
if the document couldn’t be loaded (note that doc is still destroyed in this case to avoid memory leaks).
New in version 4.1/wxWidgets-3.1.6.
LoadFile
(self, file)¶Simpler form of Load
for loading a single XRC
file.
file (string) –
bool
New in version 2.9.0.
See also
LoadFrame
(self, *args, **kw)¶LoadFrame (self, parent, name)
Loads a frame from the resource.
parent points to parent window (if any).
LoadFrame (self, frame, parent, name)
Loads the contents of a frame onto an existing wx.Frame.
This form is used to finish creation of an already existing instance (the main reason for this is that you may want to use derived class with a new event table).
LoadFromBuffer
(self, data)¶Load the resource from a bytes string or other data buffer compatible object.
bool
LoadIcon
(self, name)¶Loads an icon resource from a file.
name (string) –
LoadMenu
(self, name)¶Loads menu from resource.
Returns None
on failure.
name (string) –
LoadMenuBar
(self, *args, **kw)¶Loads a menubar from resource.
Returns None
on failure.
LoadMenuBar (self, parent, name)
parent (wx.Window) –
name (string) –
LoadMenuBar (self, name)
name (string) –
LoadObject
(self, *args, **kw)¶Load an object from the resource specifying both the resource name and the class name.
The first overload lets you load nonstandard container windows and returns None
on failure. The second one lets you finish the creation of an existing instance and returns False
on failure.
In either case, only the resources defined at the top level of XRC
files can be loaded by this function, use LoadObjectRecursively
if you need to load an object defined deeper in the hierarchy.
LoadObject (self, parent, name, classname)
LoadObject (self, instance, parent, name, classname)
bool
LoadObjectRecursively
(self, *args, **kw)¶Load an object from anywhere in the resource tree.
These methods are similar to LoadObject
but may be used to load an object from anywhere in the resource tree and not only the top level. Note that you will very rarely need to do this as in normal use the entire container window (defined at the top level) is loaded and not its individual children but this method can be useful in some particular situations.
New in version 2.9.1.
LoadObjectRecursively (self, parent, name, classname)
LoadObjectRecursively (self, instance, parent, name, classname)
bool
LoadPanel
(self, *args, **kw)¶LoadPanel (self, parent, name)
Loads a panel.
parent points to the parent window.
LoadPanel (self, panel, parent, name)
Loads a panel.
parent points to the parent window. This form is used to finish creation of an already existing instance.
LoadToolBar
(self, parent, name)¶Loads a toolbar.
parent (wx.Window) –
name (string) –
Set
(res)¶Sets the global resources object and returns a pointer to the previous one (may be None
).
res (wx.xrc.XmlResource) –
SetDomain
(self, domain)¶Sets the domain (message catalog) that will be used to load translatable strings in the XRC
.
domain (string) –
SetFlags
(self, flags)¶Sets flags (bitlist of wx.xrc.XmlResourceFlags enumeration values).
flags (int) –
Unload
(self, filename)¶This function unloads a resource previously loaded by Load
.
Returns True
if the resource was successfully unloaded and False
if it hasn’t been found in the list of loaded resources.
filename (string) –
bool
Version
¶See GetVersion