Thursday, April 29, 2021

Why didn't I do this before?

Sometimes its so much more convenient (and efficient) to implement something in C rather than Tcl: positioning a popup menu on screen is one of those situations. To this end a new option, -widget, has been added to the menu popup subcommand. 

This causes the callback handler to determine screen coordinates from the on-screen location and height of the widget specified by the -widget option.

Compare:

$abut configure -onClicked "$menu popup -widget %w"

With:

$abut configure -data $menu -onClicked {
        lassign [gnocl::winfo geometry %w] x y w h
        %d popup [expr $x-4] [expr $y+$h] }

This latter approach not only requires memory allocation using -data but 'pollutes' the global namespace with the extra variables 'x y w h' which might result in some form of conflict. 

For those who notice, there is '+4' which is an attempt to handle the buttons style border-width setting. This isn't handled in the callback script, but accommodated in the module core.





Thursday, April 22, 2021

Namespace export-import, aliases and rename

 
    Namespaces are really useful in Tcl as they permit commands and variables to be conveniently grouped together. This means that common command names can be reused within specific contexts, and that variables can be 'hidden' away from errant command calls. All this extra security does come at a cost, a lost of unecessary and respetative typing. Using the gnocl:: namespace prefix is useful if, lets say, there is a need for mixed Tcl and Gnocl programming. But, if there isn't this need what can be done to alleviate the typing burden, albeit with some risks when coming to readability and portability between applications? Variables and commands embedded within a namespace can undergo export-import process or they can be renamed.

The following code example shows how this can be done. When exporting and importing between namespaces its possible to have a naming conflict in the importing namespace. Tcl will pick this up and result in an error. Fortunately this only applies to a handful of instances and in most cases (e.g. list and listStore) command synonyms are built into the gnocl core.

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

package require Gnocl

# what namespaces are present?
puts [namespace children ]

# export all gnocl command and widge names
namespace eval ::gnocl {
    namespace export application listStore button menu window
    foreach class [widgets] { namespace export $class }
    foreach class [commands] { namespace export $class}
}

foreach class [gnocl::widgets] {
    if { [catch { namespace import gnocl::$class } err] }  { puts WIDET-$err }
}

foreach class [gnocl::commands] {
    if { [catch { namespace import gnocl::$class } err] }  { puts COMMAND-$err}   
}

set x 200 ; set dx 400
set opts "-y 400 -width 300 -height 200"

# EXAMPLE 1) create app from and array
array set app [application]

$app(topLevel) show


set lst [listStore -columns 2 -types {string string}]
$lst add [list [list a b] [list b c] ]
$app(container) add $lst -fill 1 -expand 1
$app(topLevel) configure -x [incr x $dx] {*}$opts

# EXAMPLE 2) using aliass
interp alias {} g_window {} gnocl::window
g_window -child [gnocl::text] -x [incr x $dx] {*}$opts

# EXAMPLE 3) renaming commands
foreach class [gnocl::widgets] {
    rename gnocl::$class gcl::$class
}

gcl::window -child [gcl::button -text hello]  -x [incr x $dx] {*}$opts




Wednesday, April 21, 2021

gnocl::unicode -a new command

Determining the language of the user's system and script of a text string

 

 

puts $env(LANG)
puts $env(LANGUAGE)

puts [gnocl::unicode script "我是英国人。"]
puts [gnocl::unicode script "ཀརྨ"]
puts [gnocl::unicode script "aṣṭa"]
puts [gnocl::unicode script "ꛅꛇꛈ"]
 

puts [gnocl::unicode options]
puts [gnocl::unicode commands]

Monday, April 12, 2021

March 2021 Updates and News


 

 

Fashionably late? Maybe not. Here's a listing of the recent enhancements to the gnocl core modules.

2021-03:
    gnocl::fileChooserButton
        o -fileFilters option now works correctly
    gnoclKeyboardCmd, retrieve keyboard state.
        o Returns list of boolean for: NumLock CapsLock ScrollLock
          For Overwrite Mode of text and entry widgets, obtain setting from wiget directly
          using %w cget -overwrite.
    gnocl::window, gnocl::frame, gnocl::expander, gnocl::handleBox, gnocl::scrolledWindow
        o -onDelete %c string option added to handle GTK_BIN objects, return sole child widget.
    gnocl::dialog
        o new option -noButtons, creates a buttonless dialog, with
          response handled through dialog closure
 

Most of March saw me working on the complete rewrite of my translator's workbench, code named 'JMLS'. I've worked on various 'manifestations' of this platform since 1998 but, such a complete and thorough rewrite, I'm seriously reconsidering renaming as 'Tyndale' after arguably the greatest translator in the English language who lived during the 16th Century.

Next month will see a near complete binding of the gtk vte widget along with its introspective help. The absolute dearth of meaningful public documentation on the virtual terminal is frustrating as its difficult to determine how the large range of options and signals work together to form a meaningful whole. Still, time will tell.

Now to bring the gnocl::canvas widget up to date!


Saturday, March 20, 2021

Getting Keyboard Lock and Overwrite Settings

 


 

 

 

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

if { [catch { package present Gnocl } ] } { package require Gnocl }

set win [gnocl::window -child [gnocl::text -name txt] -setSize 0.25]

exec xmodmap -e "add mod3 = Scroll_Lock"

txt configure -onKeyRelease {

    lassign [gnocl::keyboard %w] NumLock CapsLock ScrollLock
    set Overwrite [%w cget -overwrite]
    
    foreach item {NumLock CapsLock ScrollLock Overwrite} {
        puts "$item   [set $item]"
    }
    
}

Saturday, March 06, 2021

March Updates


 

Just a few tweaks this month.

2021-02:
   gnocl::stringUtils
        o new subcommands,
            totitle, convert string to title string by capitalizing all word initial characters
            toroman, convert Arabic integer to Roman numerals
    gnocl::notebook
        o tearoff tab window will now contain the same text as the child tab
        o new command -tabCget
    gnocl::dialog
        o dialog now registered to obtain a widget-id, not directly
          returned but easily obtained by child widgets using the
          [gnocl::winfo toplevel %w] command.
    gnocl::tree/list
        o -onSelectionChanged now supports %d substitution string.
        o -onWidthChanged, callback handler rewritten to automatically
          update column wrapwdith when resized.

Sunday, February 14, 2021

February 2021 Update


 

A tad late in posting this month's news but here's what happened during January.

 

 2021-01:
    gnocl::window
        o issues with snapshot subcommand fixed.
          added snapshot options: -delay, -pointer, -color, -radius, and -alpha.
    gnocl::pixBuf
        o new creation option offScreen.
    gnocl::offScreen
        o new widget type.
    gnocl::notebook
        o fixed problems with -onCreateWindow and -detachable options.
        o popupmenu labels now accept markup.
        o tabConfigure -label, -detchable, -menuText, -menulabel, -position options now work
        o tabConfigure -fill, -expand, -pack do workd, but may give unexpected results.        
    gnocl::dialog
        o -content option retired, use -child if used.
        o new option -actionWidget (add widgets to action area widgets), typically buttons.
        o -onResponse new substitution string, %c. Return child widget-id.        
    gnocl::text
        o swap substrings, now stored in widget params struct rather than data assignment.
        o new option -corrections, substitute whole words.
    gnocl::canvas
        o integrated separate module code into main module. Comparable with Tk.
    gnocl::vte
    gnocl::vfs
    gnocl::file
    gnocl::mime

json_shell_utils.tcl