Changes

Jump to navigation Jump to search

PHP WinBinder: Basic IO

105 bytes removed, 13:58, 29 January 2010
Proofreading and grammatical changes; some minor reformatting
'''''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 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.
== Cotrol Control Creation ==
The manual provides this function to create controls:
{|
</pre>
|}
On first encounter it looks intimidating hence , so I have reduced it to give this:
{|
|-
|'''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?
'''''[[#top | Top]]'''''
 
== Labels ==
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 , meaning dynamic feedback to a user.
Example 2 defines the following labels:
* Each label has a unique ID 101,102,103
* handles are captured in variables $label1,$label2 and $label3 these are optional
* You can find a components handle using it's its ID , for example '''wb_get_control($window, 102)'''
|}
|}
OK! So where does this code go? Place it 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]]'''''
 == Push Bottoms Buttons ==Strange as this may seem , push buttons are similar to labels in terms of creation. WinBinder has unified the creation process hence so there are only a few logical chanceschoices.
Example 2 defines the following push buttons:
</pre>
|
* Each push button has a unique ID : 201,202,203
* No need to capture handles. Each button is traceable by its ID
|}
|'''parent'''|| handle to the WinBinder object '''$mainwin'''
|-
|'''ctlclass'''|| is the class of the control or object to be created : '''PushButton'''
|-
|'''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.
|-
|'''id'''|| A unique integer identifies a control. Start from 100 to avoid clashes. Say labels will be begin at 100 , push buttons start at 200 , etc.
|}
OK! So where Where does this code go? Same place as the labels , in section two of the template.
'''''[[#top | Top]]'''''
 
== Interaction ==
{|
|-valign="top"
|
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.
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 Let's specify what the buttons will do and then add code to the function.
'''''Button Specification'''''
* '''Apache''' When clicked changes label1 to display “Apache Port = 80”
* '''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” and also changes both labels back to initial condition.
|
[[Image:WinBinder_2.gif]]
|}
'''''[[#top | Top]]'''''
=== Handler function - code ===
To resolve ID’s IDs, the handler function uses a switch statement.
This is not a strict requirement you . You can use whatever method that suites suits your style of programming.
However in response to ID=IDCLOSE , you must run function wb_destroy_window($window)
'''''[[#top | Top]]'''''
==== Changing Label text ====
Our specification requires changing the label text . WinBinder provides the following general function:
{|
|-
|-
|
A simpler description as followsis:
|
<pre>
</pre>
|}
When the labels are created their handles are captured in variables these . These are global hence and can be used in the Handler Function.
If the handles were not assigned to variables they can be found using this function:
|}
See example below:
 
'''''[[#top | Top]]'''''
==== Apache button ====
</pre>
|
* 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)
* break exits switch
|}
'''''[[#top | Top]]'''''
==== MySQL Button ====
Handler code for MySQL button:
</pre>
|
* When MySQL Button is clicked , case 202 (Button ID=202)is true.
* global $label2; Gives access to label 2 handle
* The label text is updated with function wb_set_text(). The label handle is directly used
* break exits switch
|}
 
'''''[[#top | Top]]'''''
==== Alert Button ====
</pre>
|
* When Alert Button is clicked , case 203 (Button ID=203)is true.
* global $label1; Gives access to label 1 handle
* global $label2; Gives access to label 2 handle
* break exits switch
|}
 
'''''[[#top | Top]]'''''
 
== Test 2 Script ==
Final The final script as shown belowis:
{|
|-valign="top"
== 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.
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 . These are fully described in the documentation.
The [[PHP WinBinder: Text input | '''next page''']] covers text input.

Navigation menu