Exemplo n.º 1
0
func setup_box(orient gtk.Orientation) *gtk.Box {
	box, err := gtk.BoxNew(orient, 0)
	if err != nil {
		log.Fatal("Unable to create box:", err)
	}
	return box
}
Exemplo n.º 2
0
func setupPropertyCheckboxes(tv *gtk.TextView, outer *gtk.Box, props []*BoolProperty) {
	box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	for _, prop := range props {
		chk, _ := gtk.CheckButtonNewWithLabel(prop.Name)
		// initialize the checkbox with the property's current value
		chk.SetActive(prop.Get())
		p := prop // w/o this all the checkboxes will toggle the last property in props
		chk.Connect("toggled", func() {
			p.Set(chk.GetActive())
		})
		box.PackStart(chk, true, true, 0)
	}
	outer.PackStart(box, false, false, 0)
}
Exemplo n.º 3
0
// TestConnectNotifySignal ensures that property notification signals (those
// whose name begins with "notify::") are queried by the name "notify" (with the
// "::" and the property name omitted). This is because the signal is "notify"
// and the characters after the "::" are not recognized by the signal system.
//
// See
// https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#GObject-notify
// for background, and
// https://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-new
// for the specification of valid signal names.
func TestConnectNotifySignal(t *testing.T) {
	runtime.LockOSThread()

	// Create any GObject that has defined properties.
	spacing := 0
	box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, spacing)

	// Connect to a "notify::" signal to listen on property changes.
	box.Connect("notify::spacing", func() {
		gtk.MainQuit()
	})

	glib.IdleAdd(func(s string) bool {
		t.Log(s)
		spacing++
		box.SetSpacing(spacing)
		return true
	}, "IdleAdd executed")

	gtk.Main()
}
Exemplo n.º 4
0
func main() {
	gtk.Init(nil)

	win := setupWindow()
	box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	win.Add(box)

	tv := setupTextView(box)

	props := []*BoolProperty{
		&BoolProperty{"cursor visible", (*tv).GetCursorVisible, (*tv).SetCursorVisible},
		&BoolProperty{"editable", (*tv).GetEditable, (*tv).SetEditable},
		&BoolProperty{"overwrite", (*tv).GetOverwrite, (*tv).SetOverwrite},
		&BoolProperty{"accepts tab", (*tv).GetAcceptsTab, (*tv).SetAcceptsTab},
	}

	setupPropertyCheckboxes(tv, box, props)

	win.ShowAll()

	gtk.Main()
}