Accessing wx.TextCtrl after refactoring

Rhodri James rhodri at wildebst.demon.co.uk
Fri Mar 27 21:13:56 EDT 2009


On Sat, 28 Mar 2009 00:51:04 -0000, Rhodri James  
<rhodri at wildebst.demon.co.uk> wrote:

> On Fri, 27 Mar 2009 21:51:19 -0000, alex <alecla at bluewin.ch> wrote:
>
>> Hi all
>> I am working on a Dialog window for a gui in wxPython and started
>> refactoring it, below code is a simplified version of it.
>> "def createInput1" should create a static text, a button and a
>> textcontrol using the information in "def box1Labels".
>> "def makeStaticBox1" then arranges all widgets in staticbox1.
>>
>> My problem is that it works fine for the static text and the button
>> label but I cant "rename" self.txtctrl that it
>> becomes self.txtctrl_inpath or self.txtctrl_outpath for getting the
>> path from either "def BrowseInDlg" or "def BrowseOutDlg".
>
> You need the special __setattr__ method.  A normal object attribute
> assignment like:
>
>    self.wombat = "go"
>
> is equivalent to a call of
>
>    self.__setattr__("wombat", "go")
>
> So in your createInput1 method, once the widgets have been created
> and all the dust has settled, if you add the line:
>
>    self.__setattr__(txtctrl_path, self.txtctrl)
>
> it will do exactly what you're after!
>

or in a slightly less "magic" way:

   setattr(self, txtctrl_path, self.txtctrl)

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list