Esempio n. 1
0
func createPage3(assistant *gtk3.Assistant) {
	label := gtk3.NewLabel("This is a confirmation page, press 'Apply' to apply changes")

	label.Show()
	assistant.AppendPage(label)
	assistant.SetPageType(label, gtk3.GtkAssistantPage.CONFIRM)
	assistant.SetPageComplete(label, true)
	assistant.SetPageTitle(label, "Confirmation")
}
Esempio n. 2
0
func CreateTree() gtk3.WidgetLike {
	model := gtk3.NewTreeStore([]gobject.GType{gobject.G_TYPE_STRING, gobject.G_TYPE_INT})

	treeView := gtk3.NewTreeViewWithModel(model)
	selection := treeView.GetSelection()
	if selection == nil {
		panic("Selection object nil")
	}
	selection.SetMode(gtk3.GtkSelectionMode.BROWSE)

	var iter gtk3.TreeIter

	for _, demo := range Demos {
		model.Append(&iter, nil)
		model.SetValues(&iter, gtk3.V{TitleColumn: demo.Title, StyleColumn: pango.PangoStyle.NORMAL})

		if len(demo.Children) > 0 {
			var childIter gtk3.TreeIter
			for _, childDemo := range demo.Children {
				model.Append(&childIter, &iter)
				model.SetValues(&childIter, gtk3.V{TitleColumn: childDemo.Title, StyleColumn: pango.PangoStyle.NORMAL})
			}
		}
	}

	cell := gtk3.NewCellRendererText()
	column := gtk3.NewTreeViewColumnWithAttributes("Widget (double click for demo)",
		cell,
		gtk3.A{{"text", TitleColumn}, {"style", StyleColumn}})

	treeView.AppendColumn(column)

	model.GetIterFirst(&iter)
	selection.SelectIter(&iter)

	treeView.Connect("row_activated", rowActivated, model)

	treeView.CollapseAll()
	treeView.SetHeadersVisible(false)

	sw := gtk3.NewScrolledWindow(nil, nil)
	sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)
	sw.Add(treeView)

	label := gtk3.NewLabel("Widget (double click for demo)")

	box := gtk3.NewNotebook()
	box.AppendPage(sw, label)

	treeView.GrabFocus()

	return box
}
Esempio n. 3
0
func DoTreeStore(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())
		window.SetTitle("Card planning sheet")
		window.Connect("destroy", func() { window = nil })

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

		vbox.PackStart(gtk3.NewLabel("Jonathan's Holiday Card Planning Sheet"), false, false, 0)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetShadowType(gtk3.GtkShadow.ETCHED_IN)
		sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC)

		vbox.PackStart(sw, true, true, 0)

		// Create model
		model := createModel()

		// Create tree view
		treeview := gtk3.NewTreeViewWithModel(model)
		treeview.SetRulesHint(true)
		treeview.GetSelection().SetMode(gtk3.GtkSelectionMode.MULTIPLE)
		treeview.Connect("realize", func() { treeview.ExpandAll() })

		sw.Add(treeview)

		addColumns(treeview)

		window.SetDefaultSize(650, 400)
	}

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

	return window
}
Esempio n. 4
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)
}
Esempio n. 5
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
}
Esempio n. 6
0
func DoInfoBar(w gtk3.WidgetLike) gtk3.WidgetLike {
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetScreen(w.W().GetScreen())

		window.SetTitle("Info Bars")
		window.Connect("destroy", func() { window.Destroy(); window = nil })
		window.SetBorderWidth(8)

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

		bar := gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.INFO)
		label := gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_INFO")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.WARNING)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_WARNING")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBarWithButtons(gtk3.B{{gtk3.GtkStock.OK, gtk3.GtkResponse.OK}})
		bar.Connect("response", func(infoBar *gtk3.InfoBar, responseId int, data ...interface{}) {
			dialog := gtk3.NewMessageDialog(window, gtk3.GtkDialogFlags.MODAL|gtk3.GtkDialogFlags.DESTROY_WITH_PARENT,
				gtk3.GtkMessage.INFO,
				gtk3.GtkButtons.OK,
				"You Clicked a button on info bar")

			dialog.FormatSecondaryText("Your response has id %d", responseId)
			dialog.Run()
			dialog.Destroy()
		})
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.QUESTION)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_QUESTION")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.ERROR)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_ERROR")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		bar = gtk3.NewInfoBar()
		vbox.PackStart(bar, false, false, 0)
		bar.SetMessageType(gtk3.GtkMessage.OTHER)
		label = gtk3.NewLabel("This is an info bar with message type GTK_MESSAGE_OTHER")
		(bar.GetContentArea()).(*gtk3.Box).PackStart(label, false, false, 0)

		frame := gtk3.NewFrame("Info bars")
		vbox.PackStart(frame, false, false, 8)

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

		// Standard message dialog
		label = gtk3.NewLabel("An example of different info bars")
		vbox2.PackStart(label, false, false, 0)
	}

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

	return window
}
Esempio n. 7
0
func DoListStore(w gtk3.WidgetLike) gtk3.WidgetLike {
	var model *gtk3.ListStore
	if window == nil {
		window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL)
		window.SetTitle("GtkListStore demo")
		window.Connect("destroy", func() { window = nil })
		window.SetBorderWidth(8)

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

		label := gtk3.NewLabel("This is the bug list (note: not based on real data...)")
		vbox.PackStart(label, false, false, 0)

		sw := gtk3.NewScrolledWindow(nil, nil)
		sw.SetShadowType(gtk3.GtkShadow.ETCHED_IN)
		sw.SetPolicy(gtk3.GtkPolicy.NEVER, gtk3.GtkPolicy.AUTOMATIC)
		vbox.PackStart(sw, true, true, 0)

		// create tree model
		model = createModel()

		// create tree view
		treeview := gtk3.NewTreeViewWithModel(model)
		treeview.SetRulesHint(true)
		treeview.SetSearchColumn(ColumnDescription)
		sw.Add(treeview)

		// Add columns to treeview
		addColumns(treeview)

		// Finish & Show
		window.SetDefaultSize(280, 250)
		window.Connect("delete-event", windowClosed)
	}

	if !window.GetVisible() {
		window.ShowAll()
		timeout = glib.GTimeoutAddFull(glib.GPriority.DEFAULT, 80,
			func() {
				var sIter gtk3.TreeIter
				model.GetIterFirst(&sIter)
				pulse := model.GetValue(&sIter, ColumnPulse).(uint)

				if pulse == ^uint(0) {
					pulse = 0
				} else {
					pulse++
				}
				model.SetValues(&sIter, gtk3.V{ColumnPulse: pulse, ColumnActive: true})
			})

	} else {
		window.Destroy()
		window = nil
		if timeout != 0 {
			glib.GSourceRemove(timeout)
			timeout = 0
		}
		return nil
	}

	return window
}
Esempio n. 8
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
}