當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gtk.GridNew函數代碼示例

本文整理匯總了Golang中github.com/conformal/gotk3/gtk.GridNew函數的典型用法代碼示例。如果您正苦於以下問題:Golang GridNew函數的具體用法?Golang GridNew怎麽用?Golang GridNew使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GridNew函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createTxInfo

func createTxInfo() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	l, err := gtk.LabelNew("")
	if err != nil {
		log.Fatal(err)
	}
	l.SetMarkup("<b>Recent Transactions</b>")
	l.OverrideFont("sans-serif 10")
	l.SetHAlign(gtk.ALIGN_START)
	grid.Add(l)

	txGrid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}
	txGrid.SetOrientation(gtk.ORIENTATION_VERTICAL)
	grid.Add(txGrid)

	Overview.Txs = txGrid

	return &grid.Container.Widget
}
開發者ID:hsk81,項目名稱:btcgui,代碼行數:27,代碼來源:overview.go

示例2: createStatusbar

func createStatusbar() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}

	l, err := gtk.LabelNew("Connecting to daemon...")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	StatusElems.Lab = l
	grid.Add(l)

	p, err := gtk.ProgressBarNew()
	if err != nil {
		log.Fatal("Unable to create progress bar:", err)
	}
	StatusElems.Pb = p
	p.SetSizeRequest(300, -1)
	p.SetFraction(0)
	p.Set("show-text", true)
	p.SetText("")
	p.SetNoShowAll(true)
	grid.Add(p)

	return &grid.Container.Widget
}
開發者ID:hsk81,項目名稱:btcgui,代碼行數:27,代碼來源:statusbar.go

示例3: windowWidget

func windowWidget() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal("Unable to create grid:", err)
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	topLabel, err = gtk.LabelNew("Text set by initializer")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	bottomLabel, err = gtk.LabelNew("Text set by initializer")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}

	grid.Add(topLabel)
	grid.Add(bottomLabel)
	topLabel.SetHExpand(true)
	topLabel.SetVExpand(true)
	bottomLabel.SetHExpand(true)
	bottomLabel.SetVExpand(true)

	return &grid.Container.Widget
}
開發者ID:alimy,項目名稱:gotk3,代碼行數:25,代碼來源:goroutines.go

示例4: createOverview

func createOverview() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}

	grid.SetColumnHomogeneous(true)
	grid.Add(createWalletInfo())
	grid.Add(createTxInfo())

	return &grid.Container.Widget
}
開發者ID:hsk81,項目名稱:btcgui,代碼行數:12,代碼來源:overview.go

示例5: openNewPage

// 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
}
開發者ID:jrick,項目名稱:xombrero2,代碼行數:52,代碼來源:pages.go

示例6: newHTMLPage

// newHTMLPage creates a new HTML page and begins loading the URI in the
// description.
func (d HTMLPageDescription) newHTMLPage() *HTMLPage {
	grid, _ := gtk.GridNew()
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
	navbar := NewNavigationBar()
	navbar.SetHExpand(true)
	wv := wk2.NewWebView()
	wv.SetHExpand(true)
	wv.SetVExpand(true)
	title, _ := gtk.LabelNew("New Tab")
	title.SetEllipsize(pango.ELLIPSIZE_END)
	crash, _ := gtk.LabelNew("WebKit crashed :'(")

	grid.SetCanFocus(false)
	navbar.SetCanFocus(false)
	title.SetCanFocus(false)

	grid.Add(navbar)
	navbar.Show()
	grid.Add(wv)
	grid.Show()

	stack, _ := gtk.StackNew()
	stack.SetCanFocus(false)
	stack.AddNamed(grid, "webview")
	stack.AddNamed(crash, "crash")
	stack.SetVisibleChild(crash)

	page := &HTMLPage{
		Stack:      stack,
		title:      "New Tab",
		uri:        string(d),
		titleLabel: title,
		navbar:     navbar,
		wv:         wv,
		crash:      crash,
	}

	page.signals = append(page.signals, page.connectNavbarSignals()...)
	page.signals = append(page.signals, page.connectWebKitSignals()...)

	page.setURI(string(d))

	stack.SetVisibleChild(grid)
	wv.Show()
	page.LoadURI(string(d))

	return page
}
開發者ID:jrick,項目名稱:xombrero2,代碼行數:50,代碼來源:pages.go

