Guest User

Untitled

a guest
Jul 9th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 3.37 KB | None | 0 0
  1. /* Copyright 2012 Andrew Higginson
  2.  *
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7. */
  8.  
  9. public class App : Object {
  10.  
  11.     private Gtk.Window window_main;
  12.     private Gtk.MenuBar menubar;
  13.     private Gtk.MenuItem menubar_item;
  14.     private Gtk.Menu menu;
  15.     private ContainerMenuItem menuitem_button;
  16.     private Gtk.VBox vbox;
  17.  
  18.     public App(string datadir) {
  19.         this.create_widgets();
  20.         this.connect_signals();
  21.        
  22.         this.window_main.get_settings().gtk_theme_name = "Adwaita";
  23.        
  24.         this.window_main.show_all();
  25.     }
  26.  
  27.     /* Private Functions */
  28.  
  29.     private void create_widgets() {
  30.         this.window_main = new Gtk.Window();
  31.         this.window_main.set_default_size(200, 200);
  32.        
  33.         this.vbox = new Gtk.VBox(false, 6);
  34.        
  35.         // In Menu
  36.        
  37.         var entry = new Gtk.Entry();
  38.         entry.set_text("Hello!");
  39.         entry.set_name("entry");
  40.         entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "edit-copy");
  41.         entry.set_position(3);
  42.  
  43.         var button = new Gtk.Button.with_label("Hi");
  44.         button.set_name("button");
  45.        
  46.         var scale = new Gtk.Scale.with_range(Gtk.Orientation.HORIZONTAL, 0, 100, 1);
  47.         scale.set_size_request(200, -1);
  48.         scale.draw_value = false;
  49.        
  50.         // Not In Menu
  51.         var entry2 = new Gtk.Entry();
  52.         entry2.set_text("Hello!");
  53.         entry2.set_name("entry");
  54.         entry2.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "edit-copy");
  55.         entry2.set_position(3);
  56.        
  57.         var button2 = new Gtk.Button.with_label("Hi");
  58.         button2.set_name("button");
  59.        
  60.         var scale2 = new Gtk.Scale.with_range(Gtk.Orientation.HORIZONTAL, 0, 100, 1);
  61.         scale2.set_size_request(200, -1);
  62.         scale2.draw_value = false;
  63.        
  64.         this.menubar = new Gtk.MenuBar();
  65.         this.menubar_item = new Gtk.MenuItem.with_label("Hiya");
  66.         this.menu = new Gtk.Menu();
  67.         this.menuitem_button = new ContainerMenuItem(Gtk.Orientation.HORIZONTAL, 6);
  68.  
  69.         this.menuitem_button.pack_start(entry, false, false);
  70.         this.menuitem_button.pack_start(button, false, false);
  71.         this.menuitem_button.pack_start(scale, false, false);
  72.        
  73.         var hbox = new Gtk.HBox(false, 6);
  74.         hbox.pack_start(entry2, false, false);
  75.         hbox.pack_start(button2, false, false);
  76.         hbox.pack_start(scale2, false, false);
  77.         hbox.margin_top = 50;
  78.        
  79.         this.menu.append(this.menuitem_button);
  80.         this.menubar_item.set_submenu(this.menu);
  81.         this.menubar.append(this.menubar_item);
  82.        
  83.         this.vbox.pack_start(this.menubar, false, false);
  84.         this.vbox.pack_start(hbox, false, false);
  85.  
  86.         this.window_main.add(this.vbox);
  87.     }
  88.    
  89.     private void connect_signals() {
  90.         this.window_main.delete_event.connect(this.on_window_main_delete_event);
  91.     }
  92.    
  93.        
  94.     /* Callbacks */
  95.     private bool on_window_main_delete_event(Gdk.EventAny event) {
  96.         this.quit();
  97.         return false;
  98.     }
  99.  
  100.     /* Public Functions */
  101.     public void quit() {
  102.         Gtk.main_quit();
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment