PHP WinBinder: Alternative control 4

From The Uniform Server Wiki
Jump to navigation Jump to search

 

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
 }

Top

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:

  • When the application starts, 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.
  • From the drop down menu “Passwords”, select “Set MySQL password”
    close the pop-up windows and click on the application, an alert pop-up is produced.

Top

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.

Top

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.

Top