Toggle Button Event Creation

141 views
Skip to first unread message

Benjamin C Miller

unread,
Jun 21, 2005, 5:24:19 PM6/21/05
to wxPython-users
I am using a method that toggles a toggle button
(self.togglebutton.SetValue()) .but does not generate a
wx.EVT_TOGGLEBUTTON event. To make sure that any handling that is set up
for the toggle button actually takes place, the method creates an event
and adds it to the appropriate handler. The only hitch so far is that I
can't create a wx.EVT_TOGGLEBUTTON event where event.IsChecked() returns
True.

Am I missing something or can I only create the event for turning off
the toggle?

Thanks,

Franz Steinhäusler

unread,
Jun 22, 2005, 8:11:07 AM6/22/05
to wxpytho...@lists.wxwindows.org

Hello Ben,

could you provide a small runnable sample program
of your problem?

I suspect, the IsChecked applies only for Menuitems and
Checkbox events.
--
Franz Steinhaeusler


Benjamin C Miller

unread,
Jun 23, 2005, 12:03:56 AM6/23/05
to wxPytho...@lists.wxwidgets.org
Thanks Franz,

See the sample attached. What I really would like to happen is to toggle
the button by sending an event to it...
Maybe I should be creating a mouse click on the button instead ?
Maybe I should just check the actual value of the button after an event
is received (which seems redundant because I have to set it directly
sometimes anyway).

But since a user button click toggles the event.IsChecked() value I
figured that I should be able to set it somewhere.
(even though _core.py does not mention this functionality for a toggle.)

Franz Steinhäusler wrote:

>---------------------------------------------------------------------
>To unsubscribe, e-mail: wxPython-user...@lists.wxwidgets.org
>For additional commands, e-mail: wxPython-...@lists.wxwidgets.org
>
>
>
>
>
>

ToggleTest.py

Franz Steinhäusler

unread,
Jun 23, 2005, 4:17:06 AM6/23/05
to wxpytho...@lists.wxwindows.org
On Thu, 23 Jun 2005 00:03:56 -0400, Benjamin C Miller
<b...@effortlessav.com> wrote:

>Thanks Franz,
>
>See the sample attached. What I really would like to happen is to toggle
>the button by sending an event to it...
>Maybe I should be creating a mouse click on the button instead ?
>Maybe I should just check the actual value of the button after an event
>is received (which seems redundant because I have to set it directly
>sometimes anyway).
>
>But since a user button click toggles the event.IsChecked() value I
>figured that I should be able to set it somewhere.
>(even though _core.py does not mention this functionality for a toggle.)
>
>Franz Steinhäusler wrote:
>

Hello Ben,

I hope, I understood you right.

The problem is, that the IsChecked always returns false, if the toggle
button is changed with "Change value w/ Event"?

What if you use the SetInt and GetInt?

def OnToggle(self, event):
self.txtValue.SetValue(str(self.toggleButton.GetValue()))
self.txtChecked.SetValue(str(event.GetInt() == 1)) #changed
event.Skip()

def OnBtnValue(self, event):
self.toggleButton.SetValue(1-self.toggleButton.GetValue())
self.txtValue.SetValue(str(self.toggleButton.GetValue()))
self.txtChecked.SetValue('no event')
event.Skip()

def OnBtnEvent(self, event):
self.toggleButton.SetValue(1-self.toggleButton.GetValue())
self.txtValue.SetValue(str(self.toggleButton.GetValue()))
self.toggleEvent =
wx.CommandEvent(wx.wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,
self.toggleButton.GetId())
self.toggleEvent.SetEventObject(self.toggleButton)
self.toggleEvent.SetInt(self.toggleButton.GetValue()) #changed

self.toggleButton.GetEventHandler().ProcessEvent(self.toggleEvent)
#self.txtChecked.SetValue(str(self.toggleEvent.IsChecked()))
#changed
self.txtChecked.SetValue(str(self.toggleEvent.GetInt() == 1))
#changed
event.Skip()

I tried it and it work for toggling button by mouse click and for the
button "change value".

BTW: nice example.

--
Franz Steinhaeusler


Benjamin C Miller

unread,
Jun 23, 2005, 8:47:37 PM6/23/05
to wxPytho...@lists.wxwidgets.org

Franz Steinhäusler wrote:

>---------------------------------------------------------------------
>To unsubscribe, e-mail: wxPython-user...@lists.wxwidgets.org
>For additional commands, e-mail: wxPython-...@lists.wxwidgets.org
>
>
>
>

GetInt() and IsChecked() return the same - and SetInt() sets the checked
/ IsChecked - who woulda thunk it ...

Brilliant - simple solutions are my favorite,

many thanks


Reply all
Reply to author
Forward
0 new messages