File: builderTest.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (56 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module builder.builderTest;

import gio.Application: GioApplication = Application;

import gtk.Application;
import gtk.ApplicationWindow;
import gtk.Builder;
import gtk.Button;

import std.stdio;
import core.stdc.stdlib;

/**
 * Usage ./gladeText /path/to/your/glade/file.glade
 *
 */

int main(string[] args) {
	string gladefile;
	if(args.length > 1) {
		writefln("Loading %s", args[1]);
		gladefile = args[1];
		args = args[0..1];
	} else {
		writeln("No glade file specified, using default \"builderTest.glade\"");
		gladefile = "builderTest.glade";
	}
	auto application = new Application("org.gtkd.demo.builder.builderTest", GApplicationFlags.FLAGS_NONE);

	void buildAndDisplay(GioApplication a) {
		auto builder = new Builder();
		if( ! builder.addFromFile(gladefile) ) {
			writeln("Oops, could not create Glade object, check your glade file ;)");
			exit(1);
		}
		auto window = cast(ApplicationWindow)builder.getObject("window");
		if (window !is null) {
			window.setApplication(application);
			window.setTitle("This is a glade application window");
			auto button = cast(Button)builder.getObject("button");
			if(button !is null) {
				button.addOnClicked( delegate void(Button aux){ a.quit(); } );
				window.showAll();
			} else {
				writeln("No button in the window?");
				exit(1);
			}
		} else {
			writeln("No window?");
			exit(1);
		}
	}

	application.addOnActivate(&buildAndDisplay);
	return application.run(args);
}