Re: [wxpython-users] Writetext from one frame event toanotherframetextctrl.
by Timothy Grant other posts by this author
Jul 8 2008 1:12PM messages near this date
Re: [wxpython-users] Writetext from one frame event toanotherframetextctrl.
|
[wxpython-users] Simple scope question
On Tue, Jul 8, 2008 at 12:41 PM, Steve Freedenburg <
stevefreedenburg@[...].net> wrote:
> Mr. Carlson, you are right, I could / should have sought others for help.
> In this istance, the people on this mailing list have made themselves
> available beyond my expectations. I just didn't want to ask a question
> where
> the answer was obvious and obliviate my chance for getting information in
> the future. The poster who cried wolf too many times over trivial things in
> my mind starts to get overlooked.
>
> Thank you all for the help... BTW using sizers (which I am having success)
> on a frame with scads of widgets is like doing a Rubik's Cube puzzle. Any
> tips?
>
> ----- Original Message ----- From: "Josiah Carlson" <
> josiah.carlson@[...].com>
> To: <wxpython-users@[...].org>
> Sent: Monday, 07 July, 2008 21:47
>
> Subject: Re: [wxpython-users] Writetext from one frame event
> toanotherframetextctrl.
>
>
> In the future, remember that you can ask questions after you have
> > exhausted reasonable methods of self-research time (where reasonable
> > is at least 10 minutes, but certainly far less than 50 hours ;) ).
> >
> > - Josiah
> >
> > On Mon, Jul 7, 2008 at 6:41 PM, Steve Freedenburg
> > <stevefreedenburg@[...].net> wrote:
> >
> >> Dear Mr. Driscoll,
> >>
> >> Your code (in your words) may not be elegant as the other examples, but
> >> I
> >> will say this: It is spectacular.
> >> If I may elaborate. I would guess that I spent a total of 50+ man hours
> >> searching for a way to do exactly what
> >> you showed me how to do. I have shelved this project for not being able
> >> to
> >> find on my own solution. The word
> >> frustration does not do justice to how I remember feeling. So with that
> >> being said, your code practically was "cut and paste." I did have to
> >> change
> >> some names around and what not, but I was able to impliment the code,
> >> without using an event, but by calling a function, which pretty much
> >> automates the process... It pretty much works like a mail sorter. "If
> >> string of text matches X-var send text to container 1... If string of
> >> text
> >> matches Y-var send text to container 2 etc."
> >>
> >> Ultimately, I want to thank you and Josiah, you have saved my project,
> >> and
> >> probably sanity even.
> >>
> >> Respectfully,
> >>
> >> Steve Freedenburg
> >> ----- Original Message ----- From: "Mike Driscoll"
> >> <mdriscoll@[...].us>
> >> To: <wxpython-users@[...].org>
> >> Sent: Monday, 07 July, 2008 12:08
> >> Subject: Re: [wxpython-users] Writetext from one frame event to
> >> anotherframetextctrl.
> >>
> >>
> >> Steve Freedenburg wrote:
> >>>
> >>>>
> >>>> <div class="moz-text-flowed" style="font-family: -moz-fixed">I'm still
> >>>> not getting it. I'm sorry for being dense, but this is the definative
> >>>> hang up if there ever was one for me and this program. This is my 3rd
> >>>> attempt at it and this is
> >>>> what is my bottle neck. Thanks to Josiah Carlson for helping me with
> >>>> the show(), hide() issue I was having with the Contianer frames, which
> >>>> was a super way to keep the
> >>>> program looking clean. Anyhow.
> >>>>
> >>>> There has to be something so fundamentally simple that I'm just not
> >>>> understanding. I'm think I'm blushing, or getting angry at myself.
> >>>>
> >>>> Here is my code, maybe it's the names that I'm using, and the example
> >>>> given that is confusing me, maybe if you see my code you can see where
> >>>> I'm getting things wrong. I haven't added portions of the program
> >>>> until I get the text control thing taken care of. I've commented
> >>>> everything I could think of that wasn't obvious.
> >>>>
> >>>> Karsten I'm sorry for not understanding your example. I tried
> >>>> implimenting your example in the function "WriteCF1" And the global
> >>>> variable "CF1Text." I tried attaching the
> >>>> function to one of the events to "write" something to the ContainerOne
> >>>> frame's text control widget, and it didn't throw an error in the
> >>>> shell, it just looked like it got skipped over,
> >>>> so I took it out so I didn't get confused with where I put things.
> >>>>
> >>>> Thanks in advance for any help.
> >>>>
> >>>
> >>> <snip long bit of code>
> >>>
> >>> I can't use your code as it included external references. So I wrote my
> >>> own short script. In it, I create two frames and use the pubsub
> >>> capabilities of wxPython to transfer the data. I tested it with wxPython
> >>> 2.8.8.0, Python 2.5 on Windows XP and it worked for me. Josiah talked
> >>> about the pubsub module last week with another fellow and had some
> >>> interesting things to say about it. his way of using pubsub is more
> >>> elegant than mine, but I didn't want to go digging through the archives
> >>> to find it.
> >>>
> >>> Hopefully that gives you an idea. I'm sure the other methods that were
> >>> mentioned work as well.
> >>>
> >>> -------------------
> >>> Mike Driscoll
> >>>
> >>> Blog: http://blog.pythonlibrary.org
> >>> Python Extension Building Network: http://www.pythonlibrary.org
> >>>
> >>>
> >>>
> >>
> >>
> >> --------------------------------------------------------------------------------
> >>
> >>
> >> import wx
> >>> from wx.lib.pubsub import Publisher
> >>>
> >>> class FrameX(wx.Frame):
> >>>
> >>> def __init__(self, parent):
> >>>
> >>> wx.Frame.__init__(self, parent, wx.ID_ANY, "Frame X")
> >>>
> >>> self.panel = wx.Panel(self, wx.ID_ANY)
> >>>
> >>> self.textCtrl = wx.TextCtrl(self.panel, wx.ID_ANY, "")
> >>> transferBtn = wx.Button(self.panel, wx.ID_ANY, "Transfer")
> >>> self.Bind(wx.EVT_BUTTON, self.onTransfer, transferBtn)
> >>>
> >>> sizer = wx.BoxSizer(wx.VERTICAL)
> >>> sizer.Add(self.textCtrl, 0, wx.ALL, 5)
> >>> sizer.Add(transferBtn, 0, wx.ALL, 5)
> >>> self.panel.SetSizer(sizer)
> >>>
> >>> # open 2nd frame
> >>> self.secFrame = FrameY(None).Show()
> >>> print type(self.secFrame)
> >>> print dir(self.secFrame)
> >>>
> >>> def onTransfer(self, event):
> >>> # get text from main frame's textctrl
> >>> text = self.textCtrl.GetValue()
> >>> Publisher().sendMessage(('frame', 'message'), [text])
> >>>
> >>> class FrameY(wx.Frame):
> >>>
> >>> def __init__(self, parent):
> >>>
> >>> wx.Frame.__init__(self, parent, wx.ID_ANY, "Frame Y")
> >>>
> >>> self.panel = wx.Panel(self, wx.ID_ANY)
> >>>
> >>> self.textCtrl = wx.TextCtrl(self.panel, wx.ID_ANY, "")
> >>>
> >>> Publisher().subscribe(self.__onReceiveMessage, ('frame',
> >>> 'message'))
> >>>
> >>> def __onReceiveMessage(self, message):
> >>> print 'in __onReceiveMessage'
> >>> self.textCtrl.SetValue(message.data[0])
> >>>
> >>> if __name__ == "__main__":
> >>> app = wx.PySimpleApp()
> >>> frame = FrameX(None).Show()
> >>> app.MainLoop()
> >>>
> >>>
> >>
I have to say I'm partial to the GridBagSizer when dealing with lots of
widgets. Though making changes can become a bit of a problem.
For me it's easiest to group related widgets together in their own panel,
and then put the panels together to create the finished Frame. This allows
you to build small, and usually more manageable, pieces at one time.
--
Stand Fast,
tjg.
Thread:
Steve Freedenburg
Mike Driscoll
Josiah Carlson
Timothy Grant
|