Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Updating Gtk2::Ex::Graph::GD

by sam_bakki (Pilgrim)
on Aug 23, 2011 at 11:54 UTC ( #921874=note: print w/ replies, xml ) Need Help??


in reply to Re: Updating Gtk2::Ex::Graph::GD
in thread Updating Gtk2::Ex::Graph::GD

Hi

Today , I also was looking in to Gtk2::Ex::Graph::GD module and I do experienced graph update problem. After debugging I have solved it

Trick is you need create new Gtk2::Ex::Graph::GD object every time when you want to update GUI in Gtk

refer following code which works for me in ActivePerl 5.12 in windows 7

use strict; use warnings; use threads; use threads::shared; use Thread::Queue; use Glib qw/TRUE FALSE/; use Gtk2 -init; use Data::Dumper; use Gtk2::Ex::Graph::GD; use GD::Graph; use GD::Graph::Data; my @xlegend = (1..10); $|=1; my $gui; my $table; sub on_window1_destroy { my $widget = shift @_; #my $userData = shift @_; Gtk2->main_quit; } sub updateGraph { print "\n called"; my @data1 = map(rand(100),(1..10)); my @graph_data = (\@xlegend,\@data1,); my $data = GD::Graph::Data->new(\@graph_data) or die GD::Graph::Data-> +error; my $graph = Gtk2::Ex::Graph::GD->new(500, 300, 'lines'); my $image = $graph->get_image($data); $table->attach_defaults($image,1,2,1,2); return TRUE; } #Main Glib::Object->set_threadsafe (TRUE); $gui = Gtk2::Builder->new(); $gui->add_from_file('chart.glade'); $gui->connect_signals(undef); $table=$gui->get_object('table1'); &updateGraph(); Glib::Timeout->add (1000,\&updateGraph); Gtk2->main();

Note: Not a very good code. ONly shared for reference

Enjoy :)


Comment on Re^2: Updating Gtk2::Ex::Graph::GD
Download Code
Re^3: Updating Gtk2::Ex::Graph::GD
by zentara (Archbishop) on Aug 23, 2011 at 12:33 UTC
    Trick is you need create new Gtk2::Ex::Graph::GD object every time when you want to update GUI in Gtk

    That makes sense to me, since all Gtk2 is doing is displaying a graphic generated by GD. If you make changes to your graph data, and want the Gtk2 gui updated, you must have GD rebuild the new graph.

    There may be a more efficient method than creating a new Gtk2::Ex::Graph::GD object every time, like reusing the existing object, clearing out it's data, and making a new graph.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://921874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-08-30 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls