GRIDPLUS - Example 3 | ![]() |
||||||
|
An Example Using Styles |
Window:
Source Code:
package require gridplus 1.0 namespace import gridplus::* #---------------# # Style Section # #---------------# option add *Entry.borderWidth 1 option add *Entry.relief solid option add *Gridplus.borderWidth 0 gridplus style title { -background black -labelcolor white/black -labelstyle 12,bold } gridplus style actions { -labelstyle bold -background lightskyblue } gridplus style sections { -labelcolor white -labelstyle bold -linkcolor white -background dodgerblue } gridplus style work_area { -background lightblue -buttoncolor /lightblue -buttonrelief flat } #----------------# # Example screen # #----------------# gridplus grid .title -style title { {"Add Customer"} {} } gridplus link .actions_customer -style actions { {"Actions"} {+ "Add Customer" .add} {+ "Edit Customer" .edit} {+ "Delete Customer" .delete} {} } gridplus link .sections -style sections { {"Sections"} {+ "Customer" .customer} {+ "Order" .order} {+ "Invoice" .invoice} {+ "Reports" .reports} {} {} } gridplus entry .data -style work_area -size 25 { {"First Name " .firstname +} {"Last Name" .lastname} {""} {"Building" .building} {"Street" .street} {"City" .city} {"State" .state} {"Zip" .zip 8} } gridplus line .line -borderwidth 2 gridplus button .add_customer -style work_area -size 60 { {.proceed :actitemadd16 "Proceed"} {.cancel :actcross16 "Cancel"} {.help :acthelp16 "Help"} } gridplus layout .work_area -style work_area { .data .line:ew .add_customer } gridplus layout .main -pad 0 -title "Demo Application" { .title:ew - .actions_customer:nsew .work_area:ns .sections:nsew ^ } pack .main
Comments:
package require gridplus 1.0 namespace import gridplus::*
option add *Entry.borderWidth 1 option add *Entry.relief solid option add *Gridplus.borderWidth 0 gridplus style title { -background black -labelcolor white/black -labelstyle 12,bold } gridplus style actions { -labelstyle bold -background lightskyblue } gridplus style sections { -labelcolor white -labelstyle bold -linkcolor white -background dodgerblue } gridplus style work_area { -background lightblue -buttoncolor /lightblue -buttonrelief flat }
This section is shown separately as this code need only be executed once (as a part of the application initialisation), regardless of how many screens/windows the application uses.
gridplus grid .title -style title { {"Add Customer"} {} }
gridplus link .actions_customer -style actions { {"Actions"} {+ "Add Customer" .add} {+ "Edit Customer" .edit} {+ "Delete Customer" .delete} {} }
gridplus link .sections -style sections { {"Sections"} {+ "Customer" .customer} {+ "Order" .order} {+ "Invoice" .invoice} {+ "Reports" .reports} {} {} }
gridplus entry .data -style work_area -size 25 { {"First Name " .firstname +} {"Last Name" .lastname} {""} {"Building" .building} {"Street" .street} {"City" .city} {"State" .state} {"Zip" .zip 8} }
Seven entry widgets are created: Generally for GRIDPLUS entry the first two items of each entry detail are the label text and the widget Identifier. The rest of the items are for options specific to the entry.
For Example: "{"First Name" .firstname +}".
"First Name" is the label text to be associated with an entry with Identifier ".firstname". The entry widget is actually created with the name ".data,firstname". The item begining with a dot (".") is considered to be the entry Identifier. In this case the leftmost item is the label and the next the Identifier. This causes the label to be to the left of the associated entry. If the items were reversed the label would be to the right of the entry. The "+" option gives this entry focus.
The number option "8" for widget ".zip", overrides the default size and sets this entry to have a size of 8 characters.
All of the entry widgets will have a "solid", "1" unit width outline as specified by the "option add" commands in the style section of the script.
The layout of the entry widgets in the window matches the layout of the entry details in the code. In this case they are one above the other (vertical) and will appear in the window accordingly as a single column.
gridplus line .line -borderwidth 2
gridplus button .add_customer -style work_area -size 60 { {.proceed :actitemadd16 "Proceed"} {.cancel :actcross16 "Cancel"} {.help :acthelp16 "Help"} }
Three button widgets are created: Each of the button widgets is a compound image/text button. To create a compound button it is only neccessary to specify an icon and a text string. In this case the command invoked by the button will be based on the name of the button Grid and the name of the icon.
For example: "{:actitemadd16 "Proceed"}".
In this case the invoked command will be: "add_customer,actitemadd16".
This example however also specifies explicitly the widget ID.
For example: "{.proceed :actitemadd16 "Proceed"}".
In this case the invoked command will be: "add_customer,proceed". The button will have the "actitemadd16" icon to the left (default) with the text "Proceed" to the right.
This method allows for more readable code, but has (just a little) extra typing.
The layout of the button widgets in the window matches the layout of the button details in the code. In this case they are one next to the other (horizontal) and will appear in the window accordingly as a single row.
gridplus layout .work_area -style work_area { .data .line:ew .add_customer }
gridplus layout .main -pad 0 -title "Demo Application" { .title:ew - .actions_customer:nsew .work_area:ns .sections:nsew ^ }
The ":ew" suffix on ".title:ew" causes the space between the widgets in the ".title" Grid to stretch in an east/west (horizontal) direction to full width of the window.
The layout of the Grids in the window matches the layout of the Grid details in the code.
pack .main
Setting and Reading GRIDPLUS Widget Values |
The values of the GRIDPLUS widgets are stored in a global array with a null name.
For Example:
global {}
For GRIDPLUS entry and checkbutton widgets the array element has the same name as the widget: Thus the value of ".first_name" in the ".data" Grid is referenced as "$(.data,first_name)".
The values of most GRIDPLUS widgets can be set simply by using the TCL "set" command.
For Example:
set (.data,first_name) Mary
However GRIDPLUS provides a gpset command. This can be used to set single or multiple widget values and is the supported method to set GRIDPLUS text and tablelist widget values.
For Example:
gpset .data,first_name Mary
...or...
gpset { .data,first_name Mary .data,last_name Smith }