func CreateText(buffer **gtk3.TextBuffer, isSource bool) gtk3.WidgetLike { scrolledW := gtk3.NewScrolledWindow(nil, nil) scrolledW.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC) scrolledW.SetShadowType(gtk3.GtkShadow.IN) *buffer = gtk3.NewTextBuffer(nil) textView := gtk3.NewTextView() textView.SetBuffer(*buffer) textView.SetEditable(false) textView.SetCursorVisible(false) scrolledW.Add(textView) if isSource { fontDesc := pango.NewFontDescriptionFromString("monospace") textView.OverrideFont(fontDesc) textView.SetWrapMode(gtk3.GtkWrapMode.NONE) } else { // Make it a bit nicer for text textView.SetWrapMode(gtk3.GtkWrapMode.WORD) textView.SetPixelsAboveLines(2) textView.SetPixelsBelowLines(2) } return scrolledW }
func DoTextView(w gtk3.WidgetLike) gtk3.WidgetLike { if window == nil { window = gtk3.NewWindow(gtk3.GtkWindowType.TOPLEVEL) window.SetScreen(w.W().GetScreen()) window.SetDefaultSize(450, 450) window.Connect("destroy", func() { window.Destroy(); window = nil }) window.SetTitle("TextView") window.SetBorderWidth(0) vpaned := gtk3.NewVPaned() vpaned.SetBorderWidth(5) window.Add(vpaned) view1 := gtk3.NewTextView() buffer := view1.GetBuffer() view2 := gtk3.NewTextViewWithBuffer(buffer) sw := gtk3.NewScrolledWindow(nil, nil) sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC) vpaned.Add1(sw) sw.Add(view1) sw = gtk3.NewScrolledWindow(nil, nil) sw.SetPolicy(gtk3.GtkPolicy.AUTOMATIC, gtk3.GtkPolicy.AUTOMATIC) vpaned.Add2(sw) sw.Add(view2) createTags(buffer) insertText(buffer) attachWidgets(view1) attachWidgets(view2) } if !window.GetVisible() { window.ShowAll() } else { window.Destroy() window = nil return nil } return window }
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 }