コード例 #1
0
ファイル: recvcoins.go プロジェクト: hsk81/btcgui
func createRecvCoins() *gtk.Widget {
	store, err := gtk.ListStoreNew(glib.TYPE_STRING, glib.TYPE_STRING)
	if err != nil {
		log.Fatal(err)
	}
	RecvCoins.Store = store

	tv, err := gtk.TreeViewNewWithModel(store)
	if err != nil {
		log.Fatal(err)
	}
	RecvCoins.Treeview = tv

	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)
	cr, err := gtk.CellRendererTextNew()
	if err != nil {
		log.Fatal(err)
	}
	col, err = gtk.TreeViewColumnNewWithAttribute("Address", cr, "text", 1)
	if err != nil {
		log.Fatal(err)
	}
	col.SetMinWidth(350)
	tv.AppendColumn(col)

	newAddr, err := gtk.ButtonNewWithLabel("New Address")
	if err != nil {
		log.Fatal(err)
	}
	newAddr.SetSizeRequest(150, -1)
	newAddr.Connect("clicked", func() {
		go func() {
			triggers.newAddr <- 1
			reply := <-triggerReplies.newAddr
			if err, ok := reply.(error); ok {
				glib.IdleAdd(func() {
					mDialog := errorDialog("New address generation failed",
						err.Error())
					mDialog.Run()
					mDialog.Destroy()

				})
			} else if addr, ok := reply.(string); ok {
				glib.IdleAdd(func() {
					iter := RecvCoins.Store.Append()
					RecvCoins.Store.Set(iter, []int{0, 1},
						[]interface{}{"", addr})
				})
			}
		}()
	})
	newAddr.SetSensitive(false)
	RecvCoins.NewAddrBtn = newAddr

	buttons, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}

	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)

	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, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
	grid.Add(sw)
	grid.Add(buttons)

	return &grid.Container.Widget
}
コード例 #2
0
ファイル: transactions.go プロジェクト: hsk81/btcgui
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
}
コード例 #3
0
ファイル: addressbook.go プロジェクト: hsk81/btcgui
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
}
コード例 #4
0
ファイル: sendcoins.go プロジェクト: hsk81/btcgui
func createRecipient(rmFn func(*glib.Object, *recipient)) *recipient {
	ret := new(recipient)
	ret.n = recipients.Len()

	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}
	ret.Widget = grid.Container.Widget

	l, err := gtk.LabelNew("Pay To:")
	if err != nil {
		log.Fatal(err)
	}
	grid.Attach(l, 0, 0, 1, 1)
	l, err = gtk.LabelNew("Amount:")
	if err != nil {
		log.Fatal(err)
	}
	grid.Attach(l, 0, 1, 1, 1)

	payTo, err := gtk.EntryNew()
	if err != nil {
		log.Fatal(err)
	}
	payTo.SetHExpand(true)
	ret.payTo = payTo
	grid.Attach(payTo, 1, 0, 1, 1)

	remove, err := gtk.ButtonNew()
	if err != nil {
		log.Fatal(err)
	}
	img, err := gtk.ImageNewFromIconName("_Delete", gtk.ICON_SIZE_MENU)
	if err != nil {
		log.Fatal(err)
	}
	remove.SetImage(img)
	remove.SetTooltipText("Remove this recipient")
	remove.Connect("clicked", rmFn, ret)
	grid.Attach(remove, 2, 0, 1, 1)

	// TODO(jrick): Label doesn't do anything currently, so don't add
	// to gui.
	/*
		l, err = gtk.LabelNew("Label:")
		if err != nil {
			log.Fatal(err)
		}
		grid.Attach(l, 0, 1, 1, 1)
		label, err := gtk.EntryNew()
		if err != nil {
			log.Fatal(err)
		}
		label.SetHExpand(true)
		ret.label = label
		grid.Attach(label, 1, 1, 2, 1)
	*/

	amounts, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}
	amount, err := gtk.SpinButtonNewWithRange(0, 21000000, 0.00000001)
	if err != nil {
		log.Fatal(err)
	}
	amount.SetHAlign(gtk.ALIGN_START)
	ret.amount = amount
	amounts.Add(amount)

	ls, err := gtk.ListStoreNew(glib.TYPE_STRING)
	if err != nil {
		log.Fatal(err)
	}
	iter := ls.Append()
	choices := []string{"BTC", "mBTC", "μBTC"}
	s := make([]interface{}, len(choices))
	for i, v := range choices {
		s[i] = v
	}
	if err := ls.Set(iter, []int{0}, []interface{}{"BTC"}); err != nil {
		fmt.Println(err)
	}
	iter = ls.Append()
	if err := ls.Set(iter, []int{0}, []interface{}{"mBTC"}); err != nil {
		fmt.Println(err)
	}
	iter = ls.Append()
	if err := ls.Set(iter, []int{0}, []interface{}{"μBTC"}); err != nil {
		fmt.Println(err)
	}

	// TODO(jrick): add back when this works.
	/*
		combo, err := gtk.ComboBoxNewWithModel(ls)
		if err != nil {
			log.Fatal(err)
		}
		cell, err := gtk.CellRendererTextNew()
		if err != nil {
			log.Fatal(err)
		}
		combo.PackStart(cell, true)
		combo.AddAttribute(cell, "text", 0)
		combo.SetActive(0)
		combo.Connect("changed", func() {
			val := amount.GetValue()
			fmt.Println(val)
			switch combo.GetActive() {
			case 0:
				fmt.Println("btc")
			case 1:
				fmt.Println("mbtc")
			case 2:
				fmt.Println("ubtc")
			}
		})
		ret.combo = combo
		amounts.Add(combo)
	*/
	l, err = gtk.LabelNew("BTC")
	if err != nil {
		log.Fatal(err)
	}
	amounts.Add(l)

	grid.Attach(amounts, 1, 1, 1, 1)

	return ret
}