godock: github.com/sqp/godock/widgets/gtk/newgtk Index | Examples | Files

package newgtk

import "github.com/sqp/godock/widgets/gtk/newgtk"

Package newgtk creates gtk objects.

Code:

///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())
}

Index

Examples

Package Files

application.go newgtk.go

func Adjustment Uses

func Adjustment(value, lower, upper, stepIncrement, pageIncrement, pageSize float64) *gtk.Adjustment

Adjustment creates a *gtk.Adjustment.

func Application Uses

func Application(appInfo *AppInfo) error

Application creates a *gtk.Application and connects its callbacks.

func Box Uses

func Box(orientation gtk.Orientation, spacing int) *gtk.Box

Box creates a *gtk.Box.

func Button Uses

func Button() *gtk.Button

Button creates a *gtk.Button.

func ButtonFromIconName Uses

func ButtonFromIconName(label string, size gtk.IconSize) *gtk.Button

ButtonFromIconName creates a *gtk.Button.

func ButtonWithLabel Uses

func ButtonWithLabel(label string) *gtk.Button

ButtonWithLabel creates a *gtk.Button.

func ButtonWithMnemonic Uses

func ButtonWithMnemonic(label string) *gtk.Button

ButtonWithMnemonic creates a *gtk.Button.

func CellRendererPixbuf Uses

func CellRendererPixbuf() *gtk.CellRendererPixbuf

CellRendererPixbuf creates a *gtk.CellRendererPixbuf.

func CellRendererText Uses

func CellRendererText() *gtk.CellRendererText

CellRendererText creates a *gtk.CellRendererText.

func CellRendererToggle Uses

func CellRendererToggle() *gtk.CellRendererToggle

CellRendererToggle creates a *gtk.CellRendererToggle.

func CheckButton Uses

func CheckButton() *gtk.CheckButton

CheckButton creates a *gtk.CheckButton.

func CheckMenuItemWithLabel Uses

func CheckMenuItemWithLabel(label string) *gtk.CheckMenuItem

CheckMenuItemWithLabel creates a *gtk.CheckMenuItem.

func ColorButtonWithRGBA Uses

func ColorButtonWithRGBA(gdkColor *gdk.RGBA) *gtk.ColorButton

ColorButtonWithRGBA creates a *gtk.ColorButton.

func ComboBox Uses

func ComboBox() *gtk.ComboBox

ComboBox creates a *gtk.ComboBox.

func ComboBoxText Uses

func ComboBoxText() *gtk.ComboBoxText

ComboBoxText creates a *gtk.ComboBoxText.

func ComboBoxWithEntry Uses

func ComboBoxWithEntry() *gtk.ComboBox

ComboBoxWithEntry creates a *gtk.ComboBox.

func ComboBoxWithModel Uses

func ComboBoxWithModel(model gtk.ITreeModel) *gtk.ComboBox

ComboBoxWithModel creates a *gtk.ComboBox.

func Dialog Uses

func Dialog() *gtk.Dialog

Dialog creates a *gtk.Dialog.

func Entry Uses

func Entry() *gtk.Entry

Entry creates a *gtk.Entry.

func Expander Uses

func Expander(label string) *gtk.Expander

Expander creates a *gtk.Expander.

func FileChooserDialogWith2Buttons Uses

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 FileFilter Uses

func FileFilter() *gtk.FileFilter

FileFilter creates a *gtk.FileFilter.

func FontButtonWithFont Uses

func FontButtonWithFont(fontname string) *gtk.FontButton

FontButtonWithFont creates a *gtk.FontButton.

func Frame Uses

func Frame(label string) *gtk.Frame

Frame creates a *gtk.Frame.

func Grid Uses

func Grid() *gtk.Grid

Grid creates a *gtk.Grid.

func Image Uses

func Image() *gtk.Image

Image creates a *gtk.Image.

func ImageFromFile Uses

func ImageFromFile(file string) *gtk.Image

ImageFromFile creates a *gtk.Image.

func ImageFromIconName Uses

func ImageFromIconName(iconName string, size gtk.IconSize) *gtk.Image

ImageFromIconName creates a *gtk.Image.

func Label Uses

func Label(label string) *gtk.Label

Label creates a *gtk.Label.

