1//--------------------------------------------------------------------------- 2// This file is generated by wxPython's SIP generator. Do not edit by hand. 3// 4// Copyright: (c) 2018 by Total Control Software 5// License: wxWindows License 6 7%Module( name=wx._xrc, 8 keyword_arguments="All", 9 use_argument_names=True, 10 all_raise_py_exception=True, 11 language="C++") 12{ 13 %AutoPyName(remove_leading="wx") 14}; 15 16%Copying 17 Copyright: (c) 2018 by Total Control Software 18 License: wxWindows License 19%End 20 21%DefaultDocstringFormat(name="deindented") 22 23%Extract(id=pycode_xrc, order=5) 24# This file is generated by wxPython's SIP generator. Do not edit by hand. 25# 26# Copyright: (c) 2018 by Total Control Software 27# License: wxWindows License 28 29""" 30The classes in this module enable loading widgets and layout from XML. 31""" 32 33from ._xrc import * 34 35%End 36 37//--------------------------------------------------------------------------- 38 39%ModuleHeaderCode 40#include <wxPython/wxpy_api.h> 41#include <wx/xrc/xmlres.h> 42#include <wx/fs_mem.h> 43#include "wxpybuffer.h" 44%End 45 46%Import _core.sip 47%Import _xml.sip 48 49 50//--------------------------------------------------------------------------- 51 52 // forward declarations 53 class wxAnimation; 54 55 56enum wxXmlResourceFlags 57{ 58 wxXRC_USE_LOCALE, 59 wxXRC_NO_SUBCLASSING, 60 wxXRC_NO_RELOADING 61}; 62 63class wxXmlResource : wxObject 64{ 65 %Docstring 66 XmlResource(filemask, flags=XRC_USE_LOCALE, domain=wx.EmptyString) 67 XmlResource(flags=XRC_USE_LOCALE, domain=wx.EmptyString) 68 69 This is the main class for interacting with the XML-based resource 70 system. 71 %End 72 %TypeHeaderCode 73 #include <wx/xrc/xmlres.h> 74 %End 75 76public: 77 wxXmlResource( 78 const wxString & filemask, 79 int flags = wxXRC_USE_LOCALE, 80 const wxString & domain = wxEmptyString 81 ); 82 %MethodCode 83 Py_BEGIN_ALLOW_THREADS 84 sipCpp = new sipwxXmlResource(*filemask,flags,*domain); 85 sipCpp->InitAllHandlers(); 86 Py_END_ALLOW_THREADS 87 %End 88 89 wxXmlResource( 90 int flags = wxXRC_USE_LOCALE, 91 const wxString & domain = wxEmptyString 92 ); 93 %MethodCode 94 Py_BEGIN_ALLOW_THREADS 95 sipCpp = new sipwxXmlResource(flags,*domain); 96 sipCpp->InitAllHandlers(); 97 Py_END_ALLOW_THREADS 98 %End 99 100 virtual 101 ~wxXmlResource(); 102 103 wxMenuBar * LoadMenuBar( 104 wxWindow * parent, 105 const wxString & name 106 ); 107 %Docstring 108 LoadMenuBar(parent, name) -> MenuBar 109 LoadMenuBar(name) -> MenuBar 110 111 Loads a menubar from resource. 112 %End 113 114 wxMenuBar * LoadMenuBar( 115 const wxString & name 116 ); 117 118 wxObject * LoadObject( 119 wxWindow * parent, 120 const wxString & name, 121 const wxString & classname 122 ); 123 %Docstring 124 LoadObject(parent, name, classname) -> Object 125 LoadObject(instance, parent, name, classname) -> bool 126 127 Load an object from the resource specifying both the resource name and 128 the class name. 129 %End 130 131 bool LoadObject( 132 wxObject * instance, 133 wxWindow * parent, 134 const wxString & name, 135 const wxString & classname 136 ); 137 138 wxObject * LoadObjectRecursively( 139 wxWindow * parent, 140 const wxString & name, 141 const wxString & classname 142 ); 143 %Docstring 144 LoadObjectRecursively(parent, name, classname) -> Object 145 LoadObjectRecursively(instance, parent, name, classname) -> bool 146 147 Load an object from anywhere in the resource tree. 148 %End 149 150 bool LoadObjectRecursively( 151 wxObject * instance, 152 wxWindow * parent, 153 const wxString & name, 154 const wxString & classname 155 ); 156 157 void AddHandler( 158 wxXmlResourceHandler * handler /Transfer/ 159 ); 160 %Docstring 161 AddHandler(handler) 162 163 Initializes only a specific handler (or custom handler). 164 %End 165 166 void InsertHandler( 167 wxXmlResourceHandler * handler /Transfer/ 168 ); 169 %Docstring 170 InsertHandler(handler) 171 172 Add a new handler at the beginning of the handler list. 173 %End 174 175 bool AttachUnknownControl( 176 const wxString & name, 177 wxWindow * control, 178 wxWindow * parent = NULL 179 ); 180 %Docstring 181 AttachUnknownControl(name, control, parent=None) -> bool 182 183 Attaches an unknown control to the given panel/window/dialog. 184 %End 185 186 void ClearHandlers(); 187 %Docstring 188 ClearHandlers() 189 190 Removes all handlers and deletes them (this means that any handlers 191 added using AddHandler() must be allocated on the heap). 192 %End 193 194 int CompareVersion( 195 int major, 196 int minor, 197 int release, 198 int revision 199 ) const; 200 %Docstring 201 CompareVersion(major, minor, release, revision) -> int 202 203 Compares the XRC version to the argument. 204 %End 205 206 const wxString & GetDomain() const; 207 %Docstring 208 GetDomain() -> String 209 210 Returns the domain (message catalog) that will be used to load 211 translatable strings in the XRC. 212 %End 213 214 int GetFlags() const; 215 %Docstring 216 GetFlags() -> int 217 218 Returns flags, which may be a bitlist of wxXmlResourceFlags 219 enumeration values. 220 %End 221 222 const wxXmlNode * GetResourceNode( 223 const wxString & name 224 ) const; 225 %Docstring 226 GetResourceNode(name) -> XmlNode 227 228 Returns the wxXmlNode containing the definition of the object with the 229 given name or NULL. 230 %End 231 232 long GetVersion() const; 233 %Docstring 234 GetVersion() -> long 235 236 Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a). 237 %End 238 239 void InitAllHandlers(); 240 %Docstring 241 InitAllHandlers() 242 243 Initializes handlers for all supported controls/windows. 244 %End 245 246 bool Load( 247 const wxString & filemask 248 ); 249 %Docstring 250 Load(filemask) -> bool 251 252 Loads resources from XML files that match given filemask. 253 %End 254 255 bool LoadFile( 256 const wxFileName & file 257 ); 258 %Docstring 259 LoadFile(file) -> bool 260 261 Simpler form of Load() for loading a single XRC file. 262 %End 263 264 bool LoadAllFiles( 265 const wxString & dirname 266 ); 267 %Docstring 268 LoadAllFiles(dirname) -> bool 269 270 Loads all .xrc files from directory dirname. 271 %End 272 273 wxBitmap LoadBitmap( 274 const wxString & name 275 ); 276 %Docstring 277 LoadBitmap(name) -> Bitmap 278 279 Loads a bitmap resource from a file. 280 %End 281 282 wxDialog * LoadDialog( 283 wxWindow * parent, 284 const wxString & name 285 ); 286 %Docstring 287 LoadDialog(parent, name) -> Dialog 288 LoadDialog(dlg, parent, name) -> bool 289 290 Loads a dialog. 291 %End 292 293 bool LoadDialog( 294 wxDialog * dlg, 295 wxWindow * parent, 296 const wxString & name 297 ); 298 299 wxFrame * LoadFrame( 300 wxWindow * parent, 301 const wxString & name 302 ); 303 %Docstring 304 LoadFrame(parent, name) -> Frame 305 LoadFrame(frame, parent, name) -> bool 306 307 Loads a frame from the resource. 308 %End 309 310 bool LoadFrame( 311 wxFrame * frame, 312 wxWindow * parent, 313 const wxString & name 314 ); 315 316 wxIcon LoadIcon( 317 const wxString & name 318 ); 319 %Docstring 320 LoadIcon(name) -> Icon 321 322 Loads an icon resource from a file. 323 %End 324 325 wxMenu * LoadMenu( 326 const wxString & name 327 ); 328 %Docstring 329 LoadMenu(name) -> Menu 330 331 Loads menu from resource. 332 %End 333 334 wxPanel * LoadPanel( 335 wxWindow * parent, 336 const wxString & name 337 ); 338 %Docstring 339 LoadPanel(parent, name) -> Panel 340 LoadPanel(panel, parent, name) -> bool 341 342 Loads a panel. 343 %End 344 345 bool LoadPanel( 346 wxPanel * panel, 347 wxWindow * parent, 348 const wxString & name 349 ); 350 351 wxToolBar * LoadToolBar( 352 wxWindow * parent, 353 const wxString & name 354 ); 355 %Docstring 356 LoadToolBar(parent, name) -> ToolBar 357 358 Loads a toolbar. 359 %End 360 361 void SetDomain( 362 const wxString & domain 363 ); 364 %Docstring 365 SetDomain(domain) 366 367 Sets the domain (message catalog) that will be used to load 368 translatable strings in the XRC. 369 %End 370 371 void SetFlags( 372 int flags 373 ); 374 %Docstring 375 SetFlags(flags) 376 377 Sets flags (bitlist of wxXmlResourceFlags enumeration values). 378 %End 379 380 bool Unload( 381 const wxString & filename 382 ); 383 %Docstring 384 Unload(filename) -> bool 385 386 This function unloads a resource previously loaded by Load(). 387 %End 388 389 static 390 void AddSubclassFactory( 391 wxXmlSubclassFactory * factory /Transfer/ 392 ); 393 %Docstring 394 AddSubclassFactory(factory) 395 396 Registers subclasses factory for use in XRC. 397 %End 398 399 static 400 wxString FindXRCIDById( 401 int numId 402 ); 403 %Docstring 404 FindXRCIDById(numId) -> String 405 406 Returns a string ID corresponding to the given numeric ID. 407 %End 408 409 static 410 wxXmlResource * Get(); 411 %Docstring 412 Get() -> XmlResource 413 414 Gets the global resources object or creates one if none exists. 415 %End 416 417 static 418 int GetXRCID( 419 const wxString & str_id, 420 int value_if_not_found = wxID_NONE 421 ); 422 %Docstring 423 GetXRCID(str_id, value_if_not_found=ID_NONE) -> int 424 425 Returns a numeric ID that is equivalent to the string ID used in an 426 XML resource. 427 %End 428 429 static 430 wxXmlResource * Set( 431 wxXmlResource * res /Transfer/ 432 ) /TransferBack/; 433 %Docstring 434 Set(res) -> XmlResource 435 436 Sets the global resources object and returns a pointer to the previous 437 one (may be NULL). 438 %End 439 440 private: 441 wxXmlResource(const wxXmlResource&); 442 443 444 public: 445 446 447 bool LoadFromBuffer(wxPyBuffer* data); 448 %Docstring 449 LoadFromBuffer(data) -> bool 450 451 Load the resource from a bytes string or other data buffer compatible 452 object. 453 %End 454 %MethodCode 455 PyErr_Clear(); 456 Py_BEGIN_ALLOW_THREADS 457 sipRes = _wxXmlResource_LoadFromBuffer(sipCpp, data); 458 Py_END_ALLOW_THREADS 459 if (PyErr_Occurred()) sipIsErr = 1; 460 %End 461 %TypeCode 462 bool _wxXmlResource_LoadFromBuffer(wxXmlResource* self, wxPyBuffer* data) 463 { 464 static int s_memFileIdx = 0; 465 466 // Check for memory FS. If not present, load the handler: 467 wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"), 468 wxT("dummy data")); 469 wxFileSystem fsys; 470 wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file")); 471 wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file")); 472 if (f) 473 delete f; 474 else 475 wxFileSystem::AddHandler(new wxMemoryFSHandler); 476 477 // Now put the resource data into the memory FS 478 wxString filename(wxT("XRC_resource/data_string_")); 479 filename << s_memFileIdx; 480 s_memFileIdx += 1; 481 wxMemoryFSHandler::AddFile(filename, data->m_ptr, data->m_len); 482 483 // Load the "file" into the resource object 484 bool retval = self->Load(wxT("memory:") + filename ); 485 return retval; 486 } 487 %End 488 489 public: 490 491 492 %Property(name=Domain, get=GetDomain, set=SetDomain) 493 %Property(name=Flags, get=GetFlags, set=SetFlags) 494 %Property(name=Version, get=GetVersion) 495}; // end of class wxXmlResource 496 497 498%Extract(id=pycode_xrc) 499XmlResource.LoadFromString = wx.deprecated(XmlResource.LoadFromBuffer, 'Use LoadFromBuffer instead') 500 501%End 502 503class wxXmlResourceHandler : wxObject 504{ 505 %Docstring 506 XmlResourceHandler() 507 508 wxSizerXmlHandler is a class for resource handlers capable of creating 509 a wxSizer object from an XML node. 510 %End 511 %TypeHeaderCode 512 #include <wx/xrc/xmlres.h> 513 %End 514 515public: 516 wxXmlResourceHandler(); 517 518 virtual 519 ~wxXmlResourceHandler(); 520 521 wxObject * CreateResource( 522 wxXmlNode * node, 523 wxObject * parent, 524 wxObject * instance 525 ); 526 %Docstring 527 CreateResource(node, parent, instance) -> Object 528 529 Creates an object (menu, dialog, control, ...) from an XML node. 530 %End 531 532 virtual 533 wxObject * DoCreateResource() = 0 /Factory/; 534 %Docstring 535 DoCreateResource() -> Object 536 537 Called from CreateResource after variables were filled. 538 %End 539 540 virtual 541 bool CanHandle( 542 wxXmlNode * node 543 ) = 0; 544 %Docstring 545 CanHandle(node) -> bool 546 547 Returns true if it understands this node and can create a resource 548 from it, false otherwise. 549 %End 550 551 void SetParentResource( 552 wxXmlResource * res 553 ); 554 %Docstring 555 SetParentResource(res) 556 557 Sets the parent resource. 558 %End 559 560 public: 561 562 563 %Property(name=Animation, get=GetAnimation) 564 %Property(name=Bitmap, get=GetBitmap) 565 %Property(name=Class, get=GetClass) 566 %Property(name=CurFileSystem, get=GetCurFileSystem) 567 %Property(name=Font, get=GetFont) 568 %Property(name=ID, get=GetID) 569 %Property(name=Icon, get=GetIcon) 570 %Property(name=ImageList, get=GetImageList) 571 %Property(name=Instance, get=GetInstance) 572 %Property(name=Name, get=GetName) 573 %Property(name=Node, get=GetNode) 574 %Property(name=Parent, get=GetParent) 575 %Property(name=ParentAsWindow, get=GetParentAsWindow) 576 %Property(name=Position, get=GetPosition) 577 %Property(name=Resource, get=GetResource) 578 %Property(name=Size, get=GetSize) 579 %Property(name=Style, get=GetStyle) 580 581protected: 582 void AddStyle( 583 const wxString & name, 584 int value 585 ); 586 %Docstring 587 AddStyle(name, value) 588 589 Add a style flag (e.g. 590 %End 591 592 void AddWindowStyles(); 593 %Docstring 594 AddWindowStyles() 595 596 Add styles common to all wxWindow-derived classes. 597 %End 598 599 void CreateChildren( 600 wxObject * parent, 601 bool this_hnd_only = false 602 ); 603 %Docstring 604 CreateChildren(parent, this_hnd_only=False) 605 606 Creates children. 607 %End 608 609 void CreateChildrenPrivately( 610 wxObject * parent, 611 wxXmlNode * rootnode = NULL 612 ); 613 %Docstring 614 CreateChildrenPrivately(parent, rootnode=None) 615 616 Helper function. 617 %End 618 619 wxObject * CreateResFromNode( 620 wxXmlNode * node, 621 wxObject * parent, 622 wxObject * instance = NULL 623 ); 624 %Docstring 625 CreateResFromNode(node, parent, instance=None) -> Object 626 627 Creates a resource from a node. 628 %End 629 630 wxAnimation * GetAnimation( 631 const wxString & param = "animation" 632 ); 633 %Docstring 634 GetAnimation(param="animation") -> Animation 635 636 Creates an animation (see wxAnimation) from the filename specified in 637 param. 638 %End 639 640 wxBitmap GetBitmap( 641 const wxString & param = "bitmap", 642 const wxArtClient & defaultArtClient = wxART_OTHER, 643 wxSize size = wxDefaultSize 644 ); 645 %Docstring 646 GetBitmap(param="bitmap", defaultArtClient=ART_OTHER, size=DefaultSize) -> Bitmap 647 GetBitmap(node, defaultArtClient=ART_OTHER, size=DefaultSize) -> Bitmap 648 649 Gets a bitmap. 650 %End 651 652 wxBitmap GetBitmap( 653 const wxXmlNode * node, 654 const wxArtClient & defaultArtClient = wxART_OTHER, 655 wxSize size = wxDefaultSize 656 ); 657 658 bool GetBool( 659 const wxString & param, 660 bool defaultv = false 661 ); 662 %Docstring 663 GetBool(param, defaultv=False) -> bool 664 665 Gets a bool flag (1, t, yes, on, true are true, everything else is 666 false). 667 %End 668 669 wxColour GetColour( 670 const wxString & param, 671 const wxColour & defaultColour = wxNullColour 672 ); 673 %Docstring 674 GetColour(param, defaultColour=NullColour) -> Colour 675 676 Gets colour in HTML syntax (#RRGGBB). 677 %End 678 679 wxFileSystem & GetCurFileSystem(); 680 %Docstring 681 GetCurFileSystem() -> FileSystem 682 683 Returns the current file system. 684 %End 685 686 wxCoord GetDimension( 687 const wxString & param, 688 wxCoord defaultv = 0, 689 wxWindow * windowToUse = 0 690 ); 691 %Docstring 692 GetDimension(param, defaultv=0, windowToUse=0) -> Coord 693 694 Gets a dimension (may be in dialog units). 695 %End 696 697 wxDirection GetDirection( 698 const wxString & param, 699 wxDirection dirDefault = wxLEFT 700 ); 701 %Docstring 702 GetDirection(param, dirDefault=LEFT) -> Direction 703 704 Gets a direction. 705 %End 706 707 wxFont GetFont( 708 const wxString & param = "font" 709 ); 710 %Docstring 711 GetFont(param="font") -> Font 712 713 Gets a font. 714 %End 715 716 int GetID(); 717 %Docstring 718 GetID() -> int 719 720 Returns the XRCID. 721 %End 722 723 wxIcon GetIcon( 724 const wxString & param = "icon", 725 const wxArtClient & defaultArtClient = wxART_OTHER, 726 wxSize size = wxDefaultSize 727 ); 728 %Docstring 729 GetIcon(param="icon", defaultArtClient=ART_OTHER, size=DefaultSize) -> Icon 730 GetIcon(node, defaultArtClient=ART_OTHER, size=DefaultSize) -> Icon 731 732 Returns an icon. 733 %End 734 735 wxIcon GetIcon( 736 const wxXmlNode * node, 737 const wxArtClient & defaultArtClient = wxART_OTHER, 738 wxSize size = wxDefaultSize 739 ); 740 741 wxIconBundle GetIconBundle( 742 const wxString & param, 743 const wxArtClient & defaultArtClient = wxART_OTHER 744 ); 745 %Docstring 746 GetIconBundle(param, defaultArtClient=ART_OTHER) -> IconBundle 747 748 Returns an icon bundle. 749 %End 750 751 wxImageList * GetImageList( 752 const wxString & param = "imagelist" 753 ); 754 %Docstring 755 GetImageList(param="imagelist") -> ImageList 756 757 Creates an image list from the param markup data. 758 %End 759 760 long GetLong( 761 const wxString & param, 762 long defaultv = 0 763 ); 764 %Docstring 765 GetLong(param, defaultv=0) -> long 766 767 Gets the integer value from the parameter. 768 %End 769 770 float GetFloat( 771 const wxString & param, 772 float defaultv = 0 773 ); 774 %Docstring 775 GetFloat(param, defaultv=0) -> float 776 777 Gets a float value from the parameter. 778 %End 779 780 wxString GetName(); 781 %Docstring 782 GetName() -> String 783 784 Returns the resource name. 785 %End 786 787 wxString GetNodeContent( 788 wxXmlNode * node 789 ); 790 %Docstring 791 GetNodeContent(node) -> String 792 793 Gets node content from wxXML_ENTITY_NODE. 794 %End 795 796 wxXmlNode * GetParamNode( 797 const wxString & param 798 ); 799 %Docstring 800 GetParamNode(param) -> XmlNode 801 802 Finds the node or returns NULL. 803 %End 804 805 wxString GetParamValue( 806 const wxString & param 807 ); 808 %Docstring 809 GetParamValue(param) -> String 810 GetParamValue(node) -> String 811 812 Finds the parameter value or returns the empty string. 813 %End 814 815 wxString GetParamValue( 816 const wxXmlNode * node 817 ); 818 819 wxPoint GetPosition( 820 const wxString & param = "pos" 821 ); 822 %Docstring 823 GetPosition(param="pos") -> Point 824 825 Gets the position (may be in dialog units). 826 %End 827 828 wxSize GetSize( 829 const wxString & param = "size", 830 wxWindow * windowToUse = 0 831 ); 832 %Docstring 833 GetSize(param="size", windowToUse=0) -> Size 834 835 Gets the size (may be in dialog units). 836 %End 837 838 int GetStyle( 839 const wxString & param = "style", 840 int defaults = 0 841 ); 842 %Docstring 843 GetStyle(param="style", defaults=0) -> int 844 845 Gets style flags from text in form "flag | flag2| flag3 |..." Only 846 understands flags added with AddStyle(). 847 %End 848 849 wxString GetText( 850 const wxString & param, 851 bool translate = true 852 ); 853 %Docstring 854 GetText(param, translate=True) -> String 855 856 Gets text from param and does some conversions: 857 %End 858 859 bool HasParam( 860 const wxString & param 861 ); 862 %Docstring 863 HasParam(param) -> bool 864 865 Check to see if a parameter exists. 866 %End 867 868 bool IsOfClass( 869 wxXmlNode * node, 870 const wxString & classname 871 ); 872 %Docstring 873 IsOfClass(node, classname) -> bool 874 875 Convenience function. 876 %End 877 878 void SetupWindow( 879 wxWindow * wnd 880 ); 881 %Docstring 882 SetupWindow(wnd) 883 884 Sets common window options. 885 %End 886 887 void ReportError( 888 wxXmlNode * context, 889 const wxString & message 890 ); 891 %Docstring 892 ReportError(context, message) 893 ReportError(message) 894 895 Reports error in XRC resources to the user. 896 %End 897 898 void ReportError( 899 const wxString & message 900 ); 901 902 void ReportParamError( 903 const wxString & param, 904 const wxString & message 905 ); 906 %Docstring 907 ReportParamError(param, message) 908 909 Like ReportError(wxXmlNode*, const wxString&), but uses the node of 910 parameter param of the currently processed object as the context. 911 %End 912 913 wxXmlResource * GetResource() const; 914 %Docstring 915 GetResource() -> XmlResource 916 917 After CreateResource has been called this will return the current 918 wxXmlResource object. 919 %End 920 921 wxXmlNode * GetNode() const; 922 %Docstring 923 GetNode() -> XmlNode 924 925 After CreateResource has been called this will return the XML node 926 being processed. 927 %End 928 929 wxString GetClass() const; 930 %Docstring 931 GetClass() -> String 932 933 After CreateResource has been called this will return the class name 934 of the XML resource node being processed. 935 %End 936 937 wxObject * GetParent() const; 938 %Docstring 939 GetParent() -> Object 940 941 After CreateResource has been called this will return the current 942 item's parent, if any. 943 %End 944 945 wxObject * GetInstance() const; 946 %Docstring 947 GetInstance() -> Object 948 949 After CreateResource has been called this will return the instance 950 that the XML resource content should be created upon, if it has 951 already been created. 952 %End 953 954 wxWindow * GetParentAsWindow() const; 955 %Docstring 956 GetParentAsWindow() -> Window 957 958 After CreateResource has been called this will return the item's 959 parent as a wxWindow. 960 %End 961 962}; // end of class wxXmlResourceHandler 963 964 965%Extract(id=pycode_xrc, order=10) 966import wx 967ID_NONE = wx.ID_NONE # Needed for some parameter defaults in this module 968 969%End 970 971%Extract(id=pycode_xrc) 972@wx.deprecatedMsg("Use :class:`xrc.XmlResource` instead") 973def EmptyXmlResource(flags=XRC_USE_LOCALE, domain=""): 974 """ 975 A compatibility wrapper for the XmlResource(flags, domain) constructor 976 """ 977 return XmlResource(flags, domain) 978 979%End 980 981%Extract(id=pycode_xrc) 982def XRCID(str_id, value_if_not_found=wx.ID_NONE): 983 """ 984 Returns a numeric ID that is equivalent to the string ID used in an XML resource. 985 """ 986 return XmlResource.GetXRCID(str_id, value_if_not_found) 987 988%End 989 990%Extract(id=pycode_xrc) 991def XRCCTRL(window, str_id, *ignoreargs): 992 """ 993 Returns the child window associated with the string ID in an XML resource. 994 """ 995 return window.FindWindow(XRCID(str_id)) 996 997%End 998 999class wxXmlSubclassFactory 1000{ 1001 %Docstring 1002 XmlSubclassFactory() 1003 %End 1004public: 1005 wxXmlSubclassFactory(); 1006 1007 ~wxXmlSubclassFactory(); 1008 1009 virtual 1010 wxObject* Create( 1011 const wxString& className 1012 ) = 0 /Factory/; 1013 %Docstring 1014 Create(className) -> Object 1015 %End 1016 1017}; // end of class wxXmlSubclassFactory 1018 1019 1020%Extract(id=pycode_xrc) 1021# Create a factory for handling the subclass property of XRC's 1022# object tag. This factory will search for the specified 1023# package.module.class and will try to instantiate it for XRC's 1024# use. The class must support instantiation with no parameters and 1025# delayed creation of the UI widget (aka 2-phase create). 1026 1027def _my_import(name): 1028 try: 1029 mod = __import__(name) 1030 except ImportError: 1031 import traceback 1032 print(traceback.format_exc()) 1033 raise 1034 components = name.split('.') 1035 for comp in components[1:]: 1036 mod = getattr(mod, comp) 1037 return mod 1038 1039class XmlSubclassFactory_Python(XmlSubclassFactory): 1040 def __init__(self): 1041 XmlSubclassFactory.__init__(self) 1042 1043 def Create(self, className): 1044 assert className.find('.') != -1, "Module name must be specified!" 1045 mname = className[:className.rfind('.')] 1046 cname = className[className.rfind('.')+1:] 1047 module = _my_import(mname) 1048 klass = getattr(module, cname) 1049 inst = klass() 1050 return inst 1051 1052XmlResource.AddSubclassFactory(XmlSubclassFactory_Python()) 1053 1054%End 1055 1056 1057//--------------------------------------------------------------------------- 1058 1059 1060%InitialisationCode 1061 wxXmlInitResourceModule(); 1062 wxXmlResource::Get()->InitAllHandlers(); 1063 1064%End 1065 1066//--------------------------------------------------------------------------- 1067 1068