Exemple #1
0
func iconPressCallback(menu *gtk3.Menu, entry *gtk3.Entry, position int, event gdk3.EventButton, data ...interface{}) {
	if position == gtk3.GtkEntryIconPosition.PRIMARY {
		menu.Popup(nil, nil, event.Button, event.Time, nil)
	} else {
		entry.SetText("")
	}
}
Exemple #2
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)
}
Exemple #3
0
func interactiveDialog(w *gtk3.Window, entry1, entry2 *gtk3.Entry) {
	dialog := gtk3.NewDialogWithButtons("Interactive Dialog",
		w,
		gtk3.GtkDialogFlags.MODAL|gtk3.GtkDialogFlags.DESTROY_WITH_PARENT,
		gtk3.B{{gtk3.GtkStock.OK, gtk3.GtkResponse.OK}, {"_Non-stock Button", gtk3.GtkResponse.CANCEL}})

	content_area := dialog.GetContentArea().(*gtk3.Box)

	hbox := gtk3.NewHBox(8)
	hbox.SetBorderWidth(uint(8))
	content_area.PackStart(hbox, false, false, 0)

	stock := gtk3.NewImageFromStock(gtk3.GtkStock.DIALOG_QUESTION, gtk3.GtkIconSize.DIALOG)
	hbox.PackStart(stock, false, false, 0)

	table := gtk3.NewGrid()
	table.SetRowSpacing(4)
	table.SetColumnSpacing(4)
	hbox.PackStart(table, true, true, 0)

	label := gtk3.NewLabelWithMnemonic("_Entry 1")
	table.Attach(label, 0, 0, 1, 1)

	local_entry1 := gtk3.NewEntry()
	local_entry1.SetText(entry1.GetText())
	table.Attach(local_entry1, 1, 0, 1, 1)
	label.SetMnemonicWidget(local_entry1)

	label = gtk3.NewLabelWithMnemonic("E_ntry 2")
	table.Attach(label, 0, 1, 1, 1)

	local_entry2 := gtk3.NewEntry()
	local_entry2.SetText(entry2.GetText())
	table.Attach(local_entry2, 1, 1, 1, 1)
	label.SetMnemonicWidget(local_entry2)

	hbox.ShowAll()
	response := dialog.Run()

	if response == gtk3.GtkResponse.OK {
		entry1.SetText(local_entry1.GetText())
		entry2.SetText(local_entry2.GetText())
	}

	dialog.Destroy()
}
Exemple #4
0
func setBackground(entry *gtk3.Entry, mask string) {
	errorColor := gdk3.RGBA{1.0, 0.9, 0.9, 1.0}
	if mask != "" {
		m, _ := regexp.Compile(mask)
		if m.FindStringIndex(entry.GetText()) == nil {
			entry.OverrideColor(0, &errorColor)
			return
		}
	}
	entry.OverrideColor(0, nil)
}
Exemple #5
0
func createSearchMenu(entry *gtk3.Entry) *gtk3.Menu {
	menu := gtk3.NewMenu()

	item := gtk3.NewImageMenuItemWithMnemonic("Search by _name")
	image := gtk3.NewImageFromStock(gtk3.GtkStock.FIND, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.FIND)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by name\nClick here to change the search type")
		entry.SetPlaceholderText("name")
	})
	menu.Append(item)

	item = gtk3.NewImageMenuItemWithMnemonic("Search by _description")
	image = gtk3.NewImageFromStock(gtk3.GtkStock.EDIT, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.EDIT)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by description\nClick here to change the search type")
		entry.SetPlaceholderText("description")
	})
	menu.Append(item)

	item = gtk3.NewImageMenuItemWithMnemonic("Search by _file name")
	image = gtk3.NewImageFromStock(gtk3.GtkStock.OPEN, gtk3.GtkIconSize.MENU)
	item.SetImage(image)
	item.SetAlwaysShowImage(true)
	item.Connect("activate", func(item gtk3.MenuItemLike, data ...interface{}) {
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.PRIMARY, gtk3.GtkStock.OPEN)
		entry.SetIconTooltipText(gtk3.GtkEntryIconPosition.PRIMARY,
			"Search by file name\nClick here to change the search type")
		entry.SetPlaceholderText("file name")
	})
	menu.Append(item)

	menu.ShowAll()

	return menu
}