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 }
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 }
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 }