[Vala] Snippet: Dazzle.GraphView hello world



Because i could not find one and i wanted to play around with it, I
wrote a hello-world-style application that uses libdazzle's graphview
courtesy to chergert.

I figured this could be useful to other people who want to get started
with it and prefer not to dig through gnome-usage's source.


Compile with: valac --pkg gtk+-3.0 --pkg libdazzle-1.0 <file.vala>

 1. publicstaticintmain(string[]argv){
 2. Gtk.init(refargv);
 3. varwin =newGtk.Window();
 4. vargv =newDazzle.GraphView();
 5. vargm =newDazzle.GraphModel();
 6. varb =newGtk.Button.with_label("add datapoint");
 7. varbox =newGtk.Box(Gtk.Orientation.VERTICAL,10);
 8. vargc =newDazzle.GraphColumn("The Value",Type.from_name("gdouble"));
 9. vargr =newDazzle.GraphLineRenderer();
10. varl =newGtk.Label("asdf");
11.  
12. gm.set_timespan(TimeSpan.MINUTE);
13. gm.set_max_samples(30);
14. gm.add_column(gc);
15.  
16. b.clicked.connect(()=>{
17. Dazzle.GraphModelItergi;
18. gm.push(outgi ,GLib.get_monotonic_time());
19. Dazzle.GraphModel.iter_set_value(gi,0,Random.double_range(0,100));
20. message("added");
21. });
22. gm.changed.connect(()=>{message("changed");});
23. box.expand=true;
24. gv.expand=true;
25. box.pack_start(b,false,false,0);
26. Gdk.RGBA linecol =Gdk.RGBA();
27. linecol.red =1.0;linecol.green=0.0;linecol.blue=0.0;linecol.alpha=1.0;
28. gr.stroke_color_rgba=linecol;
29. gr.line_width =1;
30. gr.column =0;
31. gv.add_renderer(gr);
32. box.pack_start(gv,true,true,0);
33. box.pack_start(l,false,false,0);
34. gv.set_model (gm);
35. win.add(box);
36. win.show_all();
37. win.delete_event.connect(()=>{Gtk.main_quit();returntrue;});
38.
39. Gtk.main();
40. return0;
41. }

Enjoy :)

Attachment: pEpkey.asc
Description: application/pgp-keys



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]