예제 #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)
}
예제 #2
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
}