Documentation ¶
Overview ¶
Package newgtk creates gtk objects.
Example ¶
///bin/true; exec /usr/bin/env go run "$0" "$@" // Shebang to directly run as script on unix like. package main import ( "github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" "github.com/sqp/godock/widgets/gtk/newgtk" // Create gtk widgets. "fmt" "os" "time" ) // How to create a simple Gtk3 Application in go. // Define your application informations. var appInfo = newgtk.AppInfo{ ID: "org.gtk.example", Title: "Basic Application", Width: 400, Height: 400, Flags: glib.APPLICATION_FLAGS_NONE, // See flags: https://godoc.org/github.com/gotk3/gotk3/glib#ApplicationFlags OnStart: onStart, // test OnActivateApp: onActivateApp, // test OnStop: onStop, // test } func init() { appInfo.OnActivateWin = onActivateWin } // set here only to prevents initialization loop with our test. // Start application and return error code if any. func main() { os.Exit(appInfo.Run()) } // Fill the window at creation. // // Move this and everything else in other packages. // This help the main package stay clean and not requiring impossible tests. func onActivateWin(win *gtk.ApplicationWindow) { win.Add(newgtk.Label("Hello, gotk3!")) win.ShowAll() // Don't forget to show your widgets. Most common problem for GTK beginners go time.AfterFunc(3*time.Second, win.Close) // Autoclose window for the test. title, _ := win.GetTitle() fmt.Println("win.Title :", title) fmt.Println("win.Size :", win.GetAllocatedWidth(), "x", win.GetAllocatedHeight()) fmt.Println("app.App != nil :", appInfo.App != nil) fmt.Println("app.Win != nil :", appInfo.Win != nil) } // test func onStart(app *gtk.Application) { fmt.Println("--[ started ]--") } func onActivateApp(app *gtk.Application) { fmt.Println("app.ID :", app.GetApplicationID()) } func onStop(app *gtk.Application) { fmt.Print("exit code : ") } func main() { // Auto tested example. fmt.Println(appInfo.Run()) }
Output: --[ started ]-- app.ID : org.gtk.example win.Title : Basic Application win.Size : 400 x 400 app.App != nil : true app.Win != nil : true exit code : 0
Index ¶
- func Adjustment(value, lower, upper, stepIncrement, pageIncrement, pageSize float64) *gtk.Adjustment
- func Application(appInfo *AppInfo) error
- func Box(orientation gtk.Orientation, spacing int) *gtk.Box
- func Button() *gtk.Button
- func ButtonFromIconName(label string, size gtk.IconSize) *gtk.Button
- func ButtonWithLabel(label string) *gtk.Button
- func ButtonWithMnemonic(label string) *gtk.Button
- func CellRendererPixbuf() *gtk.CellRendererPixbuf
- func CellRendererText() *gtk.CellRendererText
- func CellRendererToggle() *gtk.CellRendererToggle
- func CheckButton() *gtk.CheckButton
- func CheckMenuItemWithLabel(label string) *gtk.CheckMenuItem
- func ColorButtonWithRGBA(gdkColor *gdk.RGBA) *gtk.ColorButton
- func ComboBox() *gtk.ComboBox
- func ComboBoxText() *gtk.ComboBoxText
- func ComboBoxWithEntry() *gtk.ComboBox
- func ComboBoxWithModel(model gtk.ITreeModel) *gtk.ComboBox
- func Dialog() *gtk.Dialog
- func Entry() *gtk.Entry
- func Expander(label string) *gtk.Expander
- func FileChooserDialogWith2Buttons(title string, parent *gtk.Window, action gtk.FileChooserAction, ...) *gtk.FileChooserDialog
- func FileFilter() *gtk.FileFilter
- func FontButtonWithFont(fontname string) *gtk.FontButton
- func Frame(label string) *gtk.Frame
- func Grid() *gtk.Grid
- func Image() *gtk.Image
- func ImageFromFile(file string) *gtk.Image
- func ImageFromIconName(iconName string, size gtk.IconSize) *gtk.Image
- func Label(label string) *gtk.Label
- func LinkButtonWithLabel(uri, label string) *gtk.LinkButton
- func ListBox() *gtk.ListBox
- func ListBoxRow() *gtk.ListBoxRow
- func ListStore(types ...glib.Type) *gtk.ListStore
- func Menu() *gtk.Menu
- func MenuItem() *gtk.MenuItem
- func MenuItemWithLabel(label string) *gtk.MenuItem
- func Notebook() *gtk.Notebook
- func Paned(orientation gtk.Orientation) *gtk.Paned
- func RadioMenuItemWithLabel(group *glib.SList, label string) *gtk.RadioMenuItem
- func Scale(orientation gtk.Orientation, adjustment *gtk.Adjustment) *gtk.Scale
- func ScaleWithRange(orientation gtk.Orientation, min, max, step float64) *gtk.Scale
- func ScrolledWindow(hadjustment, vadjustment *gtk.Adjustment) *gtk.ScrolledWindow
- func Separator(orientation gtk.Orientation) *gtk.Separator
- func SeparatorMenuItem() *gtk.SeparatorMenuItem
- func SetOnError(onErr func(error))
- func SpinButtonWithRange(min, max, step float64) *gtk.SpinButton
- func Spinner() *gtk.Spinner
- func Stack() *gtk.Stack
- func StackSwitcher() *gtk.StackSwitcher
- func Switch() *gtk.Switch
- func TextView() *gtk.TextView
- func ToggleButton() *gtk.ToggleButton
- func ToggleButtonWithLabel(label string) *gtk.ToggleButton
- func TreeViewColumnWithAttribute(title string, renderer gtk.ICellRenderer, attribute string, column int) *gtk.TreeViewColumn
- func TreeViewWithModel(model gtk.ITreeModel) *gtk.TreeView
- func Window(t gtk.WindowType) *gtk.Window
- type AppInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Adjustment ¶
func Adjustment(value, lower, upper, stepIncrement, pageIncrement, pageSize float64) *gtk.Adjustment
Adjustment creates a *gtk.Adjustment.
func Application ¶
Application creates a *gtk.Application and connects its callbacks.
func ButtonFromIconName ¶
ButtonFromIconName creates a *gtk.Button.
func ButtonWithLabel ¶
ButtonWithLabel creates a *gtk.Button.
func ButtonWithMnemonic ¶
ButtonWithMnemonic creates a *gtk.Button.
func CellRendererPixbuf ¶
func CellRendererPixbuf() *gtk.CellRendererPixbuf
CellRendererPixbuf creates a *gtk.CellRendererPixbuf.
func CellRendererText ¶
func CellRendererText() *gtk.CellRendererText
CellRendererText creates a *gtk.CellRendererText.
func CellRendererToggle ¶
func CellRendererToggle() *gtk.CellRendererToggle
CellRendererToggle creates a *gtk.CellRendererToggle.
func CheckMenuItemWithLabel ¶
func CheckMenuItemWithLabel(label string) *gtk.CheckMenuItem
CheckMenuItemWithLabel creates a *gtk.CheckMenuItem.
func ColorButtonWithRGBA ¶
func ColorButtonWithRGBA(gdkColor *gdk.RGBA) *gtk.ColorButton
ColorButtonWithRGBA creates a *gtk.ColorButton.
func ComboBoxWithEntry ¶
ComboBoxWithEntry creates a *gtk.ComboBox.
func ComboBoxWithModel ¶
func ComboBoxWithModel(model gtk.ITreeModel) *gtk.ComboBox
ComboBoxWithModel creates a *gtk.ComboBox.
func FileChooserDialogWith2Buttons ¶
func FileChooserDialogWith2Buttons(title string, parent *gtk.Window, action gtk.FileChooserAction, firstText string, firstID gtk.ResponseType, secondText string, secondID gtk.ResponseType) *gtk.FileChooserDialog
FileChooserDialogWith2Buttons creates a *gtk.FileChooserDialog.
func FontButtonWithFont ¶
func FontButtonWithFont(fontname string) *gtk.FontButton
FontButtonWithFont creates a *gtk.FontButton.
func ImageFromIconName ¶
ImageFromIconName creates a *gtk.Image.
func LinkButtonWithLabel ¶
func LinkButtonWithLabel(uri, label string) *gtk.LinkButton
LinkButtonWithLabel creates a *gtk.LinkButton.
func MenuItemWithLabel ¶
MenuItemWithLabel creates a *gtk.MenuItem.
func RadioMenuItemWithLabel ¶
func RadioMenuItemWithLabel(group *glib.SList, label string) *gtk.RadioMenuItem
RadioMenuItemWithLabel creates a *gtk.RadioMenuItem.
func Scale ¶
func Scale(orientation gtk.Orientation, adjustment *gtk.Adjustment) *gtk.Scale
Scale creates a *gtk.Scale.
func ScaleWithRange ¶
func ScaleWithRange(orientation gtk.Orientation, min, max, step float64) *gtk.Scale
ScaleWithRange creates a *gtk.Scale.
func ScrolledWindow ¶
func ScrolledWindow(hadjustment, vadjustment *gtk.Adjustment) *gtk.ScrolledWindow
ScrolledWindow creates a *gtk.ScrolledWindow.
func Separator ¶
func Separator(orientation gtk.Orientation) *gtk.Separator
Separator creates a *gtk.Separator.
func SeparatorMenuItem ¶
func SeparatorMenuItem() *gtk.SeparatorMenuItem
SeparatorMenuItem creates a *gtk.SeparatorMenuItem.
func SetOnError ¶
func SetOnError(onErr func(error))
SetOnError sets the error forwarder for widget creation.
func SpinButtonWithRange ¶
func SpinButtonWithRange(min, max, step float64) *gtk.SpinButton
SpinButtonWithRange creates a *gtk.SpinButton.
func StackSwitcher ¶
func StackSwitcher() *gtk.StackSwitcher
StackSwitcher creates a *gtk.StackSwitcher.
func ToggleButtonWithLabel ¶
func ToggleButtonWithLabel(label string) *gtk.ToggleButton
ToggleButtonWithLabel creates a *gtk.ToggleButton.
func TreeViewColumnWithAttribute ¶
func TreeViewColumnWithAttribute(title string, renderer gtk.ICellRenderer, attribute string, column int) *gtk.TreeViewColumn
TreeViewColumnWithAttribute creates a *gtk.TreeViewColumn.
func TreeViewWithModel ¶
func TreeViewWithModel(model gtk.ITreeModel) *gtk.TreeView
TreeViewWithModel creates a *gtk.TreeView.
Types ¶
type AppInfo ¶
type AppInfo struct { // Window settings. ID string // Format: "org.gtk.example" Title string Width int Height int Flags glib.ApplicationFlags // See flags: https://godoc.org/github.com/gotk3/gotk3/glib#ApplicationFlags // Application callbacks (connected to signals). OnStart func(*gtk.Application) // sets up the application when it first starts OnActivateApp func(*gtk.Application) // shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment. OnActivateWin func(*gtk.ApplicationWindow) // for the first window, created on OnActivateApp OnStop func(*gtk.Application) // Pointers, filled between OnStart and OnActivateApp. App *gtk.Application // Set before OnActivateApp Win *gtk.ApplicationWindow // Set before OnActivateWin. Only set if OnActivateWin is defined. }
AppInfo defines application settings to run a GTK application.
When the object is created, start the application with:
func main() { os.Exit(appInfo.Run()) }
If OnActivateWin is set, a first window will be created, and forwarded to this callback.
Call order ¶
Callbacks are run in this order:
- OnStart
- OnActivateApp
- OnActivateWin .............. (application running)
- OnStop
See the package example.