Пример #1
0
func main() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new socket:
	s, err := gtkx.SocketNew()
	if err != nil {
		log.Fatal("Unable to create socket:", err)
	}

	//Adding the socket to the window:
	win.Add(s)

	// Getting the socketId:
	sId := s.GetId()
	fmt.Printf("Our socket: %v\n", sId)

	//Building a Plug for our Socket:
	p, err := gtkx.PlugNew(sId)
	if err != nil {
		log.Fatal("Unable to create plug:", err)
	}

	//Building a Button for our Plug:
	b, err := gtk.ButtonNewWithLabel("Click me .)")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}

	//Click events for the Button:
	b.Connect("clicked", func() {
		fmt.Printf("Yeah, such clicks!\n")
	})

	//Adding the Button to the Plug:
	p.Add(b)
	//Displaying the Plug:
	p.ShowAll()

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}
Пример #2
0
func main() {
	/*
	   We set an environment variable so that we don't get bothered by xterm accessibility warnings
	   like "** (xterm:16917): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-QznzMfGEXB: Connection refused"
	   See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15154
	*/
	os.Setenv("NO_AT_BRIDGE", "1")

	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new socket:
	s, err := gtkx.SocketNew()
	if err != nil {
		log.Fatal("Unable to create socket:", err)
	}

	//Adding the socket to the window:
	win.Add(s)

	// Getting the socketId:
	sId := s.GetId()
	fmt.Printf("Our socket: %v\n", sId)

	// Embedding something in the socket:
	xterm := exec.Command("xterm", "-into", gtkx.WindowIdToString(sId))

	go func() {
		xterm.Run()
	}()

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}