maheswaranapk

Sample Welcome Screen

Jan 14th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.69 KB | None | 0 0
  1. using Gtk;
  2. using Granite.Widgets;
  3.  
  4. public class SimpleGranite:Granite.Application{
  5.  
  6.     class ApplicationWindow:Gtk.Window {
  7.  
  8.         Welcome welcomeLayout;
  9.         int count = 3;
  10.  
  11.         public ApplicationWindow() {
  12.  
  13.             destroy.connect(main_quit);
  14.             set_titlebar(header());
  15.             set_default_size(500, 300);
  16.  
  17.             welcomeLayout = new Granite.Widgets.Welcome ("Select A Device", "List of all available devices.");
  18.  
  19.             for(int i = 0; i < count; i++ ) {
  20.                 welcomeLayout.append ("tag-new", "$ " + i.to_string(), "");
  21.             }
  22.  
  23.             this.add(welcomeLayout);
  24.         }
  25.  
  26.         public void addAWelcomeButton(){
  27.             count++;
  28.             welcomeLayout.append ("tag-new", "$ " + count.to_string(), "");
  29.         }
  30.  
  31.         public void deleteAWelcomeButton(){
  32.             count--;
  33.             welcomeLayout.remove_item(count);
  34.         }
  35.  
  36.         private Gtk.HeaderBar header() {
  37.             var header = new Gtk.HeaderBar();
  38.  
  39.             header.set_title("Welcome Screen");
  40.             header.set_show_close_button(true);
  41.             header.spacing = 0;
  42.            
  43.             Gtk.Image addImg = new Gtk.Image.from_icon_name ("tag-new", Gtk.IconSize.MENU);
  44.             Gtk.ToolButton addButton = new Gtk.ToolButton (addImg, null);
  45.             addButton.clicked.connect (() => {
  46.                 addAWelcomeButton();
  47.             });
  48.                    
  49.             Gtk.Image deleteImg = new Gtk.Image.from_icon_name ("process-stop", Gtk.IconSize.MENU);
  50.             Gtk.ToolButton  deleteButton = new Gtk.ToolButton (deleteImg, null);
  51.             deleteButton.clicked.connect (() => {
  52.                 deleteAWelcomeButton();
  53.             });
  54.        
  55.             header.pack_start(addButton);
  56.             header.pack_end(deleteButton);
  57.  
  58.             return header;
  59.         }
  60.     }
  61.  
  62.     public static void main(string[] args) {
  63.         new SimpleGranite().run(args);
  64.         Gtk.init(ref args);
  65.  
  66.         Window window = new ApplicationWindow();
  67.         window.show_all();
  68.  
  69.         Gtk.main();
  70.     }
  71. }
Add Comment
Please, Sign In to add comment