GRIDPLUS2 - Notebook
Home Reference Manpage Examples Download License Contact

GRIDPLUS Notebook

In order to simplify creation of screen layouts, GRIDPLUS provides a GRIDPLUS notebook command mode. This is used to create a paged "Tabbed Notebook".

Invoking a Command When a Notebook Tab is Selected

The -command option can be used to specify the name of a command to be invoked when a notebook tab is selected.

Two parameters are passed to the specified command - The notebook tab ID and the tab text.

Note: The notebook tab IDs are indexed from zero.

Example:

If there is a notebook defined...

gridplus notebook .mynotebook -command myproc { 
   "Page 1" .mypage1 
   "Page 2" .mypage2 
   "Page 3" .mypage3
}
...and there is a procedure with a definition starting...
proc myproc {id text} {
...If the "Page 2" tab is selected the value of "id" will be "1" and the value of "text" will be "Page 2".

Examples

This section contains an example which illustrates the main GRIDPLUS notebook command mode features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout, Entry, Checkbutton and Radiobutton pages. Information given on those pages will not be duplicated here.

Note: The example assumes that the GRIDPLUS package has already been "required" and the commands imported.


Notebook Example 1

Window:

Pressing the "Page 2" button displays the following window:-

Note: In this example the size of the notebook changes to match the size of its contents. Example 2 demonstrates a method to fix the notebook size.

Source Code:

gridplus entry .mypage1 -attach nw -width 25 {
   {"Entry1" .e1}
   {"Entry2" .e2}
   {"Entry3" .e3}
}

gridplus checkbutton .mypage2 -attach nw {
   {"Option1" .cb1}
   {"Option2" .cb2}
   {"Option3" .cb3}
   {"Option4" .cb4}
}

gridplus radiobutton .mypage3 -attach nw {
   {"Option1" .rb1 -option1}
   {"Option2" .rb2 -option2}
   {"Option3" .rb3 -option3}
   {"Option4" .rb4 -option4}
}

gridplus notebook .mynotebook {
   "Page 1" .mypage1
   "Page 2" .mypage2
   "Page 3" .mypage3
}

gridplus layout .main -wtitle "Notebook Example" {
   .mynotebook
}

pack .main

Comments:

Three GRIDPLUS widget Grids are created: ".mypage1", ".mypage2" and ".mypage3". Each of these Grids is to be a Notebook page.

Note: Any GRIDPLUS Grid or Layout can be a Notebook page.

A GRIDPLUS Notebook is created named ".mynotebook". The -wtitle option sets the window title to "Notebook Example".

The Notebook layout has a line for each page. The first item in each line defines the text to appear on the button used to select the page. The second item defines the name of the GRIDPLUS Grid/Layout that will form the page.


Notebook Example 2

Window:

Pressing the "Page 2" button displays the following window:-

Source Code:

gridplus grid .mygrid1 -relief theme -anchor center {
   {"Label1"}
   {"Label2"}
   {"Label3"}
   {"Label4"}
   {"Label5"}
   {"Label6"}
}

gridplus grid .mygrid2 -relief theme -anchor nw {
   {"Label1"} {"Label2"} {"Label3"} {"Label4"} {"Label5"}
}

gridplus entry .mypage1 -attach nw {
   {"Entry1" .e1}
   {"Entry2" .e2}
   {"Entry3" .e3}
}

gridplus checkbutton .mypage2 -attach nw {
   {"Option1" .cb1}
   {"Option2" .cb2}
   {"Option3" .cb3}
   {"Option4" .cb4}
}

gridplus radiobutton .mypage3 -attach nw {
   {"Option1" .rb1 -option1}
   {"Option2" .rb2 -option2}
   {"Option3" .rb3 -option3}
   {"Option4" .rb4 -option4}
}

gridplus notebook .mynotebook {
   "Page 1" .mypage1
   "Page 2" .mypage2
   "Page 3" .mypage3
}

gridplus layout .main -wtitle "Notebook Example" {
   .mygrid1:ew .mynotebook:nsew
   .mygrid2    -
}

pack .main

Comments:

The Notebook part of this example is the same as Example 1; However, The GRIDPLUS Entry grid has a null item at the "bottom" of the grid. This will allow the grid to stretch without anchoring "Entry3" to the bottom of the grid.

The GRIDPLUS Layout named ".main" stretches the Notebook to fill its cell (".mynotebook:nsew"), the size of which (in this example) is controlled by the GRIDPLUS Grids ".mygrid1" and ".mygrid2".


Copyright © 2014 Adrian Davis.