Skip to content

Instantly share code, notes, and snippets.

@Frankity
Forked from rickybassom/main.vala
Created October 7, 2016 01:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frankity/58d26f62be67b590a486ba31efaf01ab to your computer and use it in GitHub Desktop.
Save Frankity/58d26f62be67b590a486ba31efaf01ab to your computer and use it in GitHub Desktop.
Simple Gtk.Application example in vala
using Gtk;
public class MyApplication : Gtk.Application {
public MyApplication () {
Object(application_id: "testing.my.application",
flags: ApplicationFlags.FLAGS_NONE);
}
protected override void activate () {
// Create the window of this application and show it
Gtk.ApplicationWindow window = new Gtk.ApplicationWindow (this);
window.set_default_size (800, 600);
window.window_position = WindowPosition.CENTER;
window.set_border_width(10);
// add headerbar with button
Gtk.HeaderBar headerbar = new Gtk.HeaderBar();
headerbar.show_close_button = true;
headerbar.title = "Window";
window.set_titlebar(headerbar);
Gtk.Button button = new Gtk.Button.with_label ("About");
button.clicked.connect ( () =>{
// show about dialog on click
string[] authors = { "GNOME Documentation Team", null };
string[] documenters = { "GNOME Documentation Team", null };
Gtk.show_about_dialog (window,
"program-name", ("GtkApplication Example"),
"copyright", ("Copyright \xc2\xa9 2012 GNOME Documentation Team"),
"authors", authors,
"documenters", documenters,
"website", "http://developer.gnome.org",
"website-label", ("GNOME Developer Website"),
null);
});
// add button to headerbar
headerbar.pack_end(button);
// create stack
Gtk.Stack stack = new Gtk.Stack();
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
// giving widgets to stack
Gtk.Label label = new Gtk.Label("");
label.set_markup("<big>A label</big>");
stack.add_titled(label, "label", "A label");
Gtk.Label label2 = new Gtk.Label("");
label2.set_markup("<big>Another label</big>");
stack.add_titled(label2, "label2", "Another label");
// add stack(contains widgets) to stackswitcher widget
Gtk.StackSwitcher stack_switcher = new Gtk.StackSwitcher();
stack_switcher.halign = Gtk.Align.CENTER;
stack_switcher.set_stack(stack);
// add stackswitcher to vertical box
Gtk.Box vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
vbox.pack_start(stack_switcher, false, false, 0);
vbox.pack_start(stack, false, false, 10);
window.add(vbox);
window.show_all ();
}
public static int main (string[] args) {
MyApplication app = new MyApplication ();
return app.run (args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment