Actions
Buttons explanations » History » Revision 8
« Previous |
Revision 8/10
(diff)
| Next »
iri, 02/22/2011 08:16 PM
Buttons explanations¶
To create any button, you should use _gtkButtonNew
How to create them ?
- A simple button with a label :
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
fun CBbutton (obj, uparam)=
_fooS "The button has been clicked";
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
use _gtkButtonNew function with :
- the channel
- the parent (here a window)
- the label
- the flag. For a simple button, use SCOL_GTK_BUTTON_LABEL
- no supplemental parameter needed, so, nil it's ok */
set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_LABEL nil;
/* Define the callback
use _gtkButtonCB with :
- the Scol object
- the reflex
- any parameter at your convenience
- the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED
It's all*/
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
...
;;
- A button with a mnemonic :
A mnemonic is, by example, a keyboard shortcut
fun CBbutton (obj, uparam)=
_fooS "The button has been clicked";
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a mnemonic button, use SCOL_GTK_BUTTON_MNEMONIC
- no supplemental parameter needed, so, nil it's ok */
set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_MNEMONIC nil;
/* Define the callback
- the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
...
;;
- A button with a stock item :
It is a same code than alabel. The name is the item. That's all.
To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM.
- A button with a link (uri)
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
fun CBbutton (obj, uparam, url)=
_fooS url;
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a link button, use SCOL_GTK_BUTTON_LINK
- set the url to the 4e argument : type S */
set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/";
/* Define the callback
- the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED
- the callback take one supplemental parameter : the url (type S)
Note : this callback works only with GTK+ 3.x. With GTK+ 2.x, you should use SCOL_GTK_BUTTON_CB_CLICKED */
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED;
...
;;
- A button with a check box
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
fun CBbutton (obj, uparam, state)=
_fooS strcat "The state of the check box is " itoa state;
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a check box button, use SCOL_GTK_BUTTON_CHECK
- the 4e arg is the initial state of the check box : 1 (checked) or 0 (unchecked) type I */
set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_CHECK 0;
/* Define the callback
- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED
- the callback take one supplemental parameter : the new state (type I) */
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
...
;;
- A switch button
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
fun CBbutton (obj, uparam, state)=
_fooS strcat "The state of the switch is " itoa state;
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a switch button, use SCOL_GTK_BUTTON_SWITCH
- the 4e arg is the initial state of the switch : 1 (activate) or 0 (deactivate) (type I) */
set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_SWITCH 0;
/* Define the callback
- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED
- the callback take one supplemental parameter : the new state (type I) */
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
...
;;
- Three radios buttons
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
typeof button2 = ObjGtkWidget;;
typeof button3 = ObjGtkWidget;;
fun CBbutton (obj, uparam, state)=
_fooS strcat "The state of the switch is " itoa state;
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a radio button, use SCOL_GTK_BUTTON_RADIO
- the 4e arg is a tuple (type [ObjGtkWidget I]) :
- this Scol object is the group object. At first radio button, it's nil. Next,
others radio buttons belong to the same group have this first object.
- the initial state (1 : checked, 0, unchecked)*/
set button1 = _gtkButtonNew _channel "One" SCOL_GTK_BUTTON_RADIO [nil 1];
set button2 = _gtkButtonNew _channel "Two" SCOL_GTK_BUTTON_RADIO [button1 0];
set button3 = _gtkButtonNew _channel "Three" SCOL_GTK_BUTTON_RADIO [button1 0];
/* Define the callback
- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED
- the callback take one supplemental parameter : the new state (type I)
Note : you can set the flag to SCOL_GTK_BUTTON_CB_RADIO_CHANGED : in this case,
the callback will be called when the radio button will change group */
_gtkButtonCB button1 @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
...
;;
- A toggled button : two states : normal, pressed.
typeof win = ObjGtkWidget;;
typeof button = ObjGtkWidget;;
fun CBbutton (obj, uparam, state)=
_fooS strcat "The state of the state is " itoa state;
_fooS strcat "user param is : " uparam;
0;;
fun main ()=
_showconsole;
/* Create a window ...*/
set win = ...
/* Create the button :
- the flag. For a toggled button, use SCOL_GTK_BUTTON_TOGGLE
- the 4e arg is the initial state of the button : 1 (activate) or 0 (deactivate) (type I) */
set button = _gtkButtonNew _channel win "Click !" SCOL_GTK_BUTTON_TOGGLE 0;
/* Define the callback
- the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED
- the callback take one supplemental parameter : the new state (type I) */
_gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;
...
;;
Return Examples
Updated by iri almost 14 years ago · 8 revisions