func LinkButtonWithLabel Uses

func LinkButtonWithLabel(uri, label string) *gtk.LinkButton

LinkButtonWithLabel creates a *gtk.LinkButton.

func ListBox Uses

func ListBox() *gtk.ListBox

ListBox creates a *gtk.ListBox.

func ListBoxRow Uses

func ListBoxRow() *gtk.ListBoxRow

ListBoxRow creates a *gtk.ListBoxRow.

func ListStore Uses

func ListStore(types ...glib.Type) *gtk.ListStore

ListStore creates a *gtk.ListStore.

func Menu() *gtk.Menu

Menu creates a *gtk.Menu.

func MenuItem() *gtk.MenuItem

MenuItem creates a *gtk.MenuItem.

func MenuItemWithLabel(label string) *gtk.MenuItem

MenuItemWithLabel creates a *gtk.MenuItem.

func Notebook Uses

func Notebook() *gtk.Notebook

Notebook creates a *gtk.Notebook.

func Paned Uses

func Paned(orientation gtk.Orientation) *gtk.Paned

Paned creates a *gtk.Paned.

func RadioMenuItemWithLabel Uses

func RadioMenuItemWithLabel(group *glib.SList, label string) *gtk.RadioMenuItem

RadioMenuItemWithLabel creates a *gtk.RadioMenuItem.

func Scale Uses

func Scale(orientation gtk.Orientation, adjustment *gtk.Adjustment) *gtk.Scale

Scale creates a *gtk.Scale.

func ScaleWithRange Uses

func ScaleWithRange(orientation gtk.Orientation, min, max, step float64) *gtk.Scale

ScaleWithRange creates a *gtk.Scale.

func ScrolledWindow Uses

func ScrolledWindow(hadjustment, vadjustment *gtk.Adjustment) *gtk.ScrolledWindow

ScrolledWindow creates a *gtk.ScrolledWindow.

func Separator Uses

func Separator(orientation gtk.Orientation) *gtk.Separator

Separator creates a *gtk.Separator.

func SeparatorMenuItem Uses

func SeparatorMenuItem() *gtk.SeparatorMenuItem

SeparatorMenuItem creates a *gtk.SeparatorMenuItem.

func SetOnError Uses

func SetOnError(onErr func(error))

SetOnError sets the error forwarder for widget creation.

func SpinButtonWithRange Uses

func SpinButtonWithRange(min, max, step float64) *gtk.SpinButton

SpinButtonWithRange creates a *gtk.SpinButton.

func Spinner Uses

func Spinner() *gtk.Spinner

Spinner creates a *gtk.Spinner.

func Stack Uses

func Stack() *gtk.Stack

Stack creates a *gtk.Stack.

func StackSwitcher Uses

func StackSwitcher() *gtk.StackSwitcher

StackSwitcher creates a *gtk.StackSwitcher.

func Switch Uses

func Switch() *gtk.Switch

Switch creates a *gtk.Switch.

func TextView Uses

func TextView() *gtk.TextView

TextView creates a *gtk.TextView.

func ToggleButton Uses

func ToggleButton() *gtk.ToggleButton

ToggleButton creates a *gtk.ToggleButton.

func ToggleButtonWithLabel Uses

func ToggleButtonWithLabel(label string) *gtk.ToggleButton

ToggleButtonWithLabel creates a *gtk.ToggleButton.

func TreeViewColumnWithAttribute Uses

func TreeViewColumnWithAttribute(title string, renderer gtk.ICellRenderer, attribute string, column int) *gtk.TreeViewColumn

TreeViewColumnWithAttribute creates a *gtk.TreeViewColumn.

func TreeViewWithModel Uses

func TreeViewWithModel(model gtk.ITreeModel) *gtk.TreeView

TreeViewWithModel creates a *gtk.TreeView.

func Window Uses

func Window(t gtk.WindowType) *gtk.Window

Window creates a *gtk.Window.

type AppInfo Uses

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.

func (*AppInfo) Run Uses

func (appInfo *AppInfo) Run() int

Run starts the application and creates the window if needed. Locks the thread until application release (windows closed?). Returns an error code.

Package newgtk imports 4 packages (graph) and is imported by 17 packages. Updated 2017-11-25. Refresh now. Tools for package owners.