Beispiel #1
0
func addColumns(treeView *gtk3.TreeView) {
	model := treeView.GetModel()

	var renderer gtk3.CellRendererLike

	// column for fixed toggles
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Connect("toggled", fixedToggled, model)

	column := gtk3.NewTreeViewColumnWithAttributes("Fixed?", renderer, gtk3.A{{"active", ColumnFixed}})

	// Set this column to a fixed sizing (50 pixels)
	column.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	column.SetFixedWidth(50)
	treeView.AppendColumn(column)

	// Column for bug numbers
	renderer = gtk3.NewCellRendererText()
	column = gtk3.NewTreeViewColumnWithAttributes("Bug number", renderer, gtk3.A{{"text", ColumnNumber}})
	column.SetSortColumnId(ColumnNumber)
	treeView.AppendColumn(column)

	// Column for severities
	renderer = gtk3.NewCellRendererText()
	column = gtk3.NewTreeViewColumnWithAttributes("Severity", renderer, gtk3.A{{"text", ColumnSeverity}})
	column.SetSortColumnId(ColumnSeverity)
	treeView.AppendColumn(column)

	// Column for description
	renderer = gtk3.NewCellRendererText()
	column = gtk3.NewTreeViewColumnWithAttributes("Description", renderer, gtk3.A{{"text", ColumnDescription}})
	column.SetSortColumnId(ColumnDescription)
	treeView.AppendColumn(column)

	// Column for spinner
	renderer = gtk3.NewCellRendererSpinner()
	column = gtk3.NewTreeViewColumnWithAttributes("Spinning", renderer, gtk3.A{{"pulse", ColumnPulse}, {"active", ColumnActive}})
	column.SetSortColumnId(ColumnPulse)
	treeView.AppendColumn(column)

	// Column for symbolic icon
	renderer = gtk3.NewCellRendererPixbuf()
	renderer.CRenderer().Set(gtk3.P{"follow-state": true})
	column = gtk3.NewTreeViewColumnWithAttributes("Symbolic icon", renderer,
		gtk3.A{{"icon-name", ColumnIcon}, {"sensitive", ColumnSensitive}})
	column.SetSortColumnId(ColumnIcon)
	treeView.AppendColumn(column)
}
Beispiel #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
}
Beispiel #3
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
}
Beispiel #4
0
func addColumns(treeview *gtk3.TreeView) {
	var renderer gtk3.CellRendererLike
	model := treeview.GetModel().(*gtk3.TreeStore)

	// Column for holiday names
	renderer = gtk3.NewCellRendererText()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})

	col := gtk3.NewTreeViewColumnWithAttributes("Holiday", renderer, gtk3.A{{"text", HolidayNameCol}})
	treeview.AppendColumn(col)
	col.SetClickable(true)

	// Alex column
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})
	renderer.CRenderer().Connect("toggled", itemToggled, model, AlexCol)

	col = gtk3.NewTreeViewColumnWithAttributes("Alex", renderer,
		gtk3.A{{"active", AlexCol}, {"visible", VisibleCol}, {"activatable", WorldCol}})
	treeview.AppendColumn(col)
	col.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	col.SetFixedWidth(60)
	col.SetClickable(true)

	// Havoc column
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})
	renderer.CRenderer().Connect("toggled", itemToggled, model, HavocCol)

	col = gtk3.NewTreeViewColumnWithAttributes("Havoc", renderer,
		gtk3.A{{"active", HavocCol}, {"visible", VisibleCol}})
	treeview.AppendColumn(col)
	col.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	col.SetFixedWidth(60)
	col.SetClickable(true)

	// Tim column
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})
	renderer.CRenderer().Connect("toggled", itemToggled, model, TimCol)

	col = gtk3.NewTreeViewColumnWithAttributes("Tim", renderer,
		gtk3.A{{"active", TimCol}, {"visible", VisibleCol}, {"activatable", WorldCol}})
	treeview.AppendColumn(col)
	col.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	col.SetFixedWidth(60)
	col.SetClickable(true)

	// Owen column
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})
	renderer.CRenderer().Connect("toggled", itemToggled, model, OwenCol)

	col = gtk3.NewTreeViewColumnWithAttributes("Owen", renderer,
		gtk3.A{{"active", OwenCol}, {"visible", VisibleCol}})
	treeview.AppendColumn(col)
	col.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	col.SetFixedWidth(60)
	col.SetClickable(true)

	// Dave column
	renderer = gtk3.NewCellRendererToggle()
	renderer.CRenderer().Set(gtk3.P{"xalign": 0.0})
	renderer.CRenderer().Connect("toggled", itemToggled, model, DaveCol)

	col = gtk3.NewTreeViewColumnWithAttributes("Dave", renderer,
		gtk3.A{{"active", DaveCol}, {"visible", VisibleCol}})
	treeview.AppendColumn(col)
	col.SetSizing(gtk3.GtkTreeViewColumnSizing.FIXED)
	col.SetFixedWidth(60)
	col.SetClickable(true)

}