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,
Hello Ben,
could you provide a small runnable sample program
of your problem?
I suspect, the IsChecked applies only for Menuitems and
Checkbox events.
···
On Tue, 21 Jun 2005 17:24:19 -0400, Benjamin C Miller <ben@effortlessav.com> wrote:
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 Steinhaeusler
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:
ToggleTest.py (3.9 KB)
···
On Tue, 21 Jun 2005 17:24:19 -0400, Benjamin C Miller ><ben@effortlessav.com> wrote:
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,
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
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
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.
···
On Thu, 23 Jun 2005 00:03:56 -0400, Benjamin C Miller <ben@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:
--
Franz Steinhaeusler
Franz Steinhäusler wrote:
···
On Thu, 23 Jun 2005 00:03:56 -0400, Benjamin C Miller ><ben@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
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@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