Esempio n. 1
0
// NewNavigationBar creates a new navigation bar for a HTML page.
func NewNavigationBar() *NavigationBar {
	tb, _ := gtk.ToolbarNew()

	var back, forward, stop, reload *gtk.ToolButton
	buttons := []struct {
		iconName  string
		tooltip   string
		show      bool
		sensitive bool
		button    **gtk.ToolButton
	}{
		{"go-previous", "Go back", true, false, &back},
		{"go-next", "Go forward", true, false, &forward},
		{"process-stop", "Stop loading page", true, true, &stop},
		{"view-refresh", "Reload page", false, true, &reload},
	}
	for i := range buttons {
		b := &buttons[i]
		image, _ := gtk.ImageNewFromIconName(b.iconName, navbarIconSize)
		image.Show()
		button, _ := gtk.ToolButtonNew(image, b.iconName)
		button.SetTooltipText(b.tooltip)
		if b.show {
			button.Show()
		}
		button.SetSensitive(b.sensitive)
		tb.Add(button)
		*b.button = button
	}

	sep, _ := gtk.SeparatorToolItemNew()
	sep.SetDraw(false)
	tb.Add(sep)
	sep.Show()

	uri, _ := gtk.EntryNew()
	uri.SetInputPurpose(gtk.INPUT_PURPOSE_URL)
	uri.SetIconFromIconName(gtk.ENTRY_ICON_PRIMARY, "broken")
	uri.SetIconFromIconName(gtk.ENTRY_ICON_SECONDARY, "non-starred")
	tool, _ := gtk.ToolItemNew()
	tool.Add(uri)
	tool.SetExpand(true)
	tool.ShowAll()
	tb.Add(tool)

	sep, _ = gtk.SeparatorToolItemNew()
	sep.SetDraw(false)
	tb.Add(sep)
	sep.Show()

	search, _ := gtk.SearchEntryNew()
	tool, _ = gtk.ToolItemNew()
	tool.Add(search)
	tool.ShowAll()
	tb.Add(tool)

	return &NavigationBar{tb, back, forward, stop, reload, uri, search}
}
Esempio n. 2
0
// openNewPage adds the page content and title label to the notebook.  A close
// tab button is added to the title label to create the notebook tab widget.
// When the close button is pressed, the page will be removed from the manager.
func (p *PageManager) openNewPage(page Page) int {
	// Create tab content using title label and connect necessary signals.
	tabContent, _ := gtk.GridNew()
	image, _ := gtk.ImageNewFromIconName("window-close", notebookIconSize)
	closeButton, _ := gtk.ButtonNew()
	closeButton.SetImage(image)
	closeButton.SetCanFocus(false)
	tabContent.Add(closeButton)
	title := page.TitleLabel()
	title.SetCanFocus(false)
	title.SetSizeRequest(150, -1)
	tabContent.Add(title)
	tabContent.SetCanFocus(false)

	closeButton.Connect("clicked", func() {
		pageNum := p.PageNum(page)
		p.RemovePage(pageNum)
		switch page := page.(type) {
		case *HTMLPage:
			delete(p.htmls, page.Native())

			for _, s := range page.signals {
				s.Object.HandlerDisconnect(s.SignalHandle)
			}

			// Do not wait for the garbage collector to finalize
			// the webview and reap the web process.
			page.wv.Destroy()

		case *DownloadsPage:
			p.downloads = nil
		case *SettingsPage:
			p.settings = nil
		}

		// Always show at least one page.  This defaults to a blank
		// HTML page.
		if p.GetNPages() == 0 {
			p.OpenPage(BlankPage)
		}
	})

	tabContent.ShowAll()
	page.Show()
	n := p.AppendPage(page, tabContent)
	p.GrabFocus()
	p.SetTabReorderable(page, true)
	return n
}
Esempio n. 3
0
func createTxLabel(attr *TxAttributes) (*gtk.Widget, error) {
	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetHExpand(true)

	var amtLabel *gtk.Label
	var description *gtk.Label
	var icon *gtk.Image
	switch attr.Direction {
	case Send:
		amtLabel, err = gtk.LabelNew(amountStr(attr.Amount))
		if err != nil {
			return nil, err
		}

		description, err = gtk.LabelNew(fmt.Sprintf("Send (%s)", attr.Address))
		if err != nil {
			return nil, err
		}

		icon, err = gtk.ImageNewFromIconName("go-next",
			gtk.ICON_SIZE_SMALL_TOOLBAR)
		if err != nil {
			return nil, err
		}

	case Recv:
		amtLabel, err = gtk.LabelNew(amountStr(attr.Amount))
		if err != nil {
			return nil, err
		}

		description, err = gtk.LabelNew(fmt.Sprintf("Receive (%s)", attr.Address))
		if err != nil {
			return nil, err
		}

		icon, err = gtk.ImageNewFromIconName("go-previous",
			gtk.ICON_SIZE_SMALL_TOOLBAR)
		if err != nil {
			return nil, err
		}
	}
	grid.Attach(icon, 0, 0, 2, 2)
	grid.Attach(description, 2, 1, 2, 1)
	description.SetHAlign(gtk.ALIGN_START)
	grid.Attach(amtLabel, 3, 0, 1, 1)
	amtLabel.SetHAlign(gtk.ALIGN_END)
	amtLabel.SetHExpand(true)

	date, err := gtk.LabelNew(attr.Date.Format("Jan 2, 2006 at 3:04 PM"))
	if err != nil {
		return nil, err
	}
	grid.Attach(date, 2, 0, 1, 1)
	date.SetHAlign(gtk.ALIGN_START)

	grid.SetHAlign(gtk.ALIGN_FILL)

	return &grid.Container.Widget, nil
}
Esempio n. 4
0
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
}