Documentation‎ > ‎Concepts‎ > ‎

Percent String

Some widget options expect a percent string as value when two or more possible choices are possible.

A percent string is a string which starts with a percent sign "%" with the second character determining the type of information that follows. The following types are defined:

Types of Percent String

!
Simple string which is not further parsed.
%
Simple string which starts with a percent string and which is not further parsed.
_ (underline)
The next underline is removed and the following character is underlined and used as keyboard accelerator.
#
The following string is used as name of a stock item. Dependent on the widget the name, accelerator and/or image of the stock item is used.
Not every stock item is valid in every context. The following example shows all items which are valid as text option of the button widget.
set table [gnocl::table /
    -borderWidth 0 /
    -rowSpacing 0 /
    -columnSpacing 0]


set items ""

set stocks [lsort [gnocl::info allStockItems]]


foreach el $stocks {

if { [catch {set but [gnocl::button -text "%#$el"]} ] == 0 } {
lappend items [gnocl::box -label "$el" -children $but -fill 1 -expand 1]
if { [llength $items] == 6 } {
$table addRow $items -fill 1
set items ""
}
}
}

if { [llength $items] > 0 } {

$table addRow $items -fill 1
}

gnocl::window -title "Stock Buttons" -child $table

<
The following string is parsed as markup string. Additional the next underline is removed and the following character is underlined and used as keyboard accelerator.
/
The following string is interpreted as file name.
?
The following string is regarded as the name of an existing gnocl::pixBuf graphic.

Example:

set box [gnocl::box -orientation vertical]

$box add [gnocl::button -text "Simple String"]

$box add [gnocl::button -text "%!Another Simple String"]


$box add [gnocl::button -text "%%Simple String which starts with %"]


$box add [gnocl::button -text "%_Underlined _String"]


$box add [gnocl::button -text "%#Quit"]


$box add [gnocl::button -text "%<n_ormal <b>bold</b> <big>big</big>"]


$box add [gnocl::button -icon "%/./three.png" -text "%__Three"]


gnocl::window -title "Percent String Example" -child $box



Comments