func createAddrBook() *gtk.Widget { grid, err := gtk.GridNew() if err != nil { log.Fatal(err) } grid.SetOrientation(gtk.ORIENTATION_VERTICAL) store, err := gtk.ListStoreNew(glib.TYPE_STRING, glib.TYPE_STRING) if err != nil { log.Fatal(err) } tv, err := gtk.TreeViewNew() if err != nil { log.Fatal(err) } tv.SetModel(store) addrBookWidgets.store = store addrBookWidgets.treeview = tv sw, err := gtk.ScrolledWindowNew(nil, nil) if err != nil { log.Fatal(err) } sw.Add(tv) sw.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) sw.SetHExpand(true) sw.SetVExpand(true) grid.Add(sw) renderer, err := gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } renderer.Set("editable", true) renderer.Set("editable-set", true) renderer.Connect("edited", func(_ *glib.Object, path, text string) { iter, err := store.GetIterFromString(path) if err == nil { store.Set(iter, []int{0}, []interface{}{text}) } }) col, err := gtk.TreeViewColumnNewWithAttribute("Label", renderer, "text", 0) if err != nil { log.Fatal(err) } col.SetExpand(true) tv.AppendColumn(col) renderer, err = gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } renderer.Set("editable", true) renderer.Set("editable-set", true) renderer.Connect("edited", func(_ *glib.Object, path, text string) { iter, err := store.GetIterFromString(path) if err == nil { // TODO(jrick): verify this is a valid address store.Set(iter, []int{1}, []interface{}{text}) } }) col, err = gtk.TreeViewColumnNewWithAttribute("Address", renderer, "text", 1) if err != nil { log.Fatal(err) } col.SetMinWidth(350) tv.AppendColumn(col) // put in an example address iter := store.Append() store.Set(iter, []int{0, 1}, []interface{}{"editable label", "01234567890"}) buttons, err := gtk.GridNew() if err != nil { log.Fatal(err) } newAddr, err := gtk.ButtonNewWithLabel("New Address") if err != nil { log.Fatal(err) } newAddr.SetSizeRequest(150, -1) newAddr.Connect("clicked", func() { iter := store.Append() store.Set(iter, []int{0, 1}, []interface{}{"", "new address"}) }) buttons.Add(newAddr) cpyAddr, err := gtk.ButtonNewWithLabel("Copy Address") if err != nil { log.Fatal(err) } cpyAddr.SetSizeRequest(150, -1) cpyAddr.Connect("clicked", func() { sel, err := tv.GetSelection() if err != nil { log.Fatal(err) } var iter gtk.TreeIter if sel.GetSelected(nil, &iter) { val, err := store.GetValue(&iter, 1) if err != nil { log.Fatal(err) } display, err := gdk.DisplayGetDefault() if err != nil { log.Fatal(err) } clipboard, err := gtk.ClipboardGetForDisplay( display, gdk.SELECTION_CLIPBOARD) if err != nil { log.Fatal(err) } primary, err := gtk.ClipboardGetForDisplay( display, gdk.SELECTION_PRIMARY) if err != nil { log.Fatal(err) } s, _ := val.GetString() clipboard.SetText(s) primary.SetText(s) } }) buttons.Add(cpyAddr) grid.Add(buttons) return &grid.Container.Widget }
func createTransactions() *gtk.Widget { sw, err := gtk.ScrolledWindowNew(nil, nil) if err != nil { log.Fatal(err) } store, err := gtk.ListStoreNew(glib.TYPE_STRING, glib.TYPE_STRING, glib.TYPE_STRING, glib.TYPE_STRING) if err != nil { log.Fatal(err) } tv, err := gtk.TreeViewNew() if err != nil { log.Fatal(err) } tv.SetModel(store) tv.SetHExpand(true) tv.SetVExpand(true) txWidgets.store = store txWidgets.treeview = tv sw.Add(tv) cr, err := gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } col, err := gtk.TreeViewColumnNewWithAttribute("Date", cr, "text", 0) if err != nil { log.Fatal(err) } tv.AppendColumn(col) cr, err = gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } col, err = gtk.TreeViewColumnNewWithAttribute("Type", cr, "text", 1) if err != nil { log.Fatal(err) } tv.AppendColumn(col) cr, err = gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } col, err = gtk.TreeViewColumnNewWithAttribute("Address", cr, "text", 2) if err != nil { log.Fatal(err) } col.SetExpand(true) tv.AppendColumn(col) cr, err = gtk.CellRendererTextNew() if err != nil { log.Fatal(err) } col, err = gtk.TreeViewColumnNewWithAttribute("Amount", cr, "text", 3) if err != nil { log.Fatal(err) } tv.AppendColumn(col) return &sw.Bin.Container.Widget }