Пример #1
0
// NewPageManager creates and initializes a page manager.
func NewPageManager(session []PageDescription) *PageManager {
	nb, _ := gtk.NotebookNew()
	nb.SetCanFocus(false)
	nb.SetShowBorder(false)
	p := &PageManager{
		Notebook: nb,
		htmls:    map[uintptr]*HTMLPage{},
	}

	if session == nil {
		session = []PageDescription{BlankPage}
	}
	for _, page := range session {
		p.OpenPage(page)
	}

	actions := NewActionMenu()
	actions.newTab.Connect("activate", func() {
		n := p.OpenPage(BlankPage)
		p.FocusPageN(n)
	})
	actions.quit.Connect("activate", func() {
		gtk.MainQuit()
	})

	nb.SetActionWidget(actions, gtk.PACK_END)
	actions.Show()

	return p
}
Пример #2
0
// 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
}
Пример #3
0
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()
}
Пример #4
0
// CreateWindow creates the toplevel window for the GUI.
func CreateWindow() (*gtk.Window, error) {
	var err error
	mainWindow, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		return nil, err
	}
	mainWindow.SetTitle("btcgui")
	mainWindow.Connect("destroy", func() {
		gtk.MainQuit()
	})

	grid, err := gtk.GridNew()
	if err != nil {
		return nil, err
	}
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	grid.Add(createMenuBar())

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

	l, err := gtk.LabelNew("Overview")
	if err != nil {
		return nil, err
	}
	notebook.AppendPage(createOverview(), l)

	l, err = gtk.LabelNew("Send Coins")
	if err != nil {
		return nil, err
	}
	notebook.AppendPage(createSendCoins(), l)

	l, err = gtk.LabelNew("Receive Coins")
	if err != nil {
		return nil, err
	}
	notebook.AppendPage(createRecvCoins(), l)

	l, err = gtk.LabelNew("Transactions")
	if err != nil {
		log.Fatal(err)
	}
	notebook.AppendPage(createTransactions(), l)

	// TODO(jrick): Add back when address book is implemented.
	/*
		l, err = gtk.LabelNew("Address Book")
		if err != nil {
			log.Fatal(err)
		}
		notebook.AppendPage(createAddrBook(), l)
	*/

	grid.Add(createStatusbar())

	mainWindow.Add(grid)

	mainWindow.SetDefaultGeometry(800, 600)

	return mainWindow, nil
}