Problem with events

Now there is the file attached…

viewsF.py (7.04 KB)

···

---------- Forwarded message ----------
From: Sbaush sbaush@gmail.com
Date: 20-gen-2006 23.03
Subject: Problem with events
To: wxPython-users@lists.wxwidgets.org

Hi all.
I have a problem in the file attached.
This is a wxGlade generated gui.

At line 43 i create a Button.
At line 154 i have try to “bind” the click on this button with an event, the function onButton.

This function, to try the events, is only the quit of application, as you can see at lines 138-139.

I launch this but tha application NOT quit clicking on button.

WHY???


Sbaush


Sbaush

Sbaush wrote:

Now there is the file attached...

boy, you get hard to read code with a code generator.

However:

if __name__ == "__main__":
     Manager = wxPySimpleApp(0)
     wxInitAllImageHandlers()
     MainView = MainView(None, -1, "")
     Manager.SetTopWindow(MainView)
     MainView.CenterOnScreen()
     MainView.Show()
     Manager.MainLoop()
     MainView.button_1.Bind(EVT_BUTTON,self.onButton)

1) You can't do anything after the Mainloop is called! It doesn't return until you close the app.

2) you don't want to bind an event in the main module code, it should be bound in the Panel or Frame that's relevant. It's possible that you could write this line properly, then put it before the Show() call, but I'm not going to tell you how.

Put that line in MainView.__init__, after button_1 has been defined, and it should work.

3) In that line, you're binding to "self.onButton", What is "self" here? I don't think it's defined, you probably get an error after closing the app.

4) also you've re-bound MainView from a class to an instance of that class. That'll probably work, as you won't need that class again, but it's a bad habit to get into.

5) you don't need wxInitAllImageHandlers() any more. Minor point, but why waste the code.

6) When you're trying to figure out something -- start SMALL. Put a single button on a frame, and bind to it. It's be a lot easier to figure out, and a lot easier for us to help you.

7) Doesn't wxGlade give you a way to boiind the basic events?

8) Learn to crawl before you can walk. If you don't understand OO in Python, you're going to have a hard time with wxPython:

http://wiki.wxpython.org/index.cgi/How_20to_20Learn_20wxPython

9) As fabulous as wxGlade (and others) are, I htnk it's a good idea to at least learn the basics of wxPython by hand writing some code. It's be a lot easier to understand.

10) Or go straight to Dabo -- beat you to it Peter!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Sbaush wrote:

Now there is the file attached…

boy, you get hard to read code with a code generator.
However:

  1. You can’t do anything after the Mainloop is called! It doesn’t return
    until you close the app.

OK, i have not thought to it…

  1. you don’t want to bind an event in the main module code, it should be
    bound in the Panel or Frame that’s relevant. It’s possible that you
    could write this line properly, then put it before the Show() call, but

I’m not going to tell you how.

Put that line in MainView.init, after button_1 has been defined, and
it should work.

OK, i’ll try.

  1. In that line, you’re binding to “self.onButton”, What is “self” here?
    I don’t think it’s defined, you probably get an error after closing the app.

No, error not get, but you’re right, self is not defined.

  1. also you’ve re-bound MainView from a class to an instance of that
    class. That’ll probably work, as you won’t need that class again, but

it’s a bad habit to get into.

  1. you don’t need wxInitAllImageHandlers() any more. Minor point, but
    why waste the code.

  2. When you’re trying to figure out something – start SMALL. Put a
    single button on a frame, and bind to it. It’s be a lot easier to figure

out, and a lot easier for us to help you.

This is a very, very good idea…
I’ve a little bit of time unfortunately and my trials are directly on my project…
I know that this is a horrible method, but now i think that is the only way.

A BIG, BIG thanks to you and to all tha lists that are help me in every time. YOU ARE GREAT. If my project will have a end, you’ll be in the special thanks page of it.

  1. Doesn’t wxGlade give you a way to boiind the basic events?

yes, but i use wxGlade only for the view, i want put the events by hand

  1. Learn to crawl before you can walk. If you don’t understand OO in
    Python, you’re going to have a hard time with wxPython:

http://wiki.wxpython.org/index.cgi/How_20to_20Learn_20wxPython

good page. i’ll read it tomorrow.

  1. As fabulous as wxGlade (and others) are, I htnk it’s a good idea to

at least learn the basics of wxPython by hand writing some code. It’s be
a lot easier to understand.

  1. Or go straight to Dabo – beat you to it Peter!

-Chris

Like i’ve wrote in past lines, thanks for your help to all my questions.

I’m italian, it’s not easy learn from english only in this little bit of time… The merit of my learnig is your!!!
Thanks again to all.

···

2006/1/20, Christopher Barker Chris.Barker@noaa.gov:

Damn! That's what I get for taking time out to eat dinner! :slight_smile:

···

On 1/20/06, Christopher Barker <Chris.Barker@noaa.gov> wrote:

10) Or go straight to Dabo -- beat you to it Peter!

--

# p.d.