[Tutor] Is this a "Class" problem?

Timothy Grant timothy.grant at gmail.com
Fri Aug 29 22:42:47 CEST 2008


On Fri, Aug 29, 2008 at 9:19 AM, Adrian Greyling
<adrian.greyling at gmail.com> wrote:
> Thanks for the response Jeff, although your answer has spawned another
> question or two!  In your answer, you showed that the attribute "
> MySecondFrame.text_ctrl_2" doesn't exist and to correct that, you suggested
> the code below.  (What I understand from your response is that I can't
> reference the original object, but I must create an instance of it.  Is that
> right??)
>
>     def MainToSecond(self, event): # wxGlade: MyMainFrame.<event_handler>
>
>         m = MySecondFrame(self)
>         m.Show()
>
>         m.text_ctrl_2.SetValue("This text was generated from the 'MainFrame'
> window")
>
> Here's where I get fuzzy...  Let's say I've got a "frame_1" object
> that opens a new "frame_2" object.  As you've suggested above, I'll use "m"
> to create an instance of a frame object.  Now frame_2 opens a "dialog_1'"
> which asks for information that is sent back to 'frame_2'. How do I
> reference 'frame_2' in this case?  Especially when frame_2 hasn't been
> closed and has just been waiting behind dialog_1 until dialog_1 closes.
> When I try to reference it again as "m = frame_2(self)" from a new function
> definition, aren't I creating a brand new frame_2 object that has "blank"
> attributes, so to speak?
>
> I'm sure I've made things clear as mud, but hopefully with my blathering,
> someone will undertand my utter confusion!
>
> Thanks everyone!
> Adrian
>
>
>
>
> On Mon, Aug 18, 2008 at 3:29 PM, Jeff Younker <jeff at drinktomi.com> wrote:
>>
>> On Aug 18, 2008, at 9:13 AM, Adrian Greyling wrote:
>>
>>     def MainToSecond(self, event): # wxGlade: MyMainFrame.<event_handler>
>>         MySecondFrame(self).Show()
>>         MySecondFrame.text_ctrl_2.SetValue("This text was generated from
>> the 'MainFrame' window")
>>
>> The expression MySecondFrame(self) creates a new object.  It
>> initializes the new object by calling the MySecondFrame's __init__
>> method.
>>
>> class MySecondFrame(wx.Frame):
>>     def __init__(self, *args, **kwds):
>>         # begin wxGlade: MySecondFrame.__init__
>> ...
>>
>>        self.text_ctrl_2 = wx.TextCtrl(self, -1, "",
>> style=wx.TE_MULTILINE)
>> ...
>>
>> The __init__ method calls sets the variable text_ctrl_2 in the object
>> m.
>> Your function MainToSecond is trying to get the attribute
>> MySecondFrame.text_ctrl_2.
>> This attribute does not exist.  You want to get the attribute
>> m.text_ctrl_2.  So, the method
>> should be:
>>     def MainToSecond(self, event): # wxGlade: MyMainFrame.<event_handler>
>>         m = MySecondFrame(self)
>>         m.Show()
>>         m.text_ctrl_2.SetValue("This text was generated from the
>> 'MainFrame' window")
>>
>> Also, method and function names should always start with a lower case
>> letter: always
>> mainToSecond and never MainToSecond
>> -jeff
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
Adrian,

Two things...

You should check out the wxpython mailing list. It's a much better
place to ask wxPython related questions.

You should check out the wx.lib.pubsub module. It will allow you to
publish data in one object and subscribe to it in another.



-- 
Stand Fast,
tjg. [Timothy Grant]


More information about the Tutor mailing list