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

Saturday, June 26, 2021

Toggling Text Visibility

 A simple way of toggling text is to assign a tag and manipulate its -invisible option, again using the event handling capability of a tag to control the setting. Notice that the snippet below, for each array two tags are created _${a} and _${a}_ where the former is the display header with the control, and the latter the tag to be elided. 
















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

package require Gnocl

set txt [gnocl::text -tabs 150 -editable 0]
gnocl::window -child $txt -onDelete { exit } -setSize 0.25

array set app [gnocl::application]
array set fruit [list apple 1 bannana 2 cherry 3]
array set cars [list morris a humber b austin c]

proc addLabel {wid str tag} {
     $wid addChild [gnocl::label -text $str]
     $wid tag apply lineStart lineEnd -tags $tag
     $wid insert end \n
}

proc tagClick {w n event} {
     if { $event == "buttonPress-1" } {
          $w tag configure ${n}_ -invisible [ gnocl::toggle [$w tag cget ${n}_ -invisible]]
     }
}


foreach a [list fruit cars app] {

     $txt tag create _$a -paragraph blue -onEvent { %w clearSelection ; tagClick %w %n %t-%b }
     $txt insert end $a\n -tags _$a
     
     foreach n [array names $a] {
          $txt tag create _${a}_ -indent 10 -data 1
          $txt insert end "${n}\t[set ${a}($n)]\n" -tags _${a}_
     }
}

Tuesday, June 22, 2021

Getting Widget Style Properties

Until the move over to Gtk4, Gnocl is still built against the Gtk 2.21 libraries. One of the inconveniences of Gtk is getting and setting widget style settings which are considered to be set globally by the desktop style settings and not for the programmer to tinker around with. Needless to say, there are times when different defaults are preferred, largely to draw the users attention to 'something a bit different'.

The function gtk_widget_modify_font  is a convenience function to set the widget basefont as shown in this snippet from the button.c module, 

if ( options[baseFontIdx].status == GNOCL_STATUS_CHANGED ) {
GtkWidget *label;
label = gnoclFindChild ( GTK_WIDGET ( para->button ), GTK_TYPE_LABEL );
PangoFontDescription *font_desc = pango_font_description_from_string ( Tcl_GetString ( options[baseFontIdx].val.obj ) );
gtk_widget_modify_font ( GTK_WIDGET ( label ), font_desc );
pango_font_description_free ( font_desc );
}

Unfortunately, there's no direct retrieval convenience function in the Gtk API and the documentation on the matter is scant but, again from the button.c module, retrieving style properties can be done directly:

if ( idx == baseFontIdx ) {
GNOCL_DEBUG_LINE

GtkWidget *widget;
GtkStyle *style;

widget = gnoclFindChild ( GTK_WIDGET ( para->button ), GTK_TYPE_LABEL );
obj = Tcl_NewStringObj ( pango_font_description_to_string ( gtk_rc_get_style ( GTK_WIDGET ( widget ) )->font_desc), -1 );
}


There is an alternative api function gtk_style_get, as illustrated in this clip from treeList.c

if ( idx == treeLineWidthIdx ) {
gint size;
GtkStyle *style = gtk_rc_get_style ( para->view );
gtk_style_get ( style, G_OBJECT_TYPE ( para->view ), "tree-line-width", &size );
obj = Tcl_NewIntObj ( size );
goto end;
}


This won't work with base font as there's no object property!

The gtkstyle.h include file from the Gtk source code gives the structure containing all the details.


struct _GtkStyle
{
  GObject parent_instance;
  /*< public >*/
  GdkColor fg[5];
  GdkColor bg[5];
  GdkColor light[5];
  GdkColor dark[5];
  GdkColor mid[5];
  GdkColor text[5];
  GdkColor base[5];
  GdkColor text_aa[5]; /* Halfway between text/base */
  GdkColor black;
  GdkColor white;
  PangoFontDescription *font_desc;
  gint xthickness;
  gint ythickness;
  GdkGC *fg_gc[5];
  GdkGC *bg_gc[5];
  GdkGC *light_gc[5];
  GdkGC *dark_gc[5];
  GdkGC *mid_gc[5];
  GdkGC *text_gc[5];
  GdkGC *base_gc[5];
  GdkGC *text_aa_gc[5];
  GdkGC *black_gc;
  GdkGC *white_gc;
  GdkPixmap *bg_pixmap[5];
  /*< private >*/
  gint attach_count;
  gint depth;
  GdkColormap *colormap;
  GdkFont *private_font;
  PangoFontDescription *private_font_desc; /* Font description for style->private_font or %NULL */
  /* the RcStyle from which this style was created */
  GtkRcStyle *rc_style;
  GSList *styles;   /* of type GtkStyle* */
  GArray *property_cache;
  GSList         *icon_factories; /* of type GtkIconFactory* */
};



json_shell_utils.tcl