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
}

Friday, November 05, 2021

October News...

 2021-10:
gnocl::text
o insertImage command enhanced to follow the insert command for text, ie..
$wid insertImage <pos> <imagename> -tags <taglist>
Where image can take a standard image %-markup prefix
gnocl::pango
o new subcmds, markup2options, options2markup
attempts to convert a pango markup string <span> tag to a list of text attibutes e.g., 
gnocl::pango markup2option "<span foreground='red' background='blue'>"  
returns 
{-foreground "red" -background "blue"}
gnocl::pango option2markup {-foreground "red" -background "blue"} 
returns
"<span foreground='red' background='blue'>"
created strings.h header file, keep decls for project string utilites
gnocl::text
o tag 
  new sub command - return character tag properties as pango markup
  new options -underlineColor, -strikethroughColor, not used by widget,
but passed as a pango attribute.
gnocl::canvas
o new command clear, remove all items from canvas.
o new text item options: -clip, -clipHeight, -clipWidth, 
  -fontRise, -fontSizePoints, -fontStrikethough, -markup, 
  -textHeight, -textWidth
gnocl::text
o tag ranges issues resolved.
gnocl::labelWidget
o issues with widget commands now resolved.
gnocl::button
o new option -onDestroy
gnocl::dialog
o removed redundant -modal option, dialog widgets are modal by default

First Attempt at Accessing GObject Private Data - FAILED

When the toolbar is placed in the vertical alignment widget texts are still centred. I thought that making these alignable might be more aesthically pleasing. I didn't complete the job, but I did glean a little bit more on just how to access widget private data. It all seems to pivot around the G_TYPE_INSTANCE_GET_PRIVATE macro.

#if 1
/* ATTEMPT TO LEFT ALIGN BUTTON TEXT */

struct _GtkToolButtonPrivate
{
  GtkWidget *button;
  gchar *stock_id;
  gchar *icon_name;
  gchar *label_text;
  GtkWidget *label_widget;
  GtkWidget *icon_widget;
  GtkSizeGroup *text_size_group;
  guint use_underline : 1;
  guint contents_invalid : 1;
};

typedef struct _GtkToolButtonPrivate GtkToolButtonPrivate;

struct _GtkToolButton
{
  GtkToolItem parent;
  /*< private >*/
  GtkToolButtonPrivate *GSEAL (priv);
};


#define GTK_TOOL_BUTTON_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TOOL_BUTTON, GtkToolButtonPrivate))

GtkToolButton      *button;
GtkToolButtonPrivate *priv;

priv = GTK_TOOL_BUTTON_GET_PRIVATE (para->item);

GtkWidget *label = priv->label_widget;

gtk_misc_set_alignment (label,0.0,0.5);

#endif 

json_shell_utils.tcl