Saturday, June 04, 2022

Retrieving Invisible Text

 One of the many options of the text widget tag is the boolean -invisible property. When used, it must be born in mind that it doesn't merely affect the on-screen visibility of the contents of the text buffer to which the tag set with this option applies, but to the retrieval of the text too. The text widget get comment, returns the visible contents of the text view, if the actual contents of the displayed text buffer are needed, then the dump command should be used. 

So, to return the visible contents of the text view use:

$wid get

But to return the entire text content of the text buffer, use:

$wid dump text start end



Wednesday, June 01, 2022

Tabulate

 Simple way of inserting beautified tables into the gnocl::text widget.



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

package require Gnocl

## insert the list contents as in text widget as a formatted table
#
# @param    wid        text widget-id
# @param    lst        tcl list
# @param    id        table id
# @param    args    additional tag parameters
#
proc tabulate {wid lst {id 1} args} {

    if {$args == ""} { set args "-tabs 100" }

    foreach row $lst { append res [join $row \t]\n }

    $wid tag create _tab_table_$id {*}$args
    $wid insert end $res -tags _tab_table_$id

}

set txt [gnocl::text]
gnocl::window -child $txt -setSize 0.4

set lst(1) {{red orange yellow green blue indigo violet} {magenta cyan yellow brown grey black white}}
set lst(2) {{how now brown cow} {she sells sea shells by the sea shore}}
set lst(3) {{peter piper picked a peck of pickled peppers} {the peck of peppers peter piper picked}}

tabulate $txt $lst(1) 1 -tabs 120 -paragraph red -font {12}
tabulate $txt $lst(2) 2 -tabs 80 -foreground magenta
tabulate $txt $lst(3) 3 -tabs 80 -foreground white -paragraph #000000 -font {10}



Thursday, March 03, 2022

Home directory for a script...

If an application has a series of Tcl script packages loaded with the source command, then any subsequent calls made by those scripts will potentially loose track of the path to find associated data files. This may not be a problem if the application will always use absolute addressing, ie. be run from its home directory, but if the application is located in the execution path, downstream proceedure calls and scripts may not know where to find obtain resources.

The way around this is to keep a note of the path where the main application script is located as soon as the script begins.


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

set ::app(HOME) [file dirname [file normalize [info script]]]

set ::app(demo) 0
set ::app(ibus,defaultIM) [exec ibus engine]

source $::app(HOME)/editor_widget.tcl
source $::app(HOME)/dictionary/dictionary.tcl
source $::app(HOME)/translationEngine/translationEngine.tcl
source $::app(HOME)/translationEngine/teGUI.tcl
source $::app(HOME)/hanyuTools/hanyuTools.tcl
source $::app(HOME)/charIcons.tcl
...
...
...

Monday, February 28, 2022

Switching between IBUS input methods....

Its great having the input method controller embedded into the Gnome taskbar so that input methods can be changed when moving between input windows using a keyboard command sequence. It would be useful too, if its was possible to keep tabs on what language is supposed to be used in a text widget and have the Tcl script switch input methods automatically. Here's how to do it...




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

package require Gnocl

set chn [gnocl::text]
set skt [gnocl::text]
set vb [gnocl::vBox]

$vb add $chn -fill 1 -expand 1
$vb add $skt -fill 1 -expand 1

gnocl::window -child $vb -setSize 0.4

$chn configure \
-onFocusIn  { eval exec "ibus engine pinyin"} \
-onFocusOut { eval exec "ibus engine xkb:gb:extd:eng" }

$skt configure \
-onFocusIn  { eval exec "ibus engine m17n:sa:IAST" } \
-onFocusOut { eval exec "ibus engine xkb:gb:extd:eng" }



Friday, February 25, 2022

Using Tcl to trace changes to array variables

 
The Tcl trace command can be used to respond to changes to variables occur, these changes are array, read, write and unset. 


When one of these events occurs, a sub-script is execute and a number of values passed to it. In the case of an array operation, these are the array name, the member, and the operation.

Following this it is then possible, with a bit of string splicing, to obtain the value of the value of the changed array member.

Example:


proc AAA {args} {
    lassign $args a b c
    puts [set ${a}($b)]    
    }


trace add variable ::conze::editor::block write AAA
set ::conze::editor::block(::gnocl::_WID26_,start) 5


Thursday, February 24, 2022

Slow startup of Gnocl based applications in Ubuntu 20.4

 The recent changes to the Ubuntu 20.4 deployment sometimes sees slow startup times of between 25-60secs. Thankfully someone has solved the problem. I've downloaded the module and it works for me.


https://itsfoss.community/t/solved-apps-opening-too-slow-in-ubuntu-20-04/4578/2

With help from a teammate in investigating the common problem with our apps, he discovered a cure by installing the deprecated gtk2 library module. Available in the 20.04 distro.

All you need to do is to run this command:

sudo apt install appmenu-gtk2-module

and then rebooting. You need to reboot to get the new library working.

This allows older applications based on the older menu API to function normally. Solved the issue with Boinc Manager and GKrellm config menu.

Ref: https://launchpad.net/ubuntu/bionic/+package/appmenu-gtk2-module 478

Saturday, February 05, 2022

Creating Empty Lists

Just what it 'says on the tin', create a list of empty strings.

 

proc emptyList {n} {
    for {set i 0} {$i < $n} {incr i} { lappend res {} }
    return $res
}

json_shell_utils.tcl