Guest User

Gtk+ / Vala Example

a guest
Aug 27th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. int main(string[] args){
  2. Gtk.init(ref args);
  3.  
  4. // Declare Window
  5. var exampleWindow = new Gtk.Window();
  6. exampleWindow.title = "example";
  7. exampleWindow.border_width = 0;
  8. exampleWindow.window_position = Gtk.WindowPosition.CENTER;
  9. exampleWindow.set_default_size(800, 600);
  10. // End of Declaring Window
  11.  
  12. // Declare Container for Window
  13. var exampleContainer = new Gtk.Grid();
  14. exampleContainer.set_column_homogeneous(false);
  15. exampleContainer.set_hexpand(true);
  16. exampleWindow.add(exampleContainer);
  17.  
  18. // Create / Declare Toolbar
  19. var exampleMainToolbar = new Gtk.Toolbar();
  20. exampleMainToolbar.icon_size = 32;
  21. exampleMainToolbar.show_arrow = false;
  22. exampleMainToolbar.margin = 0;
  23. exampleMainToolbar.set_hexpand(true);
  24.  
  25. // Search Box
  26. var exampleSearchBoxContainer = new Gtk.ToolItem();
  27. exampleSearchBoxContainer.set_margin_left(6);
  28.  
  29. var exampleSearchBox = new Gtk.Entry();
  30. exampleSearchBox.set_text("Search Your Tasks..."); // Set the search box text to...
  31. exampleSearchBox.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, Gtk.Stock.FIND); // Set the icon on the right of the entry box to be the clear button
  32. exampleSearchBox.icon_press.connect((pos, event) => {
  33. if (pos == Gtk.EntryIconPosition.SECONDARY){ // If we in fact clicked on the Clear button
  34. exampleSearchBox.set_text("Search Your Tasks"); // Reset the search box text
  35. }
  36. else{ // If we didn't click the clear button a.k.a we clicked elsewhere on the input
  37. exampleSearchBox.set_text(""); // Clear the input.
  38. }
  39. });
  40. // End of Search Box
  41.  
  42. // Global menu
  43.  
  44. var exampleGlobalMenuContainer = new Gtk.ToolItem();
  45. exampleGlobalMenuContainer.tooltip_text = "Menu";
  46.  
  47. var exampleGlobalMenuButton = new Gtk.ToolButton.from_stock(Gtk.Stock.PROPERTIES);
  48. var exampleGlobalMenu = new Gtk.Menu();
  49.  
  50. exampleGlobalMenuButton.clicked.connect(() => {
  51. // I shall do nothing...for now
  52. });
  53.  
  54. var exampleGlobalMenu_SettingsMenuItem = new Gtk.MenuItem();
  55. exampleGlobalMenu_SettingsMenuItem.set_label("Settings");
  56. exampleGlobalMenu.attach(exampleGlobalMenu_SettingsMenuItem, 0, 0, 0, 0);
  57.  
  58.  
  59. // End of Global menu
  60. exampleSearchBoxContainer.add(exampleSearchBox); // Insert the search box into the toolitem container
  61. exampleGlobalMenuContainer.add(exampleGlobalMenuButton); // Insert the menu button and menu into the menu container
  62. exampleGlobalMenuContainer.add(exampleGlobalMenu); // Insert the menu into the menu container
  63. exampleMainToolbar.insert(exampleSearchBoxContainer, 0); // Insert the search box container to the left in the toolbar
  64. exampleMainToolbar.insert(exampleGlobalMenuContainer, 1); // Insert the global menu container to the right in the toolbar
  65.  
  66.  
  67. // End of Creating / Declaring Toolbar
  68.  
  69. exampleContainer.add(exampleMainToolbar); // Add the toolbar to the grid container
  70. exampleWindow.add(exampleContainer); // Add the grid container to the window
  71. exampleWindow.show_all();
  72.  
  73. Gtk.main();
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment