PHP WinBinder: Alternative control 4: Difference between revisions
(New page: {{Nav PHP WinBinder}} '''''Alternative control part 4''''' WinBinder has a few limitations most of which can be worked around. One limitation, there is no direct way to detect that an app...) |
(Proofreading and grammatical changes; some minor reformatting) |
||
Line 2: | Line 2: | ||
'''''Alternative control part 4''''' | '''''Alternative control part 4''''' | ||
WinBinder has a few limitations most of which can be worked around. One limitation | WinBinder has a few limitations, most of which can be worked around. One limitation is that there is no direct way to detect that an application has been restored from the tray menu. | ||
this detection is required for our application. A server's status may have change while our application is minimised to the tray menu. For example a server, may be closed from Apanel and when our application is restored, it requires the buttons and indicators to be updated. | |||
A crude method of perfuming this is to use a refresh button | A crude method of perfuming this is to use a refresh button, but when should a user press this button? This page shows how to detect when the application window regains focus. This allows the refresh button to be replaced with a more useful button. | ||
=== Preliminary === | === Preliminary === | ||
I made copies of test_7.phpw and test_7.bat renamed them to test_8.phpw and test_8.bat respectively. | I made copies of test_7.phpw and test_7.bat and renamed them to test_8.phpw and test_8.bat respectively. | ||
The batch file test_8.bat was edited to run test_8.phpw. | |||
'''''File test_8.phpw'':''' | '''''File test_8.phpw'':''' | ||
Line 23: | Line 22: | ||
global $focus_old; | global $focus_old; | ||
</pre> | </pre> | ||
== Timer == | == Timer == | ||
Line 30: | Line 27: | ||
|-valign="top" | |-valign="top" | ||
| | | | ||
A timer was added | A timer was added to provide a periodic tick; on each tick it calls the handler function. | ||
The handler code checks if it is a timer event and calls our main_timer()function. | |||
When starting or stopping the servers, this function updates a progress indicator and server status. | |||
When starting or stopping the servers this function updates a progress indicator and server status. | |||
The handler code is as shown on the right. | |||
| | | | ||
Line 53: | Line 48: | ||
|-valign="top" | |-valign="top" | ||
| | | | ||
This periodic tick provides an ideal solution for checking a | This periodic tick provides an ideal solution for checking a control's focus. | ||
Function '''wb_get_focus()''' returns a handle to the window or control that has the keyboard focus. | Function '''wb_get_focus()''' returns a handle to the window or control that has the keyboard focus. | ||
Function '''wb_get_text(handle)''' returns the text from a window, control, or control item. If it’s a window returns its caption (UniController) text. | Function '''wb_get_text(handle)''' returns the text from a window, control, or control item. If it’s a window, it returns its caption (UniController) text. | ||
Variable '''$txt''' holds some text of a control currently in focus. | Variable '''$txt''' holds some text of a control currently in focus. | ||
'''$txt != $focus_old''' a new control is in focus. Is it our window | if '''$txt != $focus_old''', a new control is in focus. Is it our window? | ||
If it is call function '''main_init()''' | If it is, call function '''main_init()''' | ||
Save the current focused control text in '''$focus_old''' | Save the current focused control text in '''$focus_old'''. | ||
| | | | ||
Line 87: | Line 82: | ||
</pre> | </pre> | ||
|} | |} | ||
Function main_init() is called only when the new focus is that of our window application. If the focus of a control has not changed there is nothing to do. | Function main_init() is called only when the new focus is that of our window application. If the focus of a control has not changed, there is nothing to do. | ||
For testing add a line just below main_init() as shown below: | For testing, add a line just below main_init() as shown below: | ||
<pre> | <pre> | ||
main_init(); //Yes: Update button and indicators | main_init(); //Yes: Update button and indicators | ||
Line 95: | Line 90: | ||
</pre> | </pre> | ||
=== Test === | === Test === | ||
Line 103: | Line 97: | ||
To see this functionality in action run '''test_8.bat''' | To see this functionality in action run '''test_8.bat''' | ||
Expected results | Expected results: | ||
* When the application starts, an alert pop-up is produced. | * When the application starts, an alert pop-up is produced. | ||
* Minimise and restore application, an alert pop-up is produced. | * Minimise and restore application, an alert pop-up is produced. | ||
* Click outside and then inside the application, an alert pop-up is produced. | * Click outside and then inside the application, an alert pop-up is produced. | ||
* From the drop down menu “Passwords” select “Set MySQL password”<br /> close the pop-up windows and click on the application, an alert pop-up is produced. | * From the drop down menu “Passwords”, select “Set MySQL password”<br /> close the pop-up windows and click on the application, an alert pop-up is produced. | ||
| | | | ||
[[Image:WinBinder_final.gif]] | [[Image:WinBinder_final.gif]] | ||
|} | |} | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
== Final == | == Final == | ||
The above completes this tutorial I was going to leave it there and let you fill in the detail. | The above completes this tutorial. I was going to leave it there and let you fill in the detail. | ||
However I thought better of it and decided that a working reference would be better, allowing you to change it as required. | |||
However thought better of it and decided a working reference would be better allowing you to change it as required. | |||
I made copies of test_7b.phpw, test_8.phpw and test_8.bat renamed them test_9b.phpw, test_9.phpw and test_9_final.bat respectively. | I made copies of test_7b.phpw, test_8.phpw and test_8.bat and renamed them test_9b.phpw, test_9.phpw and test_9_final.bat respectively. | ||
'''''Batch file'':''' test_9_final.bat was modified to have the following content: | '''''Batch file'':''' test_9_final.bat was modified to have the following content: | ||
Line 129: | Line 122: | ||
The batch file was then converted to an executable using [[PHP WinBinder: Project#Create an EXE file | Bat_To_Exe_Converter.exe]]. | The batch file was then converted to an executable using [[PHP WinBinder: Project#Create an EXE file | Bat_To_Exe_Converter.exe]]. | ||
'''''Note'':''' These two files (test_9_final.bat and test_9_final.exe) are included in folder UniServer\plugins\winbinder \'''alt_con_1''' | '''''Note'':''' These two files (test_9_final.bat and test_9_final.exe) are included in folder UniServer\plugins\winbinder \'''alt_con_1'''. Copy them to folder UniServer and run. | ||
=== New window application === | === New window application === | ||
Script test_9b.phpw was converted into a real windows application changes the following server parameters: | Script test_9b.phpw was converted into a real windows application and changes the following server parameters: | ||
* Appache listen port | * Appache listen port | ||
* Apache ssl port | * Apache ssl port | ||
Line 144: | Line 137: | ||
That essentially concludes this tutorial. | That essentially concludes this tutorial. | ||
If the plugin is going to be used only for controlling the server it’s probably worth making a few minor modification explained on the [[PHP WinBinder: Overlay | '''next page''']]. | If the plugin is going to be used only for controlling the server. it’s probably worth making a few minor modification explained on the [[PHP WinBinder: Overlay | '''next page''']]. | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' |
Latest revision as of 18:49, 2 February 2010
|
UniServer 5-Nano PHP WinBinder. |
Alternative control part 4
WinBinder has a few limitations, most of which can be worked around. One limitation is that there is no direct way to detect that an application has been restored from the tray menu.
this detection is required for our application. A server's status may have change while our application is minimised to the tray menu. For example a server, may be closed from Apanel and when our application is restored, it requires the buttons and indicators to be updated.
A crude method of perfuming this is to use a refresh button, but when should a user press this button? This page shows how to detect when the application window regains focus. This allows the refresh button to be replaced with a more useful button.
Preliminary
I made copies of test_7.phpw and test_7.bat and renamed them to test_8.phpw and test_8.bat respectively. The batch file test_8.bat was edited to run test_8.phpw.
File test_8.phpw:
At the end of common variables section add
$focus_old = ""; // Stores caption of focus
At top of handler function add
global $focus_old;
Timer
A timer was added to provide a periodic tick; on each tick it calls the handler function. The handler code checks if it is a timer event and calls our main_timer()function. When starting or stopping the servers, this function updates a progress indicator and server status. The handler code is as shown on the right. |
Old handler if($id ==ID_APP_TIMER){ // 200ms tick main_timer(); // Call main timer function } |
New handler section
This periodic tick provides an ideal solution for checking a control's focus. Function wb_get_focus() returns a handle to the window or control that has the keyboard focus. Function wb_get_text(handle) returns the text from a window, control, or control item. If it’s a window, it returns its caption (UniController) text. Variable $txt holds some text of a control currently in focus. if $txt != $focus_old, a new control is in focus. Is it our window? If it is, call function main_init() Save the current focused control text in $focus_old. |
New handler // Main timer tick call other functions if($id ==ID_APP_TIMER){ // 200ms tick main_timer(); // Call main timer function //Check focus $txt = wb_get_text(wb_get_focus());// Get caption of control in focus if($txt != $focus_old){ // Is it the same window or control in focus if($txt == "UniController"){ //No: Is it our window app main_init(); //Yes: Update button and indicators } $focus_old = $txt; // Save control in focus used for detecting a change } }//END timer tick |
Function main_init() is called only when the new focus is that of our window application. If the focus of a control has not changed, there is nothing to do.
For testing, add a line just below main_init() as shown below:
main_init(); //Yes: Update button and indicators wb_message_box($window, $txt,"FOCUS", WBC_WARNING); // Test Delete this test line
Test
To see this functionality in action run test_8.bat Expected results:
|
Final
The above completes this tutorial. I was going to leave it there and let you fill in the detail. However I thought better of it and decided that a working reference would be better, allowing you to change it as required.
I made copies of test_7b.phpw, test_8.phpw and test_8.bat and renamed them test_9b.phpw, test_9.phpw and test_9_final.bat respectively.
Batch file: test_9_final.bat was modified to have the following content:
cd plugins\winbinder\alt_con_1 ..\php\php.exe -c ..\php\php-wb.ini test_9.phpw
This was moved to folder UniServer and runs the script test_9.phpw from there.
The batch file was then converted to an executable using Bat_To_Exe_Converter.exe.
Note: These two files (test_9_final.bat and test_9_final.exe) are included in folder UniServer\plugins\winbinder \alt_con_1. Copy them to folder UniServer and run.
New window application
Script test_9b.phpw was converted into a real windows application and changes the following server parameters:
- Appache listen port
- Apache ssl port
- MySQL listen port
- MySQL password
This script is run from the drop down menu where appropriate.
Summary
That essentially concludes this tutorial.
If the plugin is going to be used only for controlling the server. it’s probably worth making a few minor modification explained on the next page.