コード例 #1
0
ファイル: pages.go プロジェクト: jrick/xombrero2
// 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
}
コード例 #2
0
ファイル: ui.go プロジェクト: emersion/gnomeconnect
func (ui *Ui) initDeviceView() *gtk.Box {
	vbox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	ui.deviceBox = vbox

	hbox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	vbox.PackStart(hbox, false, true, 20)

	img, _ := gtk.ImageNew()
	hbox.PackStart(img, false, true, 0)
	ui.deviceIcon = img

	nameBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	hbox.PackStart(nameBox, true, true, 0)

	l, _ := gtk.LabelNew("")
	l.Set("xalign", 0)
	nameBox.PackStart(l, true, true, 0)
	ui.deviceNameLabel = l

	l, _ = gtk.LabelNew("")
	l.Set("xalign", 0)
	nameBox.PackStart(l, true, true, 0)
	ui.deviceStatusLabel = l

	browseBtn, _ := gtk.ButtonNewFromIconName("document-open-symbolic", gtk.ICON_SIZE_BUTTON)
	hbox.PackStart(browseBtn, false, false, 0)
	ui.browseBtn = browseBtn

	browseBtn.Connect("clicked", func() {
		log.Println("Browse device", ui.selectedDevice)
		ui.plugins.Sftp.SendStartBrowsing(ui.selectedDevice)
	})

	pairBtn, _ := gtk.ButtonNew()
	hbox.PackStart(pairBtn, false, false, 5)
	ui.pairBtn = pairBtn

	pairBtn.Connect("clicked", func() {
		log.Println("Pair/unpair device", ui.selectedDevice)

		if ui.selectedDevice.Paired {
			ui.engine.UnpairDevice(ui.selectedDevice)
		} else {
			ui.engine.PairDevice(ui.selectedDevice)
		}
	})

	return vbox
}
コード例 #3
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
}