1. wxEuphoria no event triggered

What's wrong with the following code. When I click buttons no event handler is
called.

procedure select_prog2edit(integer  enable_suppress)
atom dlgSelectProg, btnSelectOk,  btnSelectCancel, btnSelectDelete
object fnVal
sequence choices
  
  prog_id = 0
  prog2edit = {}
  choices = {}
for i = 1 to length(programs) do choices =
  append(choices,programs[i][SESSION_NAME]) end for
dlgSelectProg = create(wxDialog,{CTrainerMainWin,-1,"Sélection du
  programme",-1,-1,300,305})
ProgListBox =
  create(wxListBox,{dlgSelectProg,IDD_LISTBOX,10,10,280,200,choices})
btnSelectOk = create(wxButton,{dlgSelectProg,IDD_SELECT_OK,"A&ccepter",
  20,220,60,30})
btnSelectCancel =
  create(wxButton,{dlgSelectProg,IDD_SELECT_CANCEL,"&Annuler",210,220,60,30})
  if enable_suppress then
btnSelectDelete =
    create(wxButton,{dlgSelectProg,IDD_SELECT_DELETE,"&Supprimer",115,220,60,30})
set_event_handler(dlgSelectProg,{IDD_SELECT_OK,IDD_SELECT_CANCEL,IDD_SELECT_DELETE},wxEVT_COMMAND_BUTTON_CLICKED,
                      routine_id("evt_select_prog2edit"))
  else
set_event_handler(dlgSelectProg,{IDD_SELECT_OK,IDD_SELECT_CANCEL},wxEVT_COMMAND_BUTTON_CLICKED,
                      routine_id("evt_select_prog2edit"))
  
  end if
  fnVal =  show_modal(dlgSelectProg)
  if platform()=WIN32 then
    delete_instance(dlgSelectProg)
  end if
  if  fnVal = IDD_SELECT_CANCEL then
    return 
  else
    if fnVal > 0 and fnVal <= length(programs) then
      prog_id = fnVal
      prog2edit = programs[prog_id]
    end if
    return 
  end if
end procedure



new topic     » topic index » view message » categorize

2. Re: wxEuphoria no event triggered

jacques deschênes wrote:
> 
> What's wrong with the following code. When I click buttons no event handler
> is called.
> 
> (snip)


 From dialog_demo.exw provided with wxEuphoria:

procedure on_start( atom this, atom event_type, atom id, atom event )
        -- reset the progress counter
        my_progress = 0
        
        -- create a progress dialog
progress = create( wxProgressDialog, {"dialog_demo.exw", "How are we
        doing?", 10, main,
                wxPD_CAN_ABORT + wxPD_ELAPSED_TIME + wxPD_REMAINING_TIME})
                
        -- we'll use a timer to update the progress
        start_timer( timer, 1000, 0 )
        
        -- start the dialog
        if not show_modal( progress ) then
                -- the dialog returned zero, which means the user
                -- hit the cancel button
void = message_box( "Ok, stopped early", "Progress Halted",
                wxICON_WARNING )
                my_progress = 0
        end if
        if platform() = WIN32 then
                delete_instance( progress )
        end if
end procedure
set_event_handler( start, get_id(start), wxEVT_COMMAND_BUTTON_CLICKED,
        routine_id("on_start"))



So it looks like you need to do this:

set_event_handler( Button, get_id(Button), wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("event_handler"))



HTH,

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: wxEuphoria no event triggered

Its what I tried at first but it doesn't work.
I tried:

constant IDD_BUTTON_xxx = new_id()-- declared buttons id like this

-- first try (for each button)
set_event_handler(button, IDD_BUTTON_xxx, ....)
-- second try (for each button)
set_event_handler(button,get_id(button), ....)
-- third try
set_event_handler(dlg,{IDD_BUTTON_xx1,IDD_BUTTON_xx2,IDD_BUTTON_xx3},...)

none of the above works

Greg Haberek wrote:
> 
> jacques deschênes wrote:
> > 
> > What's wrong with the following code. When I click buttons no event handler
> > is called.
> > 
> > (snip)
> 
> 
>  From dialog_demo.exw provided with wxEuphoria:
> 
> }}}
<eucode>
> procedure on_start( atom this, atom event_type, atom id, atom event )
>         -- reset the progress counter
>         my_progress = 0
>         
>         -- create a progress dialog
>         progress = create( wxProgressDialog, {"dialog_demo.exw", "How are we
>         doing?", 10, main,
>                 wxPD_CAN_ABORT + wxPD_ELAPSED_TIME + wxPD_REMAINING_TIME})
>                 
>         -- we'll use a timer to update the progress
>         start_timer( timer, 1000, 0 )
>         
>         -- start the dialog
>         if not show_modal( progress ) then
>                 -- the dialog returned zero, which means the user
>                 -- hit the cancel button
>                 void = message_box( "Ok, stopped early", "Progress Halted",
>                 wxICON_WARNING )
>                 my_progress = 0
>         end if
>         if platform() = WIN32 then
>                 delete_instance( progress )
>         end if
> end procedure
> set_event_handler( start, get_id(start), wxEVT_COMMAND_BUTTON_CLICKED,
>         routine_id("on_start"))
> </eucode>
{{{

> 
> 
> So it looks like you need to do this:
> 
> }}}
<eucode>
> set_event_handler( Button, get_id(Button), wxEVT_COMMAND_BUTTON_CLICKED,
> routine_id("event_handler"))
> </eucode>
{{{

> 
> 
> HTH,
> 
> -Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: wxEuphoria no event triggered

Greg Haberek wrote:
> 
> jacques deschênes wrote:
> > 
> > What's wrong with the following code. When I click buttons no event handler
> > is called.
> > 

(snip)
 
> So it looks like you need to do this:
> 
set_event_handler( Button, get_id(Button), wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("event_handler"))


Greg is correct.  Events don't propagate up to a dialog, so you need to
use the control itself as the event handler.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: wxEuphoria no event triggered

Matt Lewis wrote:
> 
> Greg Haberek wrote:
> > 
> > jacques deschênes wrote:
> > > 
> > > What's wrong with the following code. When I click buttons no event
> > > handler
> > > is called.
> > > 
> 
> (snip)
>  
> > So it looks like you need to do this:
> > 
> }}}
<eucode>
> set_event_handler( Button, get_id(Button), wxEVT_COMMAND_BUTTON_CLICKED,
> routine_id("event_handler"))
> </eucode>
{{{

> 
> Greg is correct.  Events don't propagate up to a dialog, so you need to
> use the control itself as the event handler.
> 
> Matt



That wright. It's what I did at first, but it was apparently not working. The
error was in the event handler itself. I was calling end_dialog() with the this
parameter which is not the dialog but the button.
So the dialog was nerver closing. From there I wrongly concluded that event
handler was not called.
I should had trace my code before going to wrong conclusion.

thanks both of you for your answer.

regards,
Jacques Deschênes

new topic     » goto parent     » topic index » view message » categorize

6. Re: wxEuphoria no event triggered

jacques deschênes wrote:
> 
> That wright. It's what I did at first, but it was apparently not working. The
> error was in the event handler itself. I was calling end_dialog() with the
> this
> parameter which is not the dialog but the button.
> So the dialog was nerver closing. From there I wrongly concluded that event
> handler was not called.
> I should had trace my code before going to wrong conclusion.
> 
> thanks both of you for your answer.

Ah yes, the "this isn't that" paradigm. wxEuphoria has lead me down that road
many, many times. I'm used to the Win32Lib mindset where each control gets its
own events and "pSelf" is what had assigned in setHandler().

Alas, I've now got a rather firm grip on wxEuphoria. I'm enjoying it more every
day!

-Greg

new topic     » goto parent     » topic index » view message » categorize

7. Re: wxEuphoria no event triggered

Greg Haberek wrote:
> 
> jacques deschênes wrote:
> > 
> > That wright. It's what I did at first, but it was apparently not working.
> > The
> > error was in the event handler itself. I was calling end_dialog() with the
> > this
> > parameter which is not the dialog but the button.
> > So the dialog was nerver closing. From there I wrongly concluded that event
> > handler was not called.
> > I should had trace my code before going to wrong conclusion.
> > 
> > thanks both of you for your answer.
> 
> Ah yes, the "this isn't that" paradigm. wxEuphoria has lead me down that road
> many, many times. I'm used to the Win32Lib mindset where each control gets
> its own events and "pSelf" is what had assigned in setHandler().

Yeah, the event handling is a little different.  It should be whatever was
the first parameter in the call to set_event_handler.  So generally, you can
have a control handle its own events, or allow its parent to do that.  

It all makes more sense in an OO environment (which wxWidgets is).  Also,
I've tried to make as many things as possible work similarly to win32lib,
but of course, not every peg manages to fit that round hole, which can lead
to some confusion.  But I think that overall, it's better to be similar,
because it generally leads to a less steep learning curve.

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu