Buttons explanations » History » Version 6
  iri, 02/22/2011 05:41 PM 
  
| 1 | 1 | iri | h1. Buttons explanations  | 
|---|---|---|---|
| 2 | |||
| 3 | To create any button, you should use [[Create|_gtkButtonNew]]  | 
||
| 4 | |||
| 5 | How to create them ?  | 
||
| 6 | |||
| 7 | * A simple button with a label :  | 
||
| 8 | |||
| 9 | 2 | iri | <pre><code class="php">  | 
| 10 | 1 | iri | typeof win = ObjGtkWidget;;  | 
| 11 | typeof button = ObjGtkWidget;;  | 
||
| 12 | |||
| 13 | fun CBbutton (obj, uparam)=  | 
||
| 14 | _fooS "The button has been clicked";  | 
||
| 15 | _fooS strcat "user param is : " uparam;  | 
||
| 16 | 0;;  | 
||
| 17 | |||
| 18 | fun main ()=  | 
||
| 19 | _showconsole;  | 
||
| 20 | |||
| 21 | /* Create a window ...*/  | 
||
| 22 | set win = ...  | 
||
| 23 | /* Create the button :  | 
||
| 24 | use _gtkButtonNew function with :  | 
||
| 25 | - the channel  | 
||
| 26 | - the parent (here a window)  | 
||
| 27 | - the label  | 
||
| 28 | - the flag. For a simple button, use SCOL_GTK_BUTTON_LABEL  | 
||
| 29 | - no supplemental parameter needed, so, nil it's ok */  | 
||
| 30 | set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_LABEL nil;  | 
||
| 31 | /* Define the callback  | 
||
| 32 | use _gtkButtonCB with :  | 
||
| 33 | - the Scol object  | 
||
| 34 | - the reflex  | 
||
| 35 | - any parameter at your convenience  | 
||
| 36 | - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED  | 
||
| 37 | It's all*/  | 
||
| 38 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;  | 
||
| 39 | ...  | 
||
| 40 | ;;  | 
||
| 41 | </code></pre>  | 
||
| 42 | 3 | iri | |
| 43 | * A button with a mnemonic :  | 
||
| 44 | A mnemonic is, by example, a keyboard shortcut  | 
||
| 45 | |||
| 46 | <pre><code class="php">  | 
||
| 47 | fun CBbutton (obj, uparam)=  | 
||
| 48 | _fooS "The button has been clicked";  | 
||
| 49 | _fooS strcat "user param is : " uparam;  | 
||
| 50 | 0;;  | 
||
| 51 | |||
| 52 | fun main ()=  | 
||
| 53 | _showconsole;  | 
||
| 54 | |||
| 55 | /* Create a window ...*/  | 
||
| 56 | set win = ...  | 
||
| 57 | /* Create the button :  | 
||
| 58 | 5 | iri | - the flag. For a mnemonic button, use SCOL_GTK_BUTTON_MNEMONIC  | 
| 59 | 3 | iri | - no supplemental parameter needed, so, nil it's ok */  | 
| 60 | set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_MNEMONIC nil;  | 
||
| 61 | /* Define the callback  | 
||
| 62 | - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */  | 
||
| 63 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED;  | 
||
| 64 | ...  | 
||
| 65 | ;;  | 
||
| 66 | </code></pre>  | 
||
| 67 | 4 | iri | |
| 68 | * A button with a stock item :  | 
||
| 69 | It is a same code than alabel. The name is the item. That's all.  | 
||
| 70 | To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM.  | 
||
| 71 | |||
| 72 | * A button with a link (uri)  | 
||
| 73 | |||
| 74 | <pre><code class="php">  | 
||
| 75 | typeof win = ObjGtkWidget;;  | 
||
| 76 | typeof button = ObjGtkWidget;;  | 
||
| 77 | |||
| 78 | fun CBbutton (obj, uparam, url)=  | 
||
| 79 | _fooS url;  | 
||
| 80 | _fooS strcat "user param is : " uparam;  | 
||
| 81 | 0;;  | 
||
| 82 | |||
| 83 | fun main ()=  | 
||
| 84 | _showconsole;  | 
||
| 85 | |||
| 86 | /* Create a window ...*/  | 
||
| 87 | set win = ...  | 
||
| 88 | /* Create the button :  | 
||
| 89 | 5 | iri | - the flag. For a link button, use SCOL_GTK_BUTTON_LINK  | 
| 90 | - set the url to the 4e argument : type S */  | 
||
| 91 | set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/";  | 
||
| 92 | 4 | iri | /* Define the callback  | 
| 93 | - the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED  | 
||
| 94 | 5 | iri | - the callback take one supplemental parameter : the url (type S)  | 
| 95 | Note : this callback works only with GTK+ 3.x. With GTK+ 2.x, you should use SCOL_GTK_BUTTON_CB_CLICKED */  | 
||
| 96 | 1 | iri | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED;  | 
| 97 | ...  | 
||
| 98 | ;;  | 
||
| 99 | </code></pre>  | 
||
| 100 | 5 | iri | |
| 101 | * A button with a check box  | 
||
| 102 | |||
| 103 | <pre><code class="php">  | 
||
| 104 | typeof win = ObjGtkWidget;;  | 
||
| 105 | typeof button = ObjGtkWidget;;  | 
||
| 106 | |||
| 107 | fun CBbutton (obj, uparam, state)=  | 
||
| 108 | _fooS strcat "The state of the check box is " itoa state;  | 
||
| 109 | _fooS strcat "user param is : " uparam;  | 
||
| 110 | 0;;  | 
||
| 111 | |||
| 112 | fun main ()=  | 
||
| 113 | _showconsole;  | 
||
| 114 | |||
| 115 | /* Create a window ...*/  | 
||
| 116 | set win = ...  | 
||
| 117 | /* Create the button :  | 
||
| 118 | - the flag. For a check box button, use SCOL_GTK_BUTTON_CHECK  | 
||
| 119 | - the 4e arg is the initial state of the check box : 1 (checked) or 0 (unchecked) type I */  | 
||
| 120 | set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_CHECK 0;  | 
||
| 121 | /* Define the callback  | 
||
| 122 | - the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED  | 
||
| 123 | - the callback take one supplemental parameter : the new state (type I) */  | 
||
| 124 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;  | 
||
| 125 | ...  | 
||
| 126 | ;;  | 
||
| 127 | </code></pre>  | 
||
| 128 | |||
| 129 | * A switch button  | 
||
| 130 | |||
| 131 | <pre><code class="php">  | 
||
| 132 | typeof win = ObjGtkWidget;;  | 
||
| 133 | typeof button = ObjGtkWidget;;  | 
||
| 134 | |||
| 135 | fun CBbutton (obj, uparam, state)=  | 
||
| 136 | _fooS strcat "The state of the switch is " itoa state;  | 
||
| 137 | _fooS strcat "user param is : " uparam;  | 
||
| 138 | 0;;  | 
||
| 139 | |||
| 140 | fun main ()=  | 
||
| 141 | _showconsole;  | 
||
| 142 | |||
| 143 | /* Create a window ...*/  | 
||
| 144 | set win = ...  | 
||
| 145 | /* Create the button :  | 
||
| 146 | - the flag. For a switch button, use SCOL_GTK_BUTTON_SWITCH  | 
||
| 147 | - the 4e arg is the initial state of the switch : 1 (activate) or 0 (deactivate) (type I) */  | 
||
| 148 | set button = _gtkButtonNew _channel win "Check it !" SCOL_GTK_BUTTON_SWITCH 0;  | 
||
| 149 | /* Define the callback  | 
||
| 150 | - the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED  | 
||
| 151 | - the callback take one supplemental parameter : the new state (type I) */  | 
||
| 152 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;  | 
||
| 153 | ...  | 
||
| 154 | ;;  | 
||
| 155 | </code></pre>  | 
||
| 156 | |||
| 157 | * Three radios buttons  | 
||
| 158 | |||
| 159 | <pre><code class="php">  | 
||
| 160 | 6 | iri | typeof win = ObjGtkWidget;;  | 
| 161 | typeof button = ObjGtkWidget;;  | 
||
| 162 | typeof button2 = ObjGtkWidget;;  | 
||
| 163 | typeof button3 = ObjGtkWidget;;  | 
||
| 164 | |||
| 165 | fun CBbutton (obj, uparam, state)=  | 
||
| 166 | _fooS strcat "The state of the switch is " itoa state;  | 
||
| 167 | _fooS strcat "user param is : " uparam;  | 
||
| 168 | 0;;  | 
||
| 169 | |||
| 170 | fun main ()=  | 
||
| 171 | _showconsole;  | 
||
| 172 | |||
| 173 | /* Create a window ...*/  | 
||
| 174 | set win = ...  | 
||
| 175 | /* Create the button :  | 
||
| 176 | - the flag. For a switch button, use SCOL_GTK_BUTTON_RADIO  | 
||
| 177 | - the 4e arg is a tuple (type [ObjGtkWidget I]) :  | 
||
| 178 | - this Scol object is the group object. At first radio button, it's nil. Next,  | 
||
| 179 | others radio buttons belong to the same group have this first object.  | 
||
| 180 | - the initial state (1 : checked, 0, unchecked)*/  | 
||
| 181 | set button1 = _gtkButtonNew _channel "One" SCOL_GTK_BUTTON_RADIO [nil 1];  | 
||
| 182 | set button2 = _gtkButtonNew _channel "Two" SCOL_GTK_BUTTON_RADIO [button1 0];  | 
||
| 183 | set button3 = _gtkButtonNew _channel "Three" SCOL_GTK_BUTTON_RADIO [button1 0];  | 
||
| 184 | /* Define the callback  | 
||
| 185 | - the flag. To get the toggled signal, use SCOL_GTK_BUTTON_CB_TOGGLED  | 
||
| 186 | - the callback take one supplemental parameter : the new state (type I)  | 
||
| 187 | Note : you can set the flag to SCOL_GTK_BUTTON_CB_RADIO_CHANGED : in this case,  | 
||
| 188 | the callback will be called when the radio button will change group */  | 
||
| 189 | _gtkButtonCB button1 @CBbutton "yes !" SCOL_GTK_BUTTON_CB_TOGGLED;  | 
||
| 190 | ...  | 
||
| 191 | ;;  | 
||
| 192 | </code></pre>  |