Пример #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
}
Пример #2
0
func attachWidgets(textView *gtk3.TextView) {
	var iter gtk3.TextIter

	buffer := textView.GetBuffer()
	buffer.GetStartIter(&iter)

	i := 0
	var widget gtk3.WidgetLike
	for findAnchor(&iter) {
		anchor := iter.GetChildAnchor()

		switch i {
		case 0:
			widget = gtk3.NewButtonWithLabel("Click Me")
			//widget.Connect("clicked",
		case 1:
			combo := gtk3.NewComboBoxText()
			combo.AppendText("Option 1")
			combo.AppendText("Option 2")
			combo.AppendText("Option 3")
			widget = combo
		case 2:
			filename, _ := findFile("floppybuddy.gif")
			widget = gtk3.NewImageFromFile(filename)
		case 3:
			widget = gtk3.NewEntry()
		default:
			break
		}
		textView.AddChildAtAnchor(widget, anchor)
		widget.W().ShowAll()
		i++
	}
}
Пример #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()
}
Пример #4
0
func main() {
	// Initialize gtk3
	gtk3.Init()

	// Create windows
	w := gtk3.NewWindow(gtk3.GTK_WINDOW_TOPLEVEL, nil)
	w.Connect("destroy", gtk3.MainQuit)
	// Let's set a couple of window properties
	w.Set(gtk3.P{"title": "Go-GTK3 Demo", "resizable": true})

	b2 := gtk3.NewVBox(0)
	w.Add(b2)

	// Create GtkFrame
	f := gtk3.NewFrame("Button Play")
	b2.Add(f)

	// Create GtkBox
	box := gtk3.NewBox(gtk3.ORIENTATION_VERTICAL, 5)
	// Add it to window
	f.Add(box)

	// Create First Button
	fbut := gtk3.NewButtonWithLabel("Click Me")
	box.PackStart(fbut, false, false, 0)
	fbut.Connect("clicked", func() { box.ReorderChild(fbut, 2) })

	// Another one
	fbut2 := gtk3.NewButtonWithLabel("Disable my upper brother")
	box.PackStart(fbut2, false, false, 0)
	// So, let's disable him
	fbut2.Connect("clicked", func(s bool) { fbut.SetSensitive(s) }, false)

	// And another
	fbut3 := gtk3.NewButtonWithLabel("Don't do it")
	box.PackStart(fbut3, false, false, 0)
	fbut2.Connect("clicked", but_disabled, fbut3, fbut)

	fbut3.Connect("clicked", func() {
		fbut.SetSensitive(true)
		fbut3.SetLabel("There you go")
	})

	entry1 := gtk3.NewEntry()
	box.PackStart(entry1, false, false, 0)
	fbut4 := gtk3.NewButtonWithLabel("Get entry text, now!")
	box.PackStart(fbut4, false, false, 0)
	fbut4.Connect("clicked", func() {
		fbut4.SetLabel(entry1.GetText())
	})
	// Run applicaton
	w.ShowAll()
	gtk3.Main()
}
Пример #5
0
func main() {
	app := gtk3.NewApplication("si.go-gtk3.demoapp", gtk3.G_APPLICATION_FLAGS_NONE)

	// Create windows
	w := gtk3.NewWindow(gtk3.GTK_WINDOW_TOPLEVEL, nil)
	// Add window to GTKApplication
	app.AddWindow(w)
	// Let's set a couple of window properties
	w.Set(gtk3.P{"title": "Go-GTK3 Demo", "resizable": false})

	//Create frame
	f := gtk3.NewFrame("Button play")
	// Add it to window
	w.Add(f)

	// Create GtkBox
	box := gtk3.NewBox(gtk3.ORIENTATION_VERTICAL, 5)
	f.Add(box)

	// Create First Button
	fbut := gtk3.NewButtonWithLabel("Click Me")
	box.PackStart(fbut, false, false, 0)
	fbut.Connect("clicked", func() { box.ReorderChild(fbut, 2) })

	// Another one
	fbut2 := gtk3.NewButtonWithLabel("Disable my upper brother")
	box.PackStart(fbut2, false, false, 0)
	// So, let's disable him
	fbut2.Connect("clicked", func(s bool) { fbut.SetSensitive(s) }, false)

	// And another
	fbut3 := gtk3.NewButtonWithLabel("Don't do it")
	box.PackStart(fbut3, false, false, 0)
	fbut2.Connect("clicked", but_disabled, fbut3, fbut)

	fbut3.Connect("clicked", func() {
		fbut.SetSensitive(true)
		fbut3.SetLabel("There you go")
	})

	entry1 := gtk3.NewEntry()
	box.PackStart(entry1, false, false, 0)
	fbut4 := gtk3.NewButtonWithLabel("Get entry text, now!")
	box.PackStart(fbut4, false, false, 0)
	fbut4.Connect("clicked", func() {
		fbut4.SetLabel(entry1.GetText())
	})
	// Run applicaton
	w.ShowAll()
	app.Run()
}
Пример #6
0
func createPage1(assistant *gtk3.Assistant) {
	box := gtk3.NewHBox(12)
	box.SetBorderWidth(12)

	label := gtk3.NewLabel("You must fill out this entry to continue")
	box.PackStart(label, false, false, 0)

	entry := gtk3.NewEntry()
	entry.SetActivatesDefault(true)
	box.PackStart(entry, true, true, 0)
	entry.Connect("changed", onEntryChanged, assistant)

	box.ShowAll()

	assistant.AppendPage(box)
	assistant.SetPageTitle(box, "Page 1")
	assistant.SetPageType(box, gtk3.GtkAssistantPage.INTRO)
}
Пример #7
0
func DoComboBox(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Combo boxes")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(10)

		vbox := gtk3.NewVBox(2)
		window.Add(vbox)

		// A combobox demonstrating cell renderers, separators and insensitive rows
		frame := gtk3.NewFrame("Some stock icons")
		vbox.PackStart(frame, false, false, 0)

		box := gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		model := createStockIconStore()
		combo := gtk3.NewComboBoxWithModel(model)
		box.Add(combo)

		var renderer gtk3.CellRendererLike

		renderer = gtk3.NewCellRendererPixbuf()
		combo.PackStart(renderer, false)
		combo.SetAttributes(renderer, gtk3.A{{"pixbuf", PixbufCol}})
		combo.SetCellDataFunc(renderer, setSensitive)

		renderer = gtk3.NewCellRendererText()
		combo.PackStart(renderer, true)
		combo.SetAttributes(renderer, gtk3.A{{"text", TextCol}})
		combo.SetCellDataFunc(renderer, setSensitive)

		combo.SetRowSeparatorFunc(isSeparator)
		combo.SetActive(0)

		// A ComboBox demonstrating trees.
		frame = gtk3.NewFrame("Where are we ?")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		model1 := createCapitalStore()
		combo3 := gtk3.NewComboBoxWithModel(model1)
		box.Add(combo3)

		renderer1 := gtk3.NewCellRendererText()
		combo3.PackStart(renderer1, true)
		combo3.SetAttributes(renderer1, gtk3.A{{"text", 0}})

		combo3.SetCellDataFunc(renderer1, isCapitalSensitive)

		var iter gtk3.TreeIter
		path := gtk3.NewTreePathFromString("3:3")
		model1.ITreeModel().GetIter(&iter, path)
		combo3.SetActiveIter(&iter)

		// a combobox with validation
		frame = gtk3.NewFrame("Editable")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		box.SetBorderWidth(5)
		frame.Add(box)

		combo1 := gtk3.NewComboBoxTextWithEntry()
		box.Add(combo1)
		combo1.AppendText("One")
		combo1.AppendText("Two")
		combo1.AppendText("2\302\275")
		combo1.AppendText("Three")

		mask := "^([0-9]*|One|Two|2\302\275|Three)$"
		entry := combo1.GetChild().(*gtk3.Entry)
		entry.Connect("changed", setBackground, entry, mask)

		// A ComboBox with string IDs
		frame = gtk3.NewFrame("String IDs")
		vbox.PackStart(frame, false, false, 0)

		box = gtk3.NewVBox(0)
		vbox.SetBorderWidth(5)
		frame.Add(box)

		combo2 := gtk3.NewComboBoxText()
		combo2.Append("never", "Not visible")
		combo2.Append("when-active", "Visible when active")
		combo2.Append("always", "Always visible")
		box.Add(combo2)

		entry = gtk3.NewEntry()
		box.Add(entry)

		gobject.BindProperty(combo2, "active-id", entry, "text", gobject.GBindingFlags.BIDIRECTIONAL)
	}

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

	return window
}
Пример #8
0
func DoDialog(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Dialogs")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(8)

		frame := gtk3.NewFrame("Dialogs")
		window.Add(frame)

		vbox := gtk3.NewVBox(8)
		vbox.SetBorderWidth(8)
		frame.Add(vbox)

		// Standard message dialog
		hbox := gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)

		button := gtk3.NewButtonWithMnemonic("_Message Dialog")
		button.Connect("clicked", dialogClickedClosure(window))
		hbox.PackStart(button, false, false, 0)

		vbox.PackStart(gtk3.NewHSeparator(), false, false, 0)

		// Interactive dialog
		hbox = gtk3.NewHBox(8)
		vbox.PackStart(hbox, false, false, 0)
		vbox2 := gtk3.NewVBox(0)

		button = gtk3.NewButtonWithMnemonic("_Interactive Dialog")
		hbox.PackStart(vbox2, false, false, 0)
		vbox2.PackStart(button, false, false, 0)

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

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

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

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

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

		button.Connect("clicked", interactiveDialog, window, entry1, entry2)
	}

	if !window.GetVisible() {
		window.ShowAll()
	} else {
		window.Destroy()
		window = nil
		return nil
	}
	return window
}
Пример #9
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
}