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
}
示例#2
0
func uiSetup() {
	var err error

	cssProvider, err = gtk.CssProviderNew()
	e.Exit(err)
	err = cssProvider.LoadFromData(css)
	e.Exit(err)

	w.count, err = gtk.SpinButtonNewWithRange(1, 999, 1)
	e.Exit(err)
	w.count.SetValue(1)

	shuffle, err := gtk.ButtonNewWithLabel("Shuffle")
	e.Exit(err)

	w.showActionsText, err = gtk.CheckButtonNewWithMnemonic("Show actions _text")
	e.Exit(err)
	w.showPermutation, err = gtk.CheckButtonNewWithMnemonic("Show _permutation")
	e.Exit(err)

	w.cellSize, err = gtk.SpinButtonNewWithRange(1, 999, 1)
	e.Exit(err)
	w.cellSize.SetValue(32)

	cellSizeLabel, err := gtk.LabelNew("Cell size:")
	e.Exit(err)

	w.count.Connect("changed", uiShuffle)
	w.count.Connect("activate", uiShuffle)
	shuffle.Connect("clicked", uiShuffle)
	w.showActionsText.Connect("toggled", uiReset)
	w.showPermutation.Connect("toggled", uiReset)
	w.cellSize.Connect("changed", uiReset)

	panel, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	e.Exit(err)
	panel.SetSpacing(5)
	panel.Add(w.count)
	panel.Add(shuffle)
	panel.Add(w.showActionsText)
	panel.Add(w.showPermutation)
	panel.Add(cellSizeLabel)
	panel.Add(w.cellSize)

	w.fieldWindow, err = gtk.ScrolledWindowNew(nil, nil)
	e.Exit(err)

	layout, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	e.Exit(err)
	layout.Add(panel)
	layout.PackStart(w.fieldWindow, true, true, 0)

	window, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	e.Exit(err)
	window.SetTitle(title)
	window.Add(layout)
	window.Connect("destroy", gtk.MainQuit)
	uiShuffle()
	window.ShowAll()
}
示例#3
0
func main() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new label widget to show in the window.
	l, err := gtk.LabelNew("Hello, gotk3!")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}

	// Add the label to the window.
	win.Add(l)

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}
示例#4
0
文件: ui.go 项目: juanfgs/checkers
// Handles user interaction with the board
func (self *MainWindow) interactBoard(eb *gtk.EventBox, event *gdk.Event) {
	evbutton := &gdk.EventButton{event}

	y, x, error := self.calculatePosition(evbutton.X(), evbutton.Y())

	if error == nil && !self.Board.SelectTile(x, y) {
		lastx, lasty := self.getSelectedPiece()
		if lastx != -1 && self.Board.Places[y][x] == nil {
			err := self.Board.MovePiece(lastx, lasty, x, y)

			if err != nil {
				errorMessage, _ := gtk.LabelNew(err.Error())
				alert, _ := gtk.DialogNew()
				alert.SetTitle("Error")
				alert.AddButton("Dismiss", gtk.RESPONSE_CLOSE)
				box, _ := alert.GetContentArea()
				box.Add(errorMessage)
				box.ShowAll()
				if alert.Run() == int(gtk.RESPONSE_CLOSE) {
					alert.Destroy()
				}

			} else {
				self.Board.Places[y][x].Selected = false
			}

		}
	}

	self.BoardView.QueueDraw()
}
示例#5
0
func listAppend(labelText string) {
	l, err := gtk.LabelNew(labelText)
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	gtkList.Add(l)
	gtkList.ShowAll()
}
示例#6
0
func (u *gtkUI) showFingerprintsForPeer(jid string, account *account) {
	builder := builderForDefinition("PeerFingerprints")
	dialog := getObjIgnoringErrors(builder, "dialog").(*gtk.Dialog)
	info := getObjIgnoringErrors(builder, "information").(*gtk.Label)
	grid := getObjIgnoringErrors(builder, "grid").(*gtk.Grid)

	info.SetSelectable(true)

	fprs := []*config.Fingerprint{}
	p, ok := account.session.GetConfig().GetPeer(jid)
	if ok {
		fprs = p.Fingerprints
	}

	if len(fprs) == 0 {
		info.SetText(fmt.Sprintf(i18n.Local("There are no known fingerprints for %s"), jid))
	} else {
		info.SetText(fmt.Sprintf(i18n.Local("These are the fingerprints known for %s:"), jid))
	}

	for ix, fpr := range fprs {
		flabel, _ := gtk.LabelNew(config.FormatFingerprint(fpr.Fingerprint))
		flabel.SetSelectable(true)
		trusted := i18n.Local("not trusted")
		if fpr.Trusted {
			trusted = i18n.Local("trusted")
		}

		ftrusted, _ := gtk.LabelNew(trusted)
		ftrusted.SetSelectable(true)

		grid.Attach(flabel, 0, ix, 1, 1)
		grid.Attach(ftrusted, 1, ix, 1, 1)
	}

	builder.ConnectSignals(map[string]interface{}{
		"on_close_signal": func() {
			dialog.Destroy()
		},
	})

	dialog.SetTransientFor(u.window)
	dialog.ShowAll()
}
示例#7
0
func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	panicIfNotNil(err)
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})
	win.SetDefaultSize(1280, 720)
	win.SetTitle("mauIRC Desktop")

	// Create a new grid widget to arrange child widgets
	grid, err := gtk.GridNew()
	panicIfNotNil(err)
	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)

	loginLabel, err := gtk.LabelNew("Log in to mauIRC")
	panicIfNotNil(err)

	email, err := gtk.EntryNew()
	panicIfNotNil(err)

	password, err := gtk.EntryNew()
	panicIfNotNil(err)
	password.SetVisibility(false)

	btn, err := gtk.ButtonNewWithLabel("Log in")
	panicIfNotNil(err)

	grid.Attach(loginLabel, 0, 2, 1, 1)
	grid.Attach(email, 0, 3, 1, 1)
	grid.Attach(password, 0, 4, 1, 1)
	grid.Attach(btn, 0, 5, 1, 1)

	//grid.Attach(nb, 1, 1, 1, 2)
	//nb.SetHExpand(true)
	//nb.SetVExpand(true)

	/*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)*/

	win.Add(grid)
	win.ShowAll()

	gtk.Main()
}
示例#8
0
文件: ui.go 项目: juanfgs/checkers
// Initialize the game widgets
func (self *MainWindow) InitializeWidgets() {

	self.BoardView, self.err = gtk.DrawingAreaNew()
	self.MainArea, self.err = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 1)
	self.ScoreArea, self.err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 2)
	self.BoardEventBox, self.err = gtk.EventBoxNew()
	self.Scores, self.err = gtk.LabelNew("Scores:")
	self.BlacksScore, self.err = gtk.LabelNew("Black pieces:")
	self.RedsScore, self.err = gtk.LabelNew("Black pieces:")
	self.BoardWidth = 640
	self.BoardHeight = 480
	self.BoardEventBox.Add(self.BoardView)
	if self.err != nil {
		log.Fatal("Failed to draw board")
	}

	self.BoardEventBox.AddEvents(int(gdk.BUTTON_PRESS_MASK))
	self.BoardEventBox.Connect("button_press_event", self.interactBoard)
	self.MainArea.PackStart(self.BoardEventBox, true, true, 10)
	self.MainArea.Add(self.ScoreArea)

	self.Scores.SetMarkup("<strong>%s</strong>")
	self.Scores.SetJustify(gtk.JUSTIFY_CENTER)

	self.ScoreArea.Add(self.Scores)
	self.BlacksScore.SetJustify(gtk.JUSTIFY_LEFT)
	self.RedsScore.SetJustify(gtk.JUSTIFY_LEFT)
	self.ScoreArea.Add(self.BlacksScore)
	self.ScoreArea.Add(self.RedsScore)

	self.Window.Add(self.MainArea)
	self.setBoardSize(8)
	self.BoardView.Connect("draw", self.drawBoard)
	self.Board.RenderText()

	self.Window.SetTitle("Checkers")
}
示例#9
0
func (dialog *EditMenuDialog) CreateDialog(extra *gtk.Widget) (err error) {
	d := dialog.dialog
	d.SetTitle("New Element")

	var active string
	active, err = dialog.fts.GetValueById(dialog.fts.GetCurrentId())
	if err != nil {
		return
	}

	var box *gtk.Box
	box, err = d.GetContentArea()
	if err != nil {
		return
	}

	activeText, err := gtk.LabelNew(fmt.Sprintf("%s", active))
	if err != nil {
		return
	}
	activeLayoutBox, err := createLabeledRow("Active element:", &activeText.Widget)
	if err != nil {
		return
	}
	box.PackStart(activeLayoutBox, false, false, 6)

	if extra != nil {
		box.PackStart(extra, false, false, 6)
	}

	dialog.stack, err = gtk.StackNew()
	if err != nil {
		return
	}
	err = dialog.fillStack()
	if err != nil {
		return
	}
	box.PackStart(dialog.stack, true, true, 6)

	d.AddButton("Cancel", gtk.RESPONSE_CANCEL)
	d.AddButton("OK", gtk.RESPONSE_OK)
	d.SetDefaultResponse(gtk.RESPONSE_OK)
	d.ShowAll()
	return
}
示例#10
0
func buildWidgetsForFields(fields []interface{}) []formField {
	ret := make([]formField, 0, len(fields))

	for _, f := range fields {
		switch field := f.(type) {
		case *data.TextFormField:
			//TODO: notify if it is required
			l, _ := gtk.LabelNew(field.Label)
			l.SetSelectable(true)

			w, _ := gtk.EntryNew()
			w.SetText(field.Default)
			w.SetVisibility(!field.Private)

			ret = append(ret, formField{field, l, w})
		default:
			log.Println("Missing to implement form field:", field)
		}
	}

	return ret
}
示例#11
0
文件: signals.go 项目: adrien3d/gobox
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(sb *gtk.SpinButton, pb *gtk.ProgressBar) {
		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.
	// These can be used by using the equivalent go type (in this case,
	// a string) as a closure argument.
	label.Connect("activate-link", func(_ *gtk.Label, uri string) {
		fmt.Println("you clicked a link to:", uri)
	})

	return &grid.Container.Widget
}
示例#12
0
文件: gtk3.go 项目: adrien3d/gobox
func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Impossible de créer la fenêtre :", err)
	}
	win.SetTitle("GoBox a0.1")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	grid, err := gtk.GridNew()
	if err != nil {
		log.Fatal("Impossible de créer la grille :", err)
	}

	label1, err := gtk.LabelNew("Adresse IP / Port : ")
	if err != nil {
		log.Fatal("Impossible de créer le label IP :", err)
	}

	label3, err := gtk.LabelNew("Dossier à synchroniser : ")
	if err != nil {
		log.Fatal("Impossible de créer le label Dossier :", err)
	}

	entry1, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Impossible de créer le champ IP :", err)
	}
	entry2, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Impossible de créer le champ Port :", err)
	}
	entry3, err := gtk.EntryNew()
	if err != nil {
		log.Fatal("Impossible de créer le champ Dossier :", err)
	}

	btn, err := gtk.ButtonNewWithLabel("Lancer la synchronisation")
	if err != nil {
		log.Fatal("Impossible de créer le bouton synchronisation :", err)
	}

	/*btn2, err := gtk.FileChooserButtonNew("Choix")
	  if err != nil {
	      log.Fatal("Impossible de créer le bouton choix :", err)
	  }*/

	grid.SetOrientation(gtk.ORIENTATION_HORIZONTAL)
	//Attach(child IWidget, left, top, width, height int)
	grid.Add(label1)
	grid.SetOrientation(gtk.ORIENTATION_HORIZONTAL)
	grid.Add(entry1)
	grid.Add(entry2)

	grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
	grid.Add(label3)
	grid.Add(entry3)

	grid.Attach(btn, 1, 2, 1, 2)

	btn.Connect("clicked", func() {
		/*dialog, _ := gtk.DialogNew()

		  filechooser, _ := gtk.FileChooserWidgetNew(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
		  dialog.AddButton("Valider", gtk.RESPONSE_ACCEPT)
		  dialog.AddButton("Annuler", gtk.RESPONSE_CANCEL)
		  dialog.SetTitle("Choisir le dossier a synchroniser")
		  box, _ := dialog.GetContentArea()
		  box.Add(filechooser)
		  box.ShowAll()
		  log.Print("Clic lancer synchro")*/
		filechooserdialog, _ := gtk.FileChooserDialogNewWith1Button(
			"Choisissez un fichier ...",
			//btn.GetTopLevelAsWindow(),
			win,
			gtk.FILE_CHOOSER_ACTION_OPEN,
			"Valider",
			gtk.RESPONSE_ACCEPT)
		/*filter := gtk.NewFileFilter()
		  filter.AddPattern("*.go")
		  filechooserdialog.AddFilter(filter)*/
		filechooserdialog.Response(func() {
			println(filechooserdialog.GetFilename())
			filechooserdialog.Destroy()
		})
		filechooserdialog.Run()
	})
	/*
	   nbChildAll, err := gtk.LabelNew("Tous mes fichiers sont ici")
	   if err != nil {
	       log.Fatal("Unable to create button:", err)
	   }
	   nbTabAll, err := gtk.LabelNew("Tout")
	   if err != nil {
	       log.Fatal("Unable to create label:", err)
	   }

	   nbChildMusic, err := gtk.LabelNew("Toute ma musique est ici")
	   if err != nil {
	       log.Fatal("Unable to create button:", err)
	   }
	   nbTabMusic, err := gtk.LabelNew("Musique")
	   if err != nil {
	       log.Fatal("Unable to create label:", err)
	   }

	   nbChildPhotos, err := gtk.LabelNew("Toutes mes photos sont ici")
	   if err != nil {
	       log.Fatal("Unable to create button:", err)
	   }
	   nbTabPhotos, err := gtk.LabelNew("Photos")
	   if err != nil {
	       log.Fatal("Unable to create label:", err)
	   }

	   nbChildVideos, err := gtk.LabelNew("Toutes mes vidéos sont ici")
	   if err != nil {
	       log.Fatal("Unable to create button:", err)
	   }
	   nbTabVideos, err := gtk.LabelNew("Vidéos")
	   if err != nil {
	       log.Fatal("Unable to create label:", err)
	   }
	   nb.AppendPage(nbChildAll, nbTabAll)
	   nb.AppendPage(nbChildMusic, nbTabMusic)
	   nb.AppendPage(nbChildPhotos, nbTabPhotos)
	   nb.AppendPage(nbChildVideos, nbTabVideos)*/

	win.Add(grid)
	win.SetDefaultSize(200, 250)
	win.ShowAll()

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

	// Just as a demonstration, we create and destroy a Label without ever
	// adding it to a container.  In native GTK, this would result in a
	// memory leak, since gtk_widget_destroy() will not deallocate any
	// memory when passed a GtkWidget with a floating reference.
	//
	// gotk3 handles this situation by always sinking floating references
	// of any struct type embedding a glib.InitiallyUnowned, and by setting
	// a finalizer to unreference the object when Go has lost scope of the
	// variable.  Due to this design, widgets may be allocated freely
	// without worrying about handling memory incorrectly.
	//
	// The following code is not entirely useful (except to demonstrate
	// this point), but it is also not "incorrect" as the C equivalent
	// would be.
	unused, err := gtk.LabelNew("This label is never used")
	if err != nil {
		// Calling Destroy() is also unnecessary in this case.  The
		// memory will still be freed with or without calling it.
		unused.Destroy()
	}

	sw, err := gtk.ScrolledWindowNew(nil, nil)
	if err != nil {
		log.Fatal("Unable to create scrolled window:", err)
	}

	grid.Attach(sw, 0, 0, 2, 1)
	sw.SetHExpand(true)
	sw.SetVExpand(true)

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

	sw.Add(labelsGrid)
	labelsGrid.SetHExpand(true)

	insertBtn, err := gtk.ButtonNewWithLabel("Add a label")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}
	removeBtn, err := gtk.ButtonNewWithLabel("Remove a label")
	if err != nil {
		log.Fatal("Unable to create button:", err)
	}

	nLabels := 1
	insertBtn.Connect("clicked", func() {
		var s string
		if nLabels == 1 {
			s = fmt.Sprintf("Inserted %d label.", nLabels)
		} else {
			s = fmt.Sprintf("Inserted %d labels.", nLabels)
		}
		label, err := gtk.LabelNew(s)
		if err != nil {
			log.Print("Unable to create label:", err)
			return
		}

		labelList.PushBack(label)
		labelsGrid.Add(label)
		label.SetHExpand(true)
		labelsGrid.ShowAll()

		nLabels++
	})

	removeBtn.Connect("clicked", func() {
		e := labelList.Front()
		if e == nil {
			log.Print("Nothing to remove")
			return
		}
		lab, ok := labelList.Remove(e).(*gtk.Label)
		if !ok {
			log.Print("Element to remove is not a *gtk.Label")
			return
		}
		// (*Widget).Destroy() breaks this label's reference with all
		// other objects (in this case, the Grid container it was added
		// to).
		lab.Destroy()

		// At this point, only Go retains a reference to the GtkLabel.
		// When the lab variable goes out of scope when this function
		// returns, at the next garbage collector run, a finalizer will
		// be run to perform the final unreference and free the widget.
	})

	grid.Attach(insertBtn, 0, 1, 1, 1)
	grid.Attach(removeBtn, 1, 1, 1, 1)

	return &grid.Container.Widget
}
示例#14
0
文件: newgtk.go 项目: sqp/godock
// Label creates a *gtk.Label.
func Label(label string) *gtk.Label {
	w, _ := gtk.LabelNew(label)
	return w
}
示例#15
0
文件: grid.go 项目: adrien3d/gobox
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()
}
示例#16
0
func (*RealGtk) LabelNew(str string) (gtki.Label, error) {
	return wrapLabel(gtk.LabelNew(str))
}