how to know what button was pressed

Dear wx geeks!!

How can i know what button was pressed?

I need to make some different windows that use the very same class but deppending on the button that was pressed the information on the new window would differ. So i need to make a whole bunch of buttons so every different button makes a different behaviour.

But i dont want to make the same number of functions 1 for each button … so the question is … how can i know WHICH button was pressed?

just to avoid this … and that up to 19 times

self.ventana.utiles_pbu1 = wx.Button(self.ventana, -1, ‘Calcular’, size=(70,25))

self.ventana.utiles_pbu1.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu1)

self.ventana.utiles_pbu2 = wx.Button(self.ventana, -1, ‘Calcular’, size=(70,25))

self.ventana.utiles_pbu2.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu2)

self.ventana.utiles_pbu3 = wx.Button(self.ventana, -1, ‘Calcular’, size=(70,25))

self.ventana.utiles_pbu3.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu3)

def calc_utiles_pbu1 (self):

self.grupo = ‘plantabaja:usoprincipal’

Sup_utiles()

def calc_utiles_pbu2 (self):

self.grupo = ‘plantabaja:usosecundario’

Sup_utiles()

def calc_utiles_pbu3 (self):

self.grupo = ‘plantabaja:usoterciario’

Sup_utiles()

many thanks for your time…

The bound function takes an event as an argument:

http://www.wxpython.org/onlinedocs.php

Go to the alphabetical class reference, and look up wxEvent and you
will see a GetId function. Lookup the wxButton and you should see how
you can specify the id of the button yourself in the constructor.

And to see the code download the python demo app open it up and look
for button under core windows/controls. I'm sure you can use the
example code there.
http://www.wxpython.org/download.php#binaries

Mark

···

On Jun 16, 7:00 am, monoBOT <monobot.s...@gmail.com> wrote:

Dear wx geeks!!

How can i know what button was pressed?

I need to make some different windows that use the very same class but
deppending on the button that was pressed the information on the new window
would differ. So i need to make a whole bunch of buttons so every different
button makes a different behaviour.
But i dont want to make the same number of functions 1 for each button ...
so the question is ... how can i know WHICH button was pressed?

just to avoid this ... and that up to 19 times

self\.ventana\.utiles\_pbu1 = wx\.Button\(self\.ventana, \-1, &#39;Calcular&#39;,

size=(70,25))
self.ventana.utiles_pbu1.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu1)
self.ventana.utiles_pbu2 = wx.Button(self.ventana, -1, 'Calcular',
size=(70,25))
self.ventana.utiles_pbu2.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu2)
self.ventana.utiles_pbu3 = wx.Button(self.ventana, -1, 'Calcular',
size=(70,25))
self.ventana.utiles_pbu3.Bind(wx.EVT_BUTTON, self.calc_utiles_pbu3)

def calc_utiles_pbu1 (self):
self.grupo = 'plantabaja:usoprincipal'
Sup_utiles()

def calc_utiles_pbu2 (self):
self.grupo = 'plantabaja:usosecundario'
Sup_utiles()

def calc_utiles_pbu3 (self):
self.grupo = 'plantabaja:usoterciario'
Sup_utiles()

many thanks for your time...

monoBOT wrote:

Dear wx geeks!!

How can i know what button was pressed?

http://wiki.wxpython.org/Passing Arguments to Callbacks

(I'm not sure what will happen with those spaces in the url, but if it doesn't take you straight to the right page, you can search.)

-CHB

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

Just FYI: If you replace the spaces with underscores then MoinMoin will redirect it to the right page. That makes it easier for the readers of the email since they can just click on the link instead of copy and paste a URL and some extra words.

http://wiki.wxpython.org/Passing_Arguments_to_Callbacks

Of course you can also URL-escape the spaces with %20:

http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks

···

On 6/15/10 4:39 PM, Christopher Barker wrote:

monoBOT wrote:

Dear wx geeks!!

How can i know what button was pressed?

http://wiki.wxpython.org/Passing Arguments to Callbacks

(I'm not sure what will happen with those spaces in the url, but if it
doesn't take you straight to the right page, you can search.)

--
Robin Dunn
Software Craftsman

If you don't want to deal with the IDs then you can use event.GetEventObject() to get a reference to the button object that triggered the event.

···

On 6/15/10 4:18 PM, Mark wrote:

The bound function takes an event as an argument:

http://www.wxpython.org/onlinedocs.php

Go to the alphabetical class reference, and look up wxEvent and you
will see a GetId function. Lookup the wxButton and you should see how
you can specify the id of the button yourself in the constructor.

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

Just FYI: If you replace the spaces with underscores then MoinMoin will redirect it to the right page. That makes it easier for the readers of the email since they can just click on the link instead of copy and paste a URL and some extra words.

Passing Arguments to Callbacks - wxPyWiki

thanks -- why in the world it doesn't just use underscores to begin with is beyond me.

Of course you can also URL-escape the spaces with %20:

Passing Arguments to Callbacks - wxPyWiki

Firefox used to do this more me when I cut&pasted -- I wonder what changed?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

That was the trick, so many thanks for the link!!!!! (even with the
spaces "bug") :slight_smile:

···

On 16 jun, 00:39, Christopher Barker <Chris.Bar...@noaa.gov> wrote:

monoBOT wrote:
> Dear wx geeks!!

> How can i know what button was pressed?

http://wiki.wxpython.org/PassingArguments to Callbacks

(I'm not sure what will happen with those spaces in the url, but if it
doesn't take you straight to the right page, you can search.)

-CHB

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Bar...@noaa.gov

I discovered that if I copied those annoying links into the search box
in the upper right of Firefox, it would put the %20 in for me. Then I
could copy that link.

Sneaky? You bet'cha! But it works!

···

On Jun 15, 9:07 pm, Christopher Barker <Chris.Bar...@noaa.gov> wrote:

Robin Dunn wrote:
> Just FYI: If you replace the spaces with underscores then MoinMoin will
> redirect it to the right page. That makes it easier for the readers of
> the email since they can just click on the link instead of copy and
> paste a URL and some extra words.

>Passing Arguments to Callbacks - wxPyWiki

thanks -- why in the world it doesn't just use underscores to begin with
is beyond me.

> Of course you can also URL-escape the spaces with %20:

>Passing Arguments to Callbacks - wxPyWiki

Firefox used to do this more me when I cut&pasted -- I wonder what changed?

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

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

Blog: http://blog.pythonlibrary.org