newgtk

package
v0.0.0-...-0caaa62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 4 Imported by: 0

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

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

func Application(appInfo *AppInfo) error

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

func Box

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

Box creates a *gtk.Box.

func Button

func Button() *gtk.Button

Button creates a *gtk.Button.

func ButtonFromIconName

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

ButtonFromIconName creates a *gtk.Button.

func ButtonWithLabel

func ButtonWithLabel(label string) *gtk.Button

ButtonWithLabel creates a *gtk.Button.

func ButtonWithMnemonic

func ButtonWithMnemonic(label string) *gtk.Button

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 CheckButton

func CheckButton() *gtk.CheckButton

CheckButton creates a *gtk.CheckButton.

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 ComboBox

func ComboBox() *gtk.ComboBox

ComboBox creates a *gtk.ComboBox.

func ComboBoxText

func ComboBoxText() *gtk.ComboBoxText

ComboBoxText creates a *gtk.ComboBoxText.

func ComboBoxWithEntry

func ComboBoxWithEntry() *gtk.ComboBox

ComboBoxWithEntry creates a *gtk.ComboBox.

func ComboBoxWithModel

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

ComboBoxWithModel creates a *gtk.ComboBox.

func Dialog

func Dialog() *gtk.Dialog

Dialog creates a *gtk.Dialog.

func Entry

func Entry() *gtk.Entry

Entry creates a *gtk.Entry.

func Expander

func Expander(label string) *gtk.Expander

Expander creates a *gtk.Expander.

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 FileFilter

func FileFilter() *gtk.FileFilter

FileFilter creates a *gtk.FileFilter.

func FontButtonWithFont

func FontButtonWithFont(fontname string) *gtk.FontButton

FontButtonWithFont creates a *gtk.FontButton.

func Frame

func Frame(label string) *gtk.Frame

Frame creates a *gtk.Frame.

func Grid

func Grid() *gtk.Grid

Grid creates a *gtk.Grid.

func Image

func Image() *gtk.Image

Image creates a *gtk.Image.

func ImageFromFile

func ImageFromFile(file string) *gtk.Image

ImageFromFile creates a *gtk.Image.

func ImageFromIconName

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

ImageFromIconName creates a *gtk.Image.

func Label

func Label(label string) *gtk.Label

Label creates a *gtk.Label.

func LinkButtonWithLabel

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

LinkButtonWithLabel creates a *gtk.LinkButton.

func ListBox

func ListBox() *gtk.ListBox

ListBox creates a *gtk.ListBox.

func ListBoxRow

func ListBoxRow() *gtk.ListBoxRow

ListBoxRow creates a *gtk.ListBoxRow.

func ListStore

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

func Notebook() *gtk.Notebook

Notebook creates a *gtk.Notebook.

func Paned

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

Paned creates a *gtk.Paned.

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 Spinner

func Spinner() *gtk.Spinner

Spinner creates a *gtk.Spinner.

func Stack

func Stack() *gtk.Stack

Stack creates a *gtk.Stack.

func StackSwitcher

func StackSwitcher() *gtk.StackSwitcher

StackSwitcher creates a *gtk.StackSwitcher.

func Switch

func Switch() *gtk.Switch

Switch creates a *gtk.Switch.

func TextView

func TextView() *gtk.TextView

TextView creates a *gtk.TextView.

func ToggleButton

func ToggleButton() *gtk.ToggleButton

ToggleButton creates a *gtk.ToggleButton.

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.

func Window

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

Window creates a *gtk.Window.

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.

func (*AppInfo) Run

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL