PHP WinBinder: Basic IO: Difference between revisions

Jump to navigation Jump to search
Proofreading and grammatical changes; some minor reformatting
(New page: {{Nav PHP WinBinder}} '''''Basic Input and Output''''' Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating somet...)
 
(Proofreading and grammatical changes; some minor reformatting)
 
Line 2: Line 2:
'''''Basic Input and Output'''''
'''''Basic Input and Output'''''


Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating something happened when a button is click. May be the result requires a more significant attention grabber such as an alert box.
Most applications are designed to provide some form of interaction with a user. This can be a simple change of text indicating something happened when a button is click. Maybe the result requires a more significant attention grabber such as an alert box.


This page shows how to create three changeable text areas, three buttons and an alert pop-up box
This page shows how to create three changeable text areas, three buttons and an alert pop-up box.


== Cotrol Creation ==
== Control Creation ==
The manual provides this function to create controls:
The manual provides this function to create controls:
{|
{|
Line 15: Line 15:
</pre>
</pre>
|}
|}
On first encounter it looks intimidating hence I have reduced it to give this:
On first encounter it looks intimidating, so I have reduced it to give this:
{|
{|
|-
|-
Line 35: Line 35:
|'''id'''|| is an integer that identifies the control. It must be unique if the control is to be processed by a callback function.
|'''id'''|| is an integer that identifies the control. It must be unique if the control is to be processed by a callback function.
|}
|}
That’s all very well but how does it all fit together?
That’s all very well, but how does it all fit together?


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Labels ==
== Labels ==
Labels are areas on a window containing text.
Labels are areas on a window containing text.


They can be static (not changeable) however once given an ID and optionally grabbing their handle you can have dynamic text areas hence dynamic feedback to a user.
They can be static (not changeable), however once given an ID and optionally grabbing their handle, you can have dynamic text areas, meaning dynamic feedback to a user.


Example 2 defines the following labels:
Example 2 defines the following labels:
Line 59: Line 58:
* Each label has a unique ID 101,102,103
* Each label has a unique ID 101,102,103
* handles are captured in variables $label1,$label2 and $label3 these are optional
* handles are captured in variables $label1,$label2 and $label3 these are optional
* You can find a components handle using it's ID for example '''wb_get_control($window, 102)'''
* You can find a components handle using its ID, for example '''wb_get_control($window, 102)'''
|}
|}


Line 76: Line 75:
|}
|}


OK! So where does this code go? Place it it section two of the template. Once the main window is created the components need to be created before they can be used.
OK! So where does this code go? Place it in section two of the template. Once the main window is created the components need to be created before they can be used.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
 
== Push Buttons ==
== Push Bottoms ==
Strange as this may seem, push buttons are similar to labels in terms of creation. WinBinder has unified the creation process so there are only a few logical choices.
Strange as this may seem push buttons are similar to labels in terms of creation. WinBinder has unified the creation process hence only a few logical chances.


Example 2 defines the following push buttons:
Example 2 defines the following push buttons:
Line 95: Line 93:
</pre>
</pre>
|
|
* Each push button has a unique ID 201,202,203
* Each push button has a unique ID: 201,202,203
* No need to capture handles. Each button is traceable by its ID
* No need to capture handles. Each button is traceable by its ID
|}
|}
Line 104: Line 102:
|'''parent'''|| handle to the WinBinder object '''$mainwin'''
|'''parent'''|| handle to the WinBinder object '''$mainwin'''
|-
|-
|'''ctlclass'''|| is the class of the control or object to be created '''PushButton'''
|'''ctlclass'''|| is the class of the control or object to be created: '''PushButton'''
|-
|-
|'''caption&nbsp;'''|| A string (Apache,MySQL and Alert)
|'''caption&nbsp;'''|| A string (Apache,MySQL and Alert)
|-
|-
|'''xpos,'''|| '''ypos''', '''width''' and '''height''' Tweak the values to position a button. Note if a button is too small text is clipped.  
|'''xpos,'''|| '''ypos''', '''width''' and '''height''' Tweak the values to position a button. Note: if a button is too small, text is clipped.  
|-
|-
|'''id'''|| A unique integer identifies a control. Start from 100 to avoid clashes. Say labels will be 100 push buttons start at 200 etc
|'''id'''|| A unique integer identifies a control. Start from 100 to avoid clashes. Say labels begin at 100, push buttons start at 200, etc.
|}
|}


OK! So where does this code go? Same place as the labels in section two of the template.  
Where does this code go? Same place as the labels, in section two of the template.  


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Interaction ==
== Interaction ==
{|
{|
|-valign="top"
|-valign="top"
|
|
At this stage running the script will produce a window as shown on the right.
At this stage, running the script will produce a window as shown on the right.


Although the buttons are active they appear to do nothing when clicked.
Although the buttons are active they appear to do nothing when clicked.


However behind the scenes they call function '''process_main()''' with parameters '''$window''' and '''$id''' ($id = ID of the button). The function contains no supporting code hence just returns. Lets specify what the buttons will do and then add code to the function.  
However behind the scenes they call function '''process_main()''' with parameters '''$window''' and '''$id''' ($id = ID of the button). The function contains no supporting code hence just returns. Let's specify what the buttons will do and then add code to the function.  
   
   
'''''Button Specification'''''
'''''Button Specification'''''
* '''Apache''' When clicked changes label1 to display “Apache Port = 80”  
* '''Apache''' When clicked changes label1 to display “Apache Port = 80”  
* '''MySQL''' When clicked changes label2 to display “MySQL Port = 3306”
* '''MySQL''' When clicked changes label2 to display “MySQL Port = 3306”
* '''Alert''' When clicked produces a pop-up alert box with message “Cannot run two servers on port 80” also changes both labels back to initial condition.
* '''Alert''' When clicked produces a pop-up alert box with message “Cannot run two servers on port 80” and also changes both labels back to initial condition.
|
|
[[Image:WinBinder_2.gif]]
[[Image:WinBinder_2.gif]]
|}
|}
'''''[[#top | Top]]'''''
 
=== Handler function - code ===
=== Handler function - code ===
To resolve ID’s the handler function uses a switch statement.
To resolve IDs, the handler function uses a switch statement.


This is not a strict requirement you can use whatever method that suites your style of programming.
This is not a strict requirement. You can use whatever method that suits your style of programming.


However in response to ID=IDCLOSE you must run function wb_destroy_window($window)  
However in response to ID=IDCLOSE, you must run function wb_destroy_window($window)  


'''''[[#top | Top]]'''''
==== Changing Label text ====
==== Changing Label text ====
Our specification requires changing label text WinBinder provides the following general function:
Our specification requires changing the label text. WinBinder provides the following general function:
{|
{|
|-
|-
Line 155: Line 151:
|-
|-
|
|
A simpler description as follows:
A simpler description is:
|
|
<pre>
<pre>
Line 161: Line 157:
</pre>
</pre>
|}
|}
When the labels are created their handles are captured in variables these are global hence can be used in the Handler Function.
When the labels are created their handles are captured in variables. These are global and can be used in the Handler Function.


If the handles were not assigned to variables they can be found using this function:
If the handles were not assigned to variables they can be found using this function:
Line 176: Line 172:
|}
|}
See example below:
See example below:
'''''[[#top | Top]]'''''


