= XRC Cheat Sheet = <> == Framework == * XrcStartingPoints == wxButton == OnInit: {{{#!python self.btn = XRCCTRL( self.frame, "ButtonName" ) # rarely needed EVT_BUTTON( self.frame, XRCID( "ButtonName" ), self.OnClick ) }}} OnClick: {{{#!python def OnClick( self, evt ): btn = evt.GetEventObject() nam = evt.GetEventObject().GetName() lbl = evt.GetLabel() # do something }}} Use "-1" instead of XRCID("ButtonName") to direct all clicks to one handler. For handle to button, add to OnInit: {{{#!python }}} == wxChoice == OnInit: {{{#!python self.choice = XRCCTRL( self.frame, "ChoiceName" ) EVT_CHOICE( XRCID( "ChoiceName" ), self.OnSelect ) }}} OnSelect: {{{#!python def OnSelect( self, evt ): sel_index = evt.GetSelection() # 0, 1, 2, ... sel_str = evt.GetString() # "Apples", "Oranges", ... choice = evt.GetEventObject() # # do something }}} == wxMenuItem == An XRC object name which matches a stock window ID (wxID_NEW, wxID_OPEN, and so on) will be recognized, and the appropriate ID will be applied to the generated item. For example, the following XML defines the "New" menu item: {{{#!xml Ctrl+N }}} The Pythonic forms of the stock IDs (wx.ID_NEW) will ''not'' be recognized. == wxTextCtrl == OnInit: {{{#!python self.txt = XRCCTRL( self.frame, "TextCtrlName" ) # need to add registrations for text change and enter key here... }}} Manipulating Text: {{{#!python self.txt.SetValue( "Text for box." ) }}} = Introduction = (Intro at end of document on purpose.) This cheat sheet exists to aleviate steps 2,3,4: 1. Use [[wxDesigner]] or [[wxGlade]] to create an XRC file. 1. Search on the wxPython wiki for "UsingXmlResources." (Generally, I've forgotten the name.) 1. Adapt UsingXmlResources' code to something that I like, to be a basic framework. 1. Scan for applicable pieces of UsingXmlResources, and search through the wxPython docs, to remember how to do the little things I want to do. 1. Actually write the interesting code. You are '''strongly invited''' to make this document more useful! If there's something that should be here, ''please add it!'' General rule of thumb: 1. If it's a feature people use ''a lot'', put it in here! 1. If it's a feature people use ''rarely'', keep it out! 1. Exercise good judgement in all other cases. For example: * Buttons are always clicked, so we put button clicking code in here. * But buttons' labels rarely change, so we don't put that in here. Go look it up. We want to get "that easy 90%", and just look up the remaining 10%.