2.3 QHTML Manual : Events.

So far we are still unable to dynamically interact with the user, as we don't now what he is doing. Actions can be associated to user events. Many widgets have a main event that corresponding to the most obvious use of the widget. All other events can be finely defined using the bind method.

2.3.1 Main events

Most widgets raises an event just after the user has interacted with them :

These are called main events. Most common needs are covered by these events. These events are defined by the action parameter of the object. This parameter can be one of the following :

Where the last two are just shortcuts to objet_variable#method with objet_variable being a reference respectively to the toplevel window or the handle of the widget itself.

local  
  
  class C  
    meth init skip end  
    meth show(Msg) {Show Msg} end  
  end  
  O={New C init}
  
  R
  P={NewPort R}
  thread  
    {ForAll R proc{$ Msg} {Show Msg} end}
  end  
  
  Window={QHTML.build toplevel(td(button(value:"Procedure"  
                                         action:proc{$} {Show 'Procedure'end)
                                  button(value:"Object"  
                                         action:O#show('Object'))
                                  button(value:"Port"  
                                         action:P#'Port')
                                  button(value:"toplevel"  
                                         action:toplevel#set(title:"Toplevel"))
                                  button(value:"widget"  
                                         action:widget#set(value:"widget clicked"))))}
in  
  {Window show}
end

As you can see the toplevel#... and widget#... are just shortcuts. A frequent use is button(value:"Close" action:toplevel#close).

2.3.2 Concurrency between actions

A unique thread is associated to each window : all actions are serialized and executed in the first in first out order. If the window is closed, pending actions are simply ignored.

local  
  Window={QHTML.build toplevel(td(button(value:"1"     action:proc{$} {Delay 2000} {Show 1} end)
                                  button(value:"2"     action:proc{$} {Delay 2000} {Show 2} end)
                                  button(value:"close" action:toplevel#close))}
in  
  {Window show}
end

See specific widget documentations for further details.

2.3.3 Other events

There are many other events that you might want to observe. Widgets have the bind method that allows you to add actions to all these events.

local 
  L                                  
  Window={QHTML.build toplevel(label(value:"Click me !" handle:L))}
in  
  {Window show}
  {C bind(event:onclick
          args:[x y]
          action:proc{$ X Y} {L set(value:"Clicked at "#X#","#Y)} end)}
end 

The event parameter is an atom describing the event you want to listen. Here onclick is the left mouse button being clicked. The action parameter can only take the procedure, method or port message forms. However these events can also receive parameters. The example above shows how the coordinates of the mouse are obtained. The parameters you want to received are specified by the args parameter. See the specific widget documentation to see valid codes. The action is called with as much parameters as specified with args.


Donatien Grolaux
Version 1.3.0 (20010902)