示例7: createWalletInfo

func createWalletInfo() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal(err)
	}

	header, err := gtk.LabelNew("")
	if err != nil {
		log.Fatal(err)
	}
	header.SetMarkup("<b>Wallet</b>")
	header.OverrideFont("sans-serif 16")
	header.SetHAlign(gtk.ALIGN_START)
	grid.Attach(header, 0, 0, 1, 1)

	balance, err := gtk.LabelNew("Balance:")
	if err != nil {
		log.Fatal(err)
	}
	balance.SetHAlign(gtk.ALIGN_START)
	grid.Attach(balance, 0, 1, 1, 1)

	unconfirmed, err := gtk.LabelNew("Unconfirmed:")
	if err != nil {
		log.Fatal(err)
	}
	unconfirmed.SetHAlign(gtk.ALIGN_START)
	grid.Attach(unconfirmed, 0, 2, 1, 1)

	balance, err = gtk.LabelNew("")
	if err != nil {
		log.Fatal(err)
	}
	balance.SetHAlign(gtk.ALIGN_START)
	grid.Attach(balance, 1, 1, 1, 1)
	Overview.Balance = balance

	unconfirmed, err = gtk.LabelNew("")
	if err != nil {
		log.Fatal(err)
	}
	grid.Attach(unconfirmed, 1, 2, 1, 1)
	Overview.Unconfirmed = unconfirmed

	/*
		transactions, err := gtk.LabelNew("Number of transactions:")
		if err != nil {
			log.Fatal(err)
		}
		transactions.SetHAlign(gtk.ALIGN_START)
		grid.Attach(transactions, 0, 3, 1, 1)

		transactions, err = gtk.LabelNew("a lot")
		if err != nil {
			log.Fatal(err)
		}
		transactions.SetHAlign(gtk.ALIGN_START)
		grid.Attach(transactions, 1, 3, 1, 1)
		Overview.NTransactions = transactions
	*/

	return &grid.Container.Widget
}
開發者ID:hsk81,項目名稱:btcgui,代碼行數:63,代碼來源:overview.go

示例8: createNewWalletDialog

