示例#1
0
func entryPopulatePopup(entry *gtk3.Entry, menu *gtk3.Menu, data ...interface{}) {
	hasText := entry.GetTextLength() > 0

	item := gtk3.NewSeparatorMenuItem()
	item.Show()
	menu.Append(item)

	item2 := gtk3.NewMenuItemWithMnemonic("C_lear")
	item2.Show()
	item2.Connect("activate", func() { entry.SetText("") })
	menu.Append(item2)
	item2.SetSensitive(hasText)

	searchMenu := createSearchMenu(entry)
	item3 := gtk3.NewMenuItemWithLabel("Search by")
	item3.Show()
	item3.SetSubmenu(searchMenu)
	menu.Append(item3)
}
示例#2
0
文件: menu.go 项目: jkeys089/go-gtk3
func DoMenu(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Menus")
		window.Connect("destroy", func() { window.Destroy(); window = nil })

		accelGroup := gtk3.NewAccelGroup()
		window.AddAccelGroup(accelGroup)
		window.SetBorderWidth(0)

		box := gtk3.NewHBox(0)
		window.Add(box)
		box.Show()

		box1 := gtk3.NewVBox(0)
		box.Add(box1)
		box1.Show()

		menubar := gtk3.NewMenuBar()
		box1.PackStart(menubar, false, true, 0)
		menubar.Show()

		menu := createMenu(2, true)

		menuitem := gtk3.NewMenuItemWithLabel("test\nline2")
		menuitem.SetSubmenu(menu)
		menubar.Append(menuitem)
		menuitem.Show()

		menuitem = gtk3.NewMenuItemWithLabel("foo")
		menuitem.SetSubmenu(createMenu(3, true))
		menubar.Append(menuitem)
		menuitem.Show()

		menuitem = gtk3.NewMenuItemWithLabel("bar")
		menuitem.SetSubmenu(createMenu(4, true))
		menubar.Append(menuitem)
		menuitem.Show()

		box2 := gtk3.NewVBox(10)
		box2.SetBorderWidth(10)
		box1.PackStart(box2, false, true, 0)
		box2.Show()

		button := gtk3.NewButtonWithLabel("Flip")
		button.Connect("clicked", changeOrientation, menubar)
		box2.PackStart(button, true, true, 0)
		button.Show()

		button = gtk3.NewButtonWithLabel("Close")
		button.Connect("clicked", func() { window.Destroy() })
		box2.PackStart(button, true, true, 0)
		button.SetCanDefault(true)
		button.GrabDefault()
		button.Show()
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}

	return window
}