==== Apache button ====
==== Apache button ====
Line 190: Line 184:
</pre>
</pre>
|
|
* When Apache Button is clicked case 201 (Button ID=201)is true.
* When Apache Button is clicked, case 201 (Button ID=201) is true.
* The label text is updated with function wb_set_text(). The label handle is obtained using its ID (101)
* The label text is updated with function wb_set_text(). The label handle is obtained using its ID (101)
* break exits switch
* break exits switch
|}
|}


'''''[[#top | Top]]'''''
==== MySQL Button ====
==== MySQL Button ====
Handler code for MySQL button:
Handler code for MySQL button:
Line 208: Line 201:
</pre>
</pre>
|
|
* When MySQL Button is clicked case 202 (Button ID=202)is true.
* When MySQL Button is clicked, case 202 (Button ID=202) is true.
* global $label2; Gives access to label 2 handle  
* global $label2; Gives access to label 2 handle  
* The label text is updated with function wb_set_text(). The label handle is directly used
* The label text is updated with function wb_set_text(). The label handle is directly used
* break exits switch
* break exits switch
|}
|}
'''''[[#top | Top]]'''''


==== Alert Button ====
==== Alert Button ====
Line 234: Line 225:
</pre>
</pre>
|
|
* When Alert Button is clicked case 203 (Button ID=203)is true.
* When Alert Button is clicked, case 203 (Button ID=203) is true.
* global $label1; Gives access to label 1 handle  
* global $label1; Gives access to label 1 handle  
* global $label2; Gives access to label 2 handle  
* global $label2; Gives access to label 2 handle  
Line 241: Line 232:
* break exits switch
* break exits switch
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Test 2 Script ==
== Test 2 Script ==
Final script as shown below:
The final script is:
{|
{|
|-valign="top"
|-valign="top"
Line 324: Line 315:


== Summary ==
== Summary ==
This page introduced two basic controls, labels and push buttons. Even with this minimum set of controls it is possible to produce useful applications.
This page introduced two basic controls: labels and push buttons. Even with this minimum set of controls: it is possible to produce useful applications.


What’s important you really do not require all the fancy bells and whistles as found on most windows applications.
What’s important is that you really do not require all the fancy bells and whistles as found on most windows applications.
That said WinBinder provides a vast array of controls you can use these are fully described in the documentation.
That said, WinBinder provides a vast array of controls you can use. These are fully described in the documentation.


The [[PHP WinBinder: Text input | '''next page''']] covers text input.  
The [[PHP WinBinder: Text input | '''next page''']] covers text input.  

Navigation menu