Linux distros have heaps of pre-installed icons ready for use. I recently needed to create a toolbar menu which needed to access a set of unique icons which contained single characters. It was, in fact, a pull down menu for the insertion of 'special characters'. The Gtk+ api has complete functionality for creating icons from pixbufs and Gnocl providing convenient access.
Here's a screenshot and the script.
# !/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
package require Gnocl
if { [namespace exists jmls] == 0} {
namespace eval jmls {}
}
set ::app(specialCharacters) [list Section ¶ Paragraph § Separator • Left-Arrow ← Up-Arrow ↑ Right-Arrow → Down-Arrow ↓ Root √]
proc jmls::charIcon {name ch} {
set pb1 [gnocl::pixBuf new -width 40 -height 40]
$pb1 text \
-position [list 15 30] \
-font [list Sans normal 30] \
-text $ch \
-align centre \
-color white
gnocl::stockItem add \
-label $name \
-icon "%?$pb1"
$pb1 delete
}
proc jmls::tbarSpecialCharacterMenu {tbar {script ""} } {
if { $script == "" } {set script {puts $::app(spChar)} }
set menu [gnocl::menu]
set mb [$tbar add menuButton \
-icon %#New -text "Char" \
-menu $menu \
-tooltip "Insert special character into active text" \
-arrowTooltip "Select Character" \
-onClicked $script ]
foreach {a b} $::app(specialCharacters) {
jmls::charIcon $a $b
$menu add [gnocl::menuRadioItem \
-text "<big>$b</big>\t<small>($a)</small>" \
-onValue $b \
-variable ::app(spChar) \
-data [list $mb configure -icon %#$a ] \
-onToggled {eval %d}]
}
$mb configure -icon %#[lindex $::app(specialCharacters) 0]
}
set tbar [gnocl::toolBar ]
jmls::tbarSpecialCharacterMenu $tbar
set box [gnocl::box -orientation vertical -borderWidth 0 -spacing 0]
$box add $tbar
gnocl::window -child $box -setSize 0.2
gnocl::mainLoop
Comments