PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
refreshing application (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: refreshing application
#62
tim_ecl (User)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
refreshing application 10 Months, 3 Weeks ago Karma: 0  
Hello,
I've got a question about refreshing an application
My problem is the following :
I've created a reader in php-gtk which open a text file on a drive.
Each hour, this file is modified by other person with another application.

So my question is : How can I do to relaunch or re-execute the code of my application automatically each hour (or each time the text file is modified) without closing and relaunching it ?

Thank you a lot.
Vincent
 
  The administrator has disabled public write access.
#63
kksou (Admin)
Admin
Posts: 443
graph
User Online Now Click here to see the profile of this user
Re:refreshing application 10 Months, 3 Weeks ago Karma: 8  
Hi Vincent,

Suppose your code to read the text file and display the content is encapsulated in a function called read_and_display().

1) If you want to refresh it at a fixed interval, e.g. every hour, then use:
Gtk::timeout_add(1000 * 60 * 60, 'read_and_display');

2) If you want to update the content close to "real-time", then use
Gtk::idle_add('check_for_update');
In the function check_for_update(), you can do a check of filesize, etc. If there's any changes, then call the read_and_display() to update the contents.

I've quite a number of sample codes on timeout_add() and idle_add(). Use the Search module to see the entire list.

Regards,
/kksou
 
 
Last Edit: 2008/02/18 02:15 By kksou.
  The administrator has disabled public write access.
#73
tim_ecl (User)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Re:refreshing application 10 Months, 2 Weeks ago Karma: 0  
Thank you for your answer.
However I tried many ways to encapsulate my display code in a function but it didn't work when I want to refresh my application.

I have nearly the same code than your excellent tutorial on how to display an array with progress bar.

1. I define my window
Code:
$window = new GtkWindow();
$window->set_size_request(680, 220);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkHBox());
$eventbox = new GtkEventBox();
2. I open the text file, extract the data I want, store into an array named $array and close the file
Code:
$handle = fopen($path1, "r"«»);
[...]
fclose($handle);
3. I call the function to display my array with the progress bar.
Code:
display_table($vbox, $array);
4. Then I finish my application
Code:
$window->show_all();
Gtk::main();
5. I define the function display table as in your example So which points do you think I have to encapsulate and then call back with timeout_add() ? And when do you think I have to call the function timeout_add()? Thank you Vincent
 
 
Last Edit: 2008/02/20 19:24 By tim_ecl.
  The administrator has disabled public write access.
#80
kksou (Admin)
Admin
Posts: 443
graph
User Online Now Click here to see the profile of this user
Re:refreshing application 10 Months, 2 Weeks ago Karma: 8  
Hi Vincent,

Here's a sample code to show you how it's done:

Sample Code 439: How to update treeview contents at fixed time interval from external data source - Part 1 - total refresh?

Note:
1. The data file is called 'data.txt', in the same directory where you run the sample code.

2. It will be automatically created the first time you run it.

3. Open the data file and change any of the data inside.

4. Within 3 seconds, you will see the changes reflected in the treeview.

Hope this helps.

Regards,
/kksou
 
 
Last Edit: 2008/02/21 04:36 By kksou.
  The administrator has disabled public write access.
#83
tim_ecl (User)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Re:refreshing application 10 Months, 2 Weeks ago Karma: 0  
It works !
Thank you a lot for your help kksou

Regards,
Vincent
 
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved