示例#1
0
文件: demo.go 项目: norisatir/go-gtk3
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
}
示例#2
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)
}
示例#3
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)

}