mywidget.vala 778 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Gtk;
  2. [GtkTemplate (ui = "/org/foo/my/mywidget.ui")]
  3. public class MyWidget : Box {
  4. public string text {
  5. get { return entry.text; }
  6. set { entry.text = value; }
  7. }
  8. [GtkChild]
  9. private Entry entry;
  10. public MyWidget (string text) {
  11. this.text = text;
  12. }
  13. [GtkCallback]
  14. private void on_button_clicked (Button button) {
  15. print ("The button was clicked with entry text: %s\n", entry.text);
  16. }
  17. [GtkCallback]
  18. private void on_entry_changed (Editable editable) {
  19. print ("The entry text changed: %s\n", entry.text);
  20. notify_property ("text");
  21. }
  22. }
  23. void main(string[] args) {
  24. Gtk.init (ref args);
  25. var win = new Window();
  26. win.destroy.connect (Gtk.main_quit);
  27. var widget = new MyWidget ("The entry text!");
  28. win.add (widget);
  29. win.show_all ();
  30. Gtk.main ();
  31. }