Beispiel #1
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.
	list, err := gtk.ListBoxNew()
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}
	gtkList = list
	// Add the label to the window.
	win.Add(gtkList)

	// Set the default window size.
	win.SetDefaultSize(640/2, 1136/2)

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

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	go getEntries()
	gtk.Main()
}
Beispiel #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()
}
Beispiel #3
0
// Setup the Window.
func setupWindow() *gtk.Window {
	w, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	w.Connect("destroy", gtk.MainQuit)
	w.SetDefaultSize(500, 300)
	w.SetPosition(gtk.WIN_POS_CENTER)
	w.SetTitle("TextView properties example")

	return w
}
Beispiel #4
0
// NewWindowMain creates a new toplevel window, set size and pack the main widget.
//
func NewWindowMain(widget gtk.IWidget, w, h int) *gtk.Window {
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		// log.Fatal("Unable to create window:", err)
		return nil
	}
	win.SetDefaultSize(w, h)
	win.Add(widget)
	win.ShowAll()
	return win
}
Beispiel #5
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()
}
Beispiel #6
0
func setup_window(title string) *gtk.Window {
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle(title)
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})
	win.SetDefaultSize(800, 600)
	win.SetPosition(gtk.WIN_POS_CENTER)
	return win
}
func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	win.Add(windowWidget())

	// Native GTK is not thread safe, and thus, gotk3's GTK bindings may not
	// be used from other goroutines.  Instead, glib.IdleAdd() must be used
	// to add a function to run in the GTK main loop when it is in an idle
	// state.
	//
	// Two examples of using glib.IdleAdd() are shown below.  The first runs
	// a user created function, LabelSetTextIdle, and passes it two
	// arguments for a label and the text to set it with.  The second calls
	// (*gtk.Label).SetText directly, passing in only the text as an
	// argument.
	//
	// If the function passed to glib.IdleAdd() returns one argument, and
	// that argument is a bool, this return value will be used in the same
	// manner as a native g_idle_add() call.  If this return value is false,
	// the function will be removed from executing in the GTK main loop's
	// idle state.  If the return value is true, the function will continue
	// to execute when the GTK main loop is in this state.
	go func() {
		for {
			time.Sleep(time.Second)
			s := fmt.Sprintf("Set a label %d time(s)!", nSets)
			_, err := glib.IdleAdd(LabelSetTextIdle, topLabel, s)
			if err != nil {
				log.Fatal("IdleAdd() failed:", err)
			}
			nSets++
			s = fmt.Sprintf("Set a label %d time(s)!", nSets)
			_, err = glib.IdleAdd(bottomLabel.SetText, s)
			if err != nil {
				log.Fatal("IdleAdd() failed:", err)
			}
			nSets++
		}
	}()

	win.ShowAll()
	gtk.Main()
}
Beispiel #8
0
func main() {
	gtk.Init(nil)

	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	win.Add(windowWidget())
	win.ShowAll()

	gtk.Main()
}
Beispiel #9
0
// NewWindow creates a new config window with its widget, ready to use.
//
func NewWindow(data datatype.Source, log cdtype.Logger) (*GuiConfigure, error) {
	win, e := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if e != nil {
		return nil, e
	}
	win.SetDefaultSize(WindowWidth, WindowHeight)
	win.SetTitle(WindowTitle)
	win.SetWMClass(WindowClass, WindowTitle)

	win.SetIconFromFile(data.AppIcon())

	widget := NewWidget(data, log)
	widget.SetWindow(win)

	win.Add(widget)
	win.ShowAll()

	return widget, nil
}
Beispiel #10
0
func NewMainWindow() *MainWindow {
	self := new(MainWindow)
	var err error
	self.Window, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)

	if err != nil {
		log.Fatal("Failed to load GTK")
	}

	self.Board = board.NewBoard()

	self.InitializeWidgets()
	self.Window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	self.Window.SetDefaultSize(640, 560)

	return self
}
Beispiel #11
0
func main() {
	gtk.Init(nil)
	win, e := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if e != nil {
		println(e.Error())
		return
	}

	path, isTest := vdata.TestPathDefault()
	var saveCall func(cftype.Builder)
	if isTest {
		saveCall = cfprint.Updated
	} else {
		saveCall = func(build cftype.Builder) { cfprint.Default(build, true) }
	}
	source := vdata.New(log.NewLog(log.Logs), win, saveCall)
	build := vdata.TestInit(source, path)
	source.SetGrouper(build)

	glib.IdleAdd(packWindow(win, source, build))
	gtk.Main()
}
func main() {
	gtk.Init(&os.Args)

	// Declarations
	Window, _ = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	RootBox, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6)
	TreeView, _ = gtk.TreeViewNew()
	Entry, _ = gtk.EntryNew()
	ListStore, _ = gtk.ListStoreNew(glib.TYPE_STRING)

	// Window properties
	Window.SetTitle("Products written in Go")
	Window.Connect("destroy", gtk.MainQuit)

	// TreeView properties
	{
		renderer, _ := gtk.CellRendererTextNew()
		column, _ := gtk.TreeViewColumnNewWithAttribute("Value", renderer, "text", 0)
		TreeView.AppendColumn(column)
	}
	TreeView.SetModel(ListStore)

	// TreeView selection properties
	sel, _ := TreeView.GetSelection()
	sel.SetMode(gtk.SELECTION_MULTIPLE)
	sel.Connect("changed", SelectionChanged)

	// Packing
	RootBox.PackStart(TreeView, true, true, 0)
	RootBox.PackStart(Entry, false, false, 0)
	Window.Add(RootBox)

	// Populating list
	// TODO: Add more values to the list
	AppendMultipleToList("Go", "Docker", "CockroachDB")

	Window.ShowAll()
	gtk.Main()
}
Beispiel #13
0
func main() {
	gtk.Init(nil)

	// gui boilerplate
	win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	da, _ := gtk.DrawingAreaNew()
	win.Add(da)
	win.SetTitle("Arrow keys")
	win.Connect("destroy", gtk.MainQuit)
	win.ShowAll()

	// Data
	unitSize := 20.0
	x := 0.0
	y := 0.0
	keyMap := map[uint]func(){
		KEY_LEFT:  func() { x-- },
		KEY_UP:    func() { y-- },
		KEY_RIGHT: func() { x++ },
		KEY_DOWN:  func() { y++ },
	}

	// Event handlers
	da.Connect("draw", func(da *gtk.DrawingArea, cr *cairo.Context) {
		cr.SetSourceRGB(0, 0, 0)
		cr.Rectangle(x*unitSize, y*unitSize, unitSize, unitSize)
		cr.Fill()
	})
	win.Connect("key-press-event", func(win *gtk.Window, ev *gdk.Event) {
		keyEvent := &gdk.EventKey{ev}
		if move, found := keyMap[keyEvent.KeyVal()]; found {
			move()
			win.QueueDraw()
		}
	})

	gtk.Main()
}
Beispiel #14
0
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()
}
Beispiel #15
0
// Window creates a *gtk.Window.
func Window(t gtk.WindowType) *gtk.Window {
	w, _ := gtk.WindowNew(t)
	return w
}
Beispiel #16
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()
}