Friday, September 17, 2021

Creating icons from UTF-8 Characters.

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


September updates

August saw a few modifications to the core, largely in the form of resolving some minor issues adding some utility functionality.

 

2021-08:
    gnocl::menu
        o bug in configure -tearoff now fixed.
    gnocl::notebook
        o new tab option -tooltip
    gnocl::text
        o fixed problems with -onButtonPress/Release signal handling.
          See gnoclConnectOptCmd.
    gnocl::pointer
        o new subcommand, monitor.
    gnocl::timeOut
        o now works properly.
          Use as an alternative to Tcl after which does not work within a Gtk.
    %c (child) substitution string added to -onKeyPress/Release callbacks
          for GtkBin objects (e.g., toplevel windows).
    gnocl::text
        o functionality of getPos subcommand now enhanced.
          $text-wid getPos <position> <offset>
              position, row column pair in list,
              offset, any relative keyword, e.g. wordStart, wordEnd
          Omitting a position and/or keyword option will result in
          returning a buffer position based upon the current mouse pointer position in the widget

Wednesday, August 04, 2021

gnocl::timeOut

I'm not certain what's going on, but running the Tcl after command within a Gnocl application results in the after command not working properly. No big problem. use the gnocl::timeOut command which offers the same basic functionality.

gnocl::timer milliseconds script

returns timerid

To stop a timer, run

gnocl::timer stop timerid

Here's a sample script:





# !/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

set i 0
set hb [gnocl::hBox]
set lab [gnocl::label -variable i -baseFont {Sans 24}]

set stop  [gnocl::button -text "STOP" -onClicked { 
%w configure -sensitive 0 ; $start configure -sensitive 1
gnocl::timeOut stop $timer } -sensitive 0]

set start [gnocl::button -text "START" -onClicked { 
%w configure -sensitive 0 ; $stop configure -sensitive 1
set timer [gnocl::timeOut 1000 { incr i } ]  }]

$hb add $lab -fill 1 -expand 1 
$hb add "$start $stop"

gnocl::window -title "Timed Counter" -child $hb -width 250

Monday, August 02, 2021

Working with tagging words.

The problem, how to tag a block of text in a textwidget when only a row-col (line-offset) pairing is know?

The Gnocl text widget has employed offsets for some time but this has always been in used in commands where the insertion point is used. Some recent changes to the getPos text subcommand will go some way in picking out words, lines etc., when using the "tag apply" instruction. 

Previously, getPos would only return a line-offset pair based upon the current mouse pointer position over the widget, this has now become the default. The enhancements allow two arguments to be passed, a line-offset pair and a keyword. So, if the line-offset refers to a point mid-way in a word, its now possible to hold of other relative positions using keywords.


  $text tag apply \

[$text getPos [list $a $b] wordStart] \

[$text getPos [list $a $b] wordEnd] \

-tags red

August News and Updates

Been very busy working on other projects during July, so only one improvement to report:


2021-07:

gnocl::notebook

o new tag option -baseFont, cget yet to be completed.

o new command clear, remove all pages

Thursday, July 01, 2021

Working with long text tag names.

Pango is really useful for creating markup strings although it does some caveats. It is markup for display purposes and not interactive editing. Some work has been done in bridging the gap between the display widgets and the text editor by creating preset markup tags which are meaningful names as tag whilst being valid pango strings. Pango also has some convenience tags although extending this list is not possible at all, nor its is directly possible through the Gtk api to directly convert pango attributes to tag properties or vice versa. 

To exchange formatted data between the text edit and display widgets needs a degree of creative programming on the part of the coder:

 

set txt [gnocl::text -useMarkup 0 -wrapMode word]
gnocl::window -child $txt -setSize 0.2 -onDelete {exit}
$txt tag create "<span rise='3000' font_size='small'>" -fontRise 3 -fontSize 8 -foreground red -editable 0
puts [$txt tag names]
$txt insert end AAAA -tags [$txt tag names]
$txt insert end \n
$txt insert end BBBB -tags "{<span rise='3000' font_size='small'>}"

July updates.

Added some useful functionality during June although some work still needs to be completed. The most annoying thing to be fixed was nagging issues over lineEnd and sentenceEnd, which was a simple logic matter. Of the most pleasing, reworking of dump. The aim being to provide the scripter with the ability to created serialized text files, Blog post to follow.

2021-06:

gnocl::text

o issues with lineEnd and sentenceEnd offset keywords now fixed. 

gnocl::labelEntry

o cget -value now works properly.

gnocl::tmpFile

o convenience command to create a temporary file name, with prefix.

gnocl::languages

o return information on languages supported and their naming conventions .

gnocl::text

o reworking dump command.

o new tag option -markup, assign pango markup equivalent (not validated).

o mark options -gravity and -visible can now be set on creation

json_shell_utils.tcl