Skip to content

Instantly share code, notes, and snippets.

@lf-araujo
Created August 21, 2018 17:34
Show Gist options
  • Save lf-araujo/dc9bd3887237b865dafd0cd0ea605970 to your computer and use it in GitHub Desktop.
Save lf-araujo/dc9bd3887237b865dafd0cd0ea605970 to your computer and use it in GitHub Desktop.
Gtk Containers with Notebooks and Buttons
*This is part of a series of posts about the Genie programming language. I am updating my progress in learning the language from scratch in the hopes it will be useful for anyone also trying to get to programming in the linux/Gtk world.*
Let's now move on to more complex Gtk designs. These are not necessarily useful, but serve as good example on how to code them. Here is an example of how to design the window by using grids. The next posting will be about containers using boxes.
```vala
[indent=4]
uses Gtk
class TestWindow : Window
notebook:Gtk.Notebook
init
// General characteristics of the window
title = "Gtk Containers"
default_height = 250
default_width = 250
window_position = WindowPosition.CENTER
destroy.connect(Gtk.main_quit)
// Now building the notebook
notebook = new Gtk.Notebook()
var label1 = new Gtk.Label("Page one")
var label2 = new Gtk.Label("Page two")
var label3 = new Gtk.Label("Page three")
var label4 = new Gtk.Label("Page four")
var child1 = new Button.with_label ("Go to next page")
child1.clicked.connect (childclicked1)
var child2 = new Button.with_label ("Go to next page")
child2.clicked.connect (childclicked2)
var child3 = new Button.with_label ("Go to next page")
child3.clicked.connect (childclicked3)
var child4 = new Button.with_label ("Go to first page")
child4.clicked.connect (childclicked4)
notebook.append_page(child1, label1)
notebook.append_page(child2, label2)
notebook.append_page(child3, label3)
notebook.append_page(child4, label4)
// Now building the grid
var grid = new Grid()
var button1 = new Gtk.Button.with_mnemonic("Button_1")
button1.clicked.connect(button1clicked)
var button2 = new Button.with_mnemonic("Button 2")
button2.clicked.connect(button2clicked)
// Attaching all elements into the grid
grid.attach(notebook, 0,0,2,1)
grid.attach(button1, 0,1,1,1)
grid.attach(button2, 1,1,1,1)
add(grid)
def childclicked1()
notebook.set_current_page(1)
def childclicked2()
notebook.set_current_page(2)
def childclicked3()
notebook.set_current_page(3)
def childclicked4()
notebook.set_current_page(0)
def button1clicked()
var page = notebook.get_current_page()
notebook.set_current_page(page - 1)
def button2clicked()
main_quit()
init
Gtk.init (ref args)
var test = new TestWindow ()
test.show_all ()
Gtk.main ()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment