communication between frames

Hi,all, I am a new user to wxpython. I have just ran into a problem
recently that I have a separate clicklistbox frame window that would
pop up upon clicking on a button on the main frame and by checking the
items on the checklist I want to append them into a list defined in
the main frame, but I just can't get it to work since there should be
something wrong with the way I call the onbutton function. anyone can
help me out? thanks!

here is the piece of the code:

inside the mainframe:

  def OnShowButton(self,event):
    showallframe = ShowAll(self.list) # ShowAll is the customized
frame embedding a checklist box
    showallframe.Show()
    to_extend= showallframe.returnlists() # returnlist is the method
of ShowAll class, which simply returns a list of the checked terms

    if len(to_extend):
      self.orginalist.extend(to_extend) # extend the original list in
the main frame of the program

the problem is that it is always giving an empty to_extend, I don't
know how to make the returnlist() method return the list only after I
check the items and hit on the add button on the small popped out
window.

Thanks!

winter

Sorry, I guess I did not make it clear. The popped up frame really
does what I want but it is just the way I instantiate the frame and
call its returnlist() method that could not give me the right result.
it executes the lines after the frame.Show() right after the frame is
shown, I am not able to make it executes the lines only after I have
made the checks on the checklist box.

Probablly this is a silly question, but could anyone help me? Thank
you!

···

On Oct 13, 7:27 pm, Winter <ytlu...@gmail.com> wrote:

Hi,all, I am a new user to wxpython. I have just ran into a problem
recently that I have a separate clicklistbox frame window that would
pop up upon clicking on a button on the main frame and by checking the
items on the checklist I want to append them into a list defined in
the main frame, but I just can't get it to work since there should be
something wrong with the way I call the onbutton function. anyone can
help me out? thanks!

here is the piece of the code:

inside the mainframe:

    def OnShowButton\(self,event\):
            showallframe = ShowAll\(self\.list\)    \# ShowAll is the customized

frame embedding a checklist box
showallframe.Show()
to_extend= showallframe.returnlists() # returnlist is the method
of ShowAll class, which simply returns a list of the checked terms

            if len\(to\_extend\):
                    self\.orginalist\.extend\(to\_extend\)    \# extend the original list in

the main frame of the program

the problem is that it is always giving an empty to_extend, I don't
know how to make the returnlist() method return the list only after I
check the items and hit on the add button on the small popped out
window.

Thanks!

winter

Hi,all, I am a new user to wxpython.

Hi, and welcome!

I have just ran into a problem

recently that I have a separate clicklistbox frame window that would

pop up upon clicking on a button on the main frame and by checking the

items on the checklist I want to append them into a list defined in

the main frame, but I just can’t get it to work since there should be

something wrong with the way I call the onbutton function. anyone can

help me out? thanks!

here is the piece of the code:

inside the mainframe:

    def OnShowButton(self,event):

            showallframe = ShowAll(self.list)    # ShowAll is the customized

frame embedding a checklist box

            showallframe.Show()

            to_extend= showallframe.returnlists()   # returnlist is the method

of ShowAll class, which simply returns a list of the checked terms

            if len(to_extend):

                    self.orginalist.extend(to_extend)    # extend the original list in

the main frame of the program

the problem is that it is always giving an empty to_extend,

That is because when Python reads the code, it just goes down the lines and after it completes the task of Show()ing the frame, it simply calls returnlists(), but of course it has not yet had a chance to get any checked items.

One way to do this is create the showallframe as a child frame to the main frame. Then, whenever you need to reference the main frame to pass it anything (like the results of the returnlists() function), you can reference it by self.GetParent().

I would have an event handler for the button in your showallframe get the to_extend data, and then you can pass it to the main frame by something like:

self.GetParent().to_extend = returnlists()

This is kind of a quick and dirty way to do it. There are other ways, such as pubsub, or passing in a reference to the main frame when you create the showallframe.

BTW, I’d also recommend you use better object names. “showallframe” is not good wxPython naming convention. You can see them here, under “naming conventions”:
http://www.wxpython.org/codeguidelines.php

Also, might want to make the method names more explicit. ShowAll() what? for example.

Che

Speaking of code guidelines, you mights also find the official Python style guide helpful: http://www.python.org/dev/peps/pep-0008/

Of course, it doesn’t quite match up with ours. The big thing is to be consistent.

···

Mike Driscoll

Blog: http://blog.pythonlibrary.org

thank you so much! it is working right now as I followed your advice!
And yeah, I really need to look at some of the naming conventions
since I always got stuck when naming all the variables.

···

On Oct 13, 11:29 pm, C M <cmpyt...@gmail.com> wrote:

Hi,all, I am a new user to wxpython.

Hi, and welcome!

> I have just ran into a problem
> recently that I have a separate clicklistbox frame window that would
> pop up upon clicking on a button on the main frame and by checking the
> items on the checklist I want to append them into a list defined in
> the main frame, but I just can't get it to work since there should be
> something wrong with the way I call the onbutton function. anyone can
> help me out? thanks!

> here is the piece of the code:

> inside the mainframe:

> def OnShowButton(self,event):
> showallframe = ShowAll(self.list) # ShowAll is the
> customized
> frame embedding a checklist box
> showallframe.Show()
> to_extend= showallframe.returnlists() # returnlist is the
> method
> of ShowAll class, which simply returns a list of the checked terms

> if len(to_extend):
> self.orginalist.extend(to_extend) # extend the
> original list in
> the main frame of the program

> the problem is that it is always giving an empty to_extend,

That is because when Python reads the code, it just goes down the lines and
after it completes the task of Show()ing the frame, it simply calls
returnlists(), but of course it has not yet had a chance to get any checked
items.

One way to do this is create the showallframe as a child frame to the main
frame. Then, whenever you need to reference the main frame to pass it
anything (like the results of the returnlists() function), you can reference
it by self.GetParent().

I would have an event handler for the button in your showallframe get the
to_extend data, and then you can pass it to the main frame by something
like:

self.GetParent().to_extend = returnlists()

This is kind of a quick and dirty way to do it. There are other ways, such
as pubsub, or passing in a reference to the main frame when you create the
showallframe.

BTW, I'd also recommend you use better object names. "showallframe" is not
good wxPython naming convention. You can see them here, under "naming
conventions":http://www.wxpython.org/codeguidelines.php

Also, might want to make the method names more explicit. ShowAll() what?
for example.

Che

Yeah, I have looked at it, it is really helpful, thank you!

···

On Oct 14, 9:56 am, Mike Driscoll <kyoso...@gmail.com> wrote:

Speaking of code guidelines, you mights also find the official Python style
guide helpful:PEP 8 – Style Guide for Python Code | peps.python.org

Of course, it doesn't quite match up with ours. The big thing is to be
consistent.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Since this just came up, and you’re new to the list and wxPython, might as well mention that this list prefers bottom posting. That is, place your responses to other people’s messages UNDER their words (not above, as you have done in the last few messages). Just makes following the thread of a conversation much easier*. Thanks.

*http://idallen.com/topposting.html

···

On Fri, Oct 14, 2011 at 11:19 AM, Winter ytlustc@gmail.com wrote:

Yeah, I have looked at it, it is really helpful, thank you!

You’re such a whiner!