func createNewWalletDialog() (*gtk.Dialog, error) {
	dialog, err := gtk.DialogNew()
	if err != nil {
		return nil, err
	}
	dialog.SetTitle("New wallet")

	dialog.AddButton("_OK", gtk.RESPONSE_OK)

	dialog.SetDefaultGeometry(500, 100)

	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetHExpand(true)
	grid.SetVExpand(true)

	b, err := dialog.GetContentArea()
	if err != nil {
		return nil, err
	}
	b.Add(grid)

	// Because the label will wrap and the final minimum heights
	// and widths will be absurdly large, first give a size request and
	// show the grid (allocating space for the requested size).  This will
	// make text wrapping labels size nicely inside the grid.
	grid.SetSizeRequest(500, 100)
	grid.Show()

	l, err := gtk.LabelNew("")
	if err != nil {
		return nil, err
	}
	l.SetLineWrap(true)
	l.SetMarkup(newWalletMessage)
	l.SetAlignment(0, 0)
	grid.Attach(l, 0, 0, 2, 1)

	b.SetHExpand(true)
	b.SetVExpand(true)

	l, err = gtk.LabelNew("Enter passphrase:")
	if err != nil {
		return nil, err
	}
	l.SetAlignment(1.0, 0.5)
	grid.Attach(l, 0, 1, 1, 1)

	passphrase, err := gtk.EntryNew()
	if err != nil {
		return nil, err
	}
	passphrase.SetVisibility(false)
	passphrase.SetHExpand(true)
	passphrase.Connect("activate", func() {
		dialog.Emit("response", gtk.RESPONSE_OK, nil)
	})
	grid.Attach(passphrase, 1, 1, 1, 1)

	l, err = gtk.LabelNew("Confirm passphrase:")
	if err != nil {
		return nil, err
	}
	l.SetAlignment(1.0, 0.5)
	grid.Attach(l, 0, 2, 1, 1)

	repeated, err := gtk.EntryNew()
	if err != nil {
		return nil, err
	}
	repeated.SetVisibility(false)
	repeated.SetVAlign(gtk.ALIGN_START)
	repeated.Connect("activate", func() {
		dialog.Emit("response", gtk.RESPONSE_OK, nil)
	})
	grid.Attach(repeated, 1, 2, 1, 1)

	showEntryText, err := gtk.CheckButtonNewWithLabel("Show passphrase")
	if err != nil {
		return nil, err
	}
	showEntryText.Connect("toggled", func() {
		active := showEntryText.GetActive()
		passphrase.SetVisibility(active)
		repeated.SetVisibility(active)
	})
	grid.Attach(showEntryText, 1, 3, 2, 1)

	dialog.SetTransientFor(mainWindow)
	dialog.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
	dialog.ShowAll()

	dialog.Connect("response", func(_ *glib.Object, rt gtk.ResponseType) {
		switch rt {
		case gtk.RESPONSE_OK:
			pStr, err := passphrase.GetText()
			if err != nil {
				log.Print(err)
//.........這裏部分代碼省略.........
開發者ID:hsk81,項目名稱:btcgui,代碼行數:101,代碼來源:newwalletdialog.go

示例9: createAddrBook

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)
		}
//.........這裏部分代碼省略.........
開發者ID:hsk81,項目名稱:btcgui,代碼行數:101,代碼來源:addressbook.go

示例10: createEncryptionDialog

func createEncryptionDialog() (*gtk.Dialog, error) {
	dialog, err := gtk.DialogNew()
	if err != nil {
		return nil, err
	}
	dialog.SetTitle("Encrypt wallet")

	dialog.AddButton("_OK", gtk.RESPONSE_OK)
	dialog.AddButton("_Cancel", gtk.RESPONSE_CANCEL)

	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetHExpand(true)
	grid.SetVExpand(true)
	b, err := dialog.GetContentArea()
	if err != nil {
		return nil, err
	}
	b.Add(grid)
	b.SetHExpand(true)
	b.SetVExpand(true)

	l, err := gtk.LabelNew("")
	if err != nil {
		return nil, err
	}
	l.SetMarkup(encryptMessage)
	l.SetHExpand(true)
	l.SetVExpand(true)
	l.SetHAlign(gtk.ALIGN_START)
	grid.Attach(l, 0, 0, 2, 1)

	l, err = gtk.LabelNew("New passphrase")
	if err != nil {
		return nil, err
	}
	grid.Attach(l, 0, 1, 1, 1)

	passphrase, err := gtk.EntryNew()
	if err != nil {
		return nil, err
	}
	passphrase.SetVisibility(false)
	passphrase.SetHExpand(true)
	passphrase.Connect("activate", func() {
		dialog.Emit("response", gtk.RESPONSE_OK, nil)
	})
	grid.Attach(passphrase, 1, 1, 1, 1)

	l, err = gtk.LabelNew("Repeat new passphrase")
	if err != nil {
		return nil, err
	}
	l.SetVExpand(true)
	l.SetVAlign(gtk.ALIGN_START)
	grid.Attach(l, 0, 2, 1, 1)

	repeated, err := gtk.EntryNew()
	if err != nil {
		return nil, err
	}
	repeated.SetVisibility(false)
	repeated.SetVExpand(true)
	repeated.SetVAlign(gtk.ALIGN_START)
	repeated.Connect("activate", func() {
		dialog.Emit("response", gtk.RESPONSE_OK, nil)
	})
	grid.Attach(repeated, 1, 2, 1, 1)

	dialog.SetTransientFor(mainWindow)
	dialog.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
	dialog.ShowAll()

	dialog.Connect("response", func(_ *glib.Object, rt gtk.ResponseType) {
		switch rt {
		case gtk.RESPONSE_OK:
			pStr, err := passphrase.GetText()
			if err != nil {
				log.Print(err)
				return
			}
			rStr, err := repeated.GetText()
			if err != nil {
				log.Print(err)
				return
			}
			if pStr == rStr {
				// use the passphrase, encrypt wallet...
				dialog.Destroy()
			} else {
				msg := "The supplied passphrases do not match."
				mDialog := gtk.MessageDialogNew(dialog, 0,
					gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg)
				mDialog.SetTitle("Wallet encryption failed")
				mDialog.Run()
				mDialog.Destroy()
			}
		case gtk.RESPONSE_CANCEL:
//.........這裏部分代碼省略.........
開發者ID:hsk81,項目名稱:btcgui,代碼行數:101,代碼來源:encryptdialog.go

示例11: main

func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("UDP client v0.0.1")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	var c client.Client
	answers := make(chan string)

	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal("Unable to create grid:", err)
	}

	messageHistory, err := gtk.TextViewNew()
	if err != nil {
		log.Fatal("Unable to create TextView:", err)
	}
	grid.Attach(messageHistory, 0, 0, 4, 1)

	messageEntry, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Unable to create entry:", err)
	}
	grid.Attach(messageEntry, 0, 1, 1, 1)

	privateEntry, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Unable to create entry:", err)
	}
	grid.Attach(privateEntry, 1, 1, 1, 1)

	sendButton, err := gtk.ButtonNewWithLabel("Send")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	sendButton.Connect("clicked", func(btn *gtk.Button) {
		lbl, _ := btn.GetLabel()
		if lbl != "Send" {
			return
		}
		log.Print(lbl)
		msg, _ := messageEntry.GetText()
		log.Print(msg)
		c.Message(msg)
	})
	grid.Attach(sendButton, 0, 2, 1, 1)

	privateButton, err := gtk.ButtonNewWithLabel("Private")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	privateButton.Connect("clicked", func(btn *gtk.Button) {
		lbl, _ := btn.GetLabel()
		if lbl != "Private" {
			return
		}
		log.Print(lbl)
		private, _ := privateEntry.GetText()
		log.Print(private)
		if private != "" {
			msg, _ := messageEntry.GetText()
			log.Print(msg)
			c.Private(private, msg)
		}
	})
	grid.Attach(privateButton, 1, 2, 1, 1)

	listButton, err := gtk.ButtonNewWithLabel("List")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	listButton.Connect("clicked", func(btn *gtk.Button) {
		lbl, _ := btn.GetLabel()
		if lbl != "List" {
			return
		}
		log.Print(lbl)
		c.List()
		log.Print(lbl)
	})
	grid.Attach(listButton, 2, 1, 1, 1)

	leaveButton, err := gtk.ButtonNewWithLabel("Leave")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	leaveButton.Connect("clicked", func(btn *gtk.Button) {
		lbl, _ := btn.GetLabel()
		if lbl != "Leave" {
			return
		}
		log.Print(lbl)
		c.Leave()
//.........這裏部分代碼省略.........
開發者ID:fiddenmar,項目名稱:netlabs,代碼行數:101,代碼來源:gui.go

示例12: main

func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Grid Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new grid widget to arrange child widgets
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal("Unable to create grid:", err)
	}

	// gtk.Grid embeds an Orientable struct to simulate the GtkOrientable
	// GInterface.  Set the orientation from the default horizontal to
	// vertical.
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	// Create some widgets to put in the grid.
	lab, err := gtk.LabelNew("Just a label")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}

	btn, err := gtk.ButtonNewWithLabel("Button with label")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}

	entry, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Unable to create entry:", err)
	}

	spnBtn, err := gtk.SpinButtonNewWithRange(0.0, 1.0, 0.001)
	if err != nil {
		log.Fatal("Unable to create spin button:", err)
	}

	nb, err := gtk.NotebookNew()
	if err != nil {
		log.Fatal("Unable to create notebook:", err)
	}

	// Calling (*gtk.Container).Add() with a gtk.Grid will add widgets next
	// to each other, in the order they were added, to the right side of the
	// last added widget when the grid is in a horizontal orientation, and
	// at the bottom of the last added widget if the grid is in a vertial
	// orientation.  Using a grid in this manner works similar to a gtk.Box,
	// but unlike gtk.Box, a gtk.Grid will respect its child widget's expand
	// and margin properties.
	grid.Add(btn)
	grid.Add(lab)
	grid.Add(entry)
	grid.Add(spnBtn)

	// Widgets may also be added by calling (*gtk.Grid).Attach() to specify
	// where to place the widget in the grid, and optionally how many rows
	// and columns to span over.
	//
	// Additional rows and columns are automatically added to the grid as
	// necessary when new widgets are added with (*gtk.Container).Add(), or,
	// as shown in this case, using (*gtk.Grid).Attach().
	//
	// In this case, a notebook is added beside the widgets inserted above.
	// The notebook widget is inserted with a left position of 1, a top
	// position of 1 (starting at the same vertical position as the button),
	// a width of 1 column, and a height of 2 rows (spanning down to the
	// same vertical position as the entry).
	//
	// This example also demonstrates how not every area of the grid must
	// contain a widget.  In particular, the area to the right of the label
	// and the right of spin button have contain no widgets.
	grid.Attach(nb, 1, 1, 1, 2)
	nb.SetHExpand(true)
	nb.SetVExpand(true)

	// Add a child widget and tab label to the notebook so it renders.
	nbChild, err := gtk.LabelNew("Notebook content")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	nbTab, err := gtk.LabelNew("Tab label")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	nb.AppendPage(nbChild, nbTab)

	// Add the grid to the window, and show all widgets.
	win.Add(grid)
	win.ShowAll()

	gtk.Main()
}
開發者ID:alimy,項目名稱:gotk3,代碼行數:99,代碼來源:grid.go

示例13: createRecipient

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()
//.........這裏部分代碼省略.........
開發者ID:hsk81,項目名稱:btcgui,代碼行數:101,代碼來源:sendcoins.go

示例14: CreateTutorialDialog

// CreateTutorialDialog opens a tutorial dialog explaining usage for a
// first-time user.  If appWindow is non-nil, it will be used as the
// parent window of the dialog.  If nil, the tutorial dialog will open as
// a top-level window and a new application main window will be created
// and opened after the final tutorial message is shown.
func CreateTutorialDialog(appWindow *gtk.Window) (*gtk.Dialog, error) {
	d, err := gtk.DialogNew()
	if err != nil {
		return nil, err
	}
	d.SetTitle("btcgui First Start Tutorial")
	box, err := d.GetContentArea()
	if err != nil {
		return nil, err
	}
	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
	box.Add(grid)

	d.SetDefaultGeometry(500, 100)

	if appWindow != nil {
		d.SetTransientFor(appWindow)
		d.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
	} else {
		d.Connect("destroy", func() {
			go StartMainApplication()
		})
		d.SetPosition(gtk.WIN_POS_CENTER)
	}

	// Add a notebook and tab for each dialog message.
	nb, err := gtk.NotebookNew()
	if err != nil {
		return nil, err
	}

	// Because the labels added below will wrap and their final minimum
	// heights and widths will be absurdly large, first give a size request
	// and show the notebook (allocating space for the requested size).
	// This will make text wrapping labels size nicely inside the notebook.
	nb.SetSizeRequest(500, 100)
	nb.Show()

	// Create messages and append each in a notebook page.
	for _, msg := range dialogMessages {
		lbl, err := gtk.LabelNew("")
		if err != nil {
			return nil, err
		}
		lbl.SetMarkup(msg)
		lbl.SetLineWrap(true)
		lbl.Show()
		lbl.SetAlignment(0, 0)
		nb.AppendPage(lbl, nil)
	}
	nb.SetShowTabs(false)
	grid.Add(nb)

	prevPage, err := d.AddButton("_Previous", gtk.RESPONSE_NONE)
	if err != nil {
		return nil, err
	}
	prevPage.SetSensitive(false)
	nextPage, err := d.AddButton("_Next", gtk.RESPONSE_NONE)
	if err != nil {
		return nil, err
	}
	prevPage.Connect("clicked", func() {
		nb.PrevPage()
		pagen := nb.GetCurrentPage()
		if pagen == 0 {
			prevPage.SetSensitive(false)
		}
		nextPage.SetSensitive(true)
	})
	nextPage.Connect("clicked", func() {
		nb.NextPage()
		pagen := nb.GetCurrentPage()
		if pagen == len(dialogMessages)-1 {
			nextPage.SetSensitive(false)
		}
		prevPage.SetSensitive(true)
	})
	_, err = d.AddButton("_Close", gtk.RESPONSE_CLOSE)
	if err != nil {
		return nil, err
	}
	d.Connect("response", func(_ *glib.Object, rt gtk.ResponseType) {
		if rt == gtk.RESPONSE_CLOSE {
			// Using w.Close() would be nice but it needs GTK 3.10.
			d.Hide()
			d.Destroy()
		}
	})

	return d, nil
//.........這裏部分代碼省略.........
開發者ID:hsk81,項目名稱:btcgui,代碼行數:101,代碼來源:tutorial.go

示例15: windowWidget

func windowWidget() *gtk.Widget {
	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal("Unable to create grid:", err)
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	entry, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Unable to create entry:", err)
	}
	s, _ := entry.GetText()
	label, err := gtk.LabelNew(s)
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	grid.Add(entry)
	entry.SetHExpand(true)
	grid.AttachNextTo(label, entry, gtk.POS_RIGHT, 1, 1)
	label.SetHExpand(true)

	// Connects this entry's "activate" signal (which is emitted whenever
	// Enter is pressed when the Entry is activated) to an anonymous
	// function that gets the current text of the entry and sets the text of
	// the label beside it with it.  Unlike with native GTK callbacks,
	// (*glib.Object).Connect() supports closures.  In this example, this is
	// demonstrated by using the label variable.  Without closures, a
	// pointer to the label would need to be passed in as user data
	// (demonstrated in the next example).
	entry.Connect("activate", func() {
		s, _ := entry.GetText()
		label.SetText(s)
	})

	sb, err := gtk.SpinButtonNewWithRange(0, 1, 0.1)
	if err != nil {
		log.Fatal("Unable to create spin button:", err)
	}
	pb, err := gtk.ProgressBarNew()
	if err != nil {
		log.Fatal("Unable to create progress bar:", err)
	}
	grid.Add(sb)
	sb.SetHExpand(true)
	grid.AttachNextTo(pb, sb, gtk.POS_RIGHT, 1, 1)
	label.SetHExpand(true)

	// Pass in a ProgressBar and the target SpinButton as user data rather
	// than using the sb and pb variables scoped to the anonymous func.
	// This can be useful when passing in a closure that has already been
	// generated, but when you still wish to connect the callback with some
	// variables only visible in this scope.
	sb.Connect("value-changed", func(obj *glib.Object, pb *gtk.ProgressBar) {
		sb := &gtk.SpinButton{gtk.Entry{gtk.Widget{
			glib.InitiallyUnowned{obj}}}}
		pb.SetFraction(sb.GetValue() / 1)
	}, pb)

	label, err = gtk.LabelNew("")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	s = "Hyperlink to <a href=\"https://www.cyphertite.com/\">Cyphertite</a> for your clicking pleasure"
	label.SetMarkup(s)
	grid.AttachNextTo(label, sb, gtk.POS_BOTTOM, 2, 1)

	// Some GTK callback functions require arguments, such as the
	// 'gchar *uri' argument of GtkLabel's "activate-link" signal.  To use
	// these arguments, pass in a *glib.CallbackContext as an argument, and
	// access by calling (*glib.CallbackContext).Arg(n) for the nth
	// argument.
	label.Connect("activate-link", func(_ *glib.Object, uri string) {
		fmt.Println("you clicked a link to:", uri)
	})

	return &grid.Container.Widget
}
開發者ID:kendellfab,項目名稱:gotk3,代碼行數:77,代碼來源:signals.go


注:本文中的github.com/conformal/gotk3/gtk.GridNew函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。