Example #1
0
func DoSpinner(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewDialogWithButtons("GtkSpinner", w.(*gtk3.Window), 0,
			gtk3.B{{gtk3.GtkStock.CLOSE, gtk3.GtkResponse.NONE}})

		window.SetResizable(false)
		window.Connect("response", func() { window.Destroy() })
		window.Connect("destroy", func() { window = nil })

		contentArea := window.GetContentArea().(*gtk3.Box)

		vbox := gtk3.NewVBox(5)
		contentArea.PackStart(vbox, true, true, 0)
		vbox.SetBorderWidth(5)

		// Sensitive
		hbox := gtk3.NewHBox(5)
		spinnerS := gtk3.NewSpinner()
		hbox.Add(spinnerS)
		hbox.Add(gtk3.NewEntry())
		vbox.Add(hbox)

		// Disabled
		hbox = gtk3.NewHBox(5)
		spinnerU := gtk3.NewSpinner()
		hbox.Add(spinnerU)
		hbox.Add(gtk3.NewEntry())
		vbox.Add(hbox)
		hbox.SetSensitive(false)

		button := gtk3.NewButtonFromStock(gtk3.GtkStock.MEDIA_PLAY)

		button.Connect("clicked", func() {
			spinnerS.Start()
			spinnerU.Start()
		})
		vbox.Add(button)

		button = gtk3.NewButtonFromStock(gtk3.GtkStock.MEDIA_STOP)
		button.Connect("clicked", func() {
			spinnerS.Stop()
			spinnerU.Stop()
		})
		vbox.Add(button)

		spinnerS.Start()
		spinnerU.Start()
	}

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

	return window
}
Example #2
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()
}
Example #3
0
func DoEntryBuffer(w gtk3.WidgetLike) gtk3.WidgetLike {
	if dialog == nil {
		dialog = gtk3.NewDialogWithButtons("GtkEntryBuffer",
			w.(*gtk3.Window), 0,
			gtk3.B{{gtk3.GtkStock.CLOSE, gtk3.GtkResponse.NONE}})
		dialog.SetResizable(false)
		dialog.Connect("response", func() { dialog.Destroy() })
		dialog.Connect("destroy", func() { dialog = nil })

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

		vbox := gtk3.NewVBox(5)
		content_area.PackStart(vbox, true, true, 0)

		label := gtk3.NewLabel("")
		label.SetMarkup("Entries share a buffer. Typing in one is reflected in the other.")
		vbox.PackStart(label, false, false, 0)

		// Create a buffer
		buffer := gtk3.NewEntryBuffer("")

		// Create entry with visibility off
		entry := gtk3.NewEntryWithBuffer(buffer)
		entry.Set(gtk3.P{"visibility": false})
		vbox.PackStart(entry, false, false, 0)

		// Create second entry
		entry = gtk3.NewEntryWithBuffer(buffer)
		vbox.PackStart(entry, false, false, 0)
	}

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

	return dialog
}
Example #4
0
func DoSearchEntry(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		var searchProgressId, finishSearchId uint

		window = gtk3.NewDialogWithButtons("Search Entry", w.(*gtk3.Window),
			0, gtk3.B{{gtk3.GtkStock.CLOSE, gtk3.GtkResponse.NONE}})
		window.SetResizable(false)
		window.Connect("response", func() { window.Destroy() })
		window.Connect("destroy", func() {
			if finishSearchId != 0 {
				glib.GSourceRemove(finishSearchId)
			}
			if searchProgressId != 0 {
				glib.GSourceRemove(searchProgressId)
			}

			window = nil
		})

		contentArea := window.GetContentArea().(*gtk3.Box)

		vbox := gtk3.NewVBox(5)
		contentArea.PackStart(vbox, true, true, 0)
		vbox.SetBorderWidth(5)

		label := gtk3.NewLabel("")
		label.SetMarkup("Search entry demo")
		vbox.PackStart(label, false, false, 0)

		hbox := gtk3.NewHBox(10)
		vbox.PackStart(hbox, true, true, 0)
		hbox.SetBorderWidth(0)

		// Create our entry
		entry := gtk3.NewEntry()
		hbox.PackStart(entry, false, false, 0)

		// Create the find and cancel buttons
		notebook := gtk3.NewNotebook()
		notebook.SetShowTabs(false)
		notebook.SetShowBorder(false)
		hbox.PackStart(notebook, false, false, 0)

		startSearchFunc := func() { entry.ProgressPulse() }

		finishSearchFunc := func() bool {
			notebook.SetCurrentPage(0)
			glib.GSourceRemove(searchProgressId)
			searchProgressId = 0
			entry.SetProgressFraction(0.0)
			return false
		}

		findButton := gtk3.NewButtonWithLabel("Find")
		findButton.Connect("clicked", func() {
			notebook.SetCurrentPage(1)

			searchProgressId = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 100, startSearchFunc)

			finishSearchId = glib.GTimeoutAddSecondsFull(glib.GPriority.DEFAULT, 15, finishSearchFunc)
		})
		notebook.AppendPage(findButton, nil)
		findButton.Show()

		cancelButton := gtk3.NewButtonWithLabel("Cancel")
		cancelButton.Connect("clicked", func() {
			glib.GSourceRemove(finishSearchId)
			finishSearchFunc()
		})
		notebook.AppendPage(cancelButton, nil)
		cancelButton.Show()

		// Set up the search icon
		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")

		// Set up the clear icon
		entry.SetIconFromStock(gtk3.GtkEntryIconPosition.SECONDARY, gtk3.GtkStock.CLEAR)

		menu := createSearchMenu(entry)
		menu.AttachToWidget(entry, nil)

		textChangedFunc := func() {
			hasText := entry.GetTextLength() > 0
			entry.SetIconSensitive(gtk3.GtkEntryIconPosition.SECONDARY, hasText)
			findButton.SetSensitive(hasText)
		}

		textChangedFunc()

		entry.Connect("icon-press", iconPressCallback, menu)
		entry.Connect("notify::text", textChangedFunc)

		entry.Connect("activate", func() {
			if searchProgressId != 0 {
				return
			}
			notebook.SetCurrentPage(1)

			searchProgressId = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 100, startSearchFunc)

			finishSearchId = glib.GTimeoutAddSecondsFull(glib.GPriority.DEFAULT, 15, finishSearchFunc)

		})

		entry.Connect("populate-popup", entryPopulatePopup)

		button := window.GetWidgetForResponse(gtk3.GtkResponse.NONE)
		button.W().GrabFocus()
	}

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

	return window
}