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 

Friday, October 29, 2021

Converting a Pango Markup Span Tag to a List of Text Widget Tag Options

Its always been a trouble task sharing formatted text between the gnocl::text widget and other display widgets such as the gnocl::label, gnocl::tree and gnocl::list widgets. This diffculty arises from not being able to define text attributes as pango markup, this is understandable given that fact that there is not a smooth overlap between the widget and pango attributes.

What was needed was a way of bridging the two requirments, being able to take a markup <span> tag and converting to an -opt val list.

Parsing markup strings using the pango api is not terribly helpful, it is complex and only works on complete strings, "<span .... ...>" would simply through up a pango formatting error.

The solution has been much simpler by using a series of string mapping operations in the source module with the resul being the creation of a new gnocl::pango subcommand "markup2options". For instance, if: 

set markup "<span font='Serif italic bold 24' foreground='green' background='red'>"

then calling

gnocl::pango markup2options $markup

returns

-font "Serif italic bold 24" -foreground "green" -background "red"

Using this a working script would produce something along the lines of:

$txt tag create test {*}[gnocl::pango markup2options $markup]
$txt insert end $sometext -tags test


Wednesday, October 20, 2021

String and Text Block Insertion Allowing for HTML/Pango String Markup

Tcl offers some really excelling string manipulation tools 'straight out of the box' although sometimes something extra might be needed. What if, for instance, the strings contain markup? Any markup is invisible on screen and so any string positioning needs to ignore the effects of that markup on the overall string length.

This can be achieved by using a simple flag to keep track of where characters in a string are containtained within a markup substring or not.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## insert str1 into str2 at position pos, allow for pango/html markup
# @param[in] str1	
# @param[in] str2
# @param[in] pos
# @param[in] opt
# @return modified string
proc string_insert { str1 str2 pos {opt ""} } {
	switch $opt {
		-markup {
			set flag 1
			set i 0
			set res ""
			foreach c [split $str2 ""] {
				append res $c
				if { $c == "<" } { set flag 0 }
				if { $c == ">" } { set flag 1 }
				if { $flag } { 
					if {$i == $pos } { append res $str1 } 
					incr i
					}  
			}
			return $res
			}
		default {
			return [string range $str2 0 $pos-1]$str1[string range $str2 $pos end]
		}
	}
}



## insert str1 into str2 at specified line and offset, allow for pango/html markup
# @param[in] str1
# @param[in] str2
# @param[in] line
# @param[in] offset
# @param[in] opt
# @return modified string
proc text_insert { str1 str2 line offset {opt ""} } {
	# extract specific line
	set strings [split $str2 \n]
	set ln [lindex $strings $line]
	# make insertion
	if { $opt == "-markup"} {
		set ln [string_insert $str1 $ln $offset $opt]
	} else {
		set ln [string range $ln 0 $offset-1]$str1[string range $ln $offset end]
	}
	# repack the text
	return [join [lreplace $strings $line $line $ln] \n]
}



asdasd

Recent Changes October, 2021

Most significant change during September was the inclusion of the -spellcheck option for the gnocl::text widget.


 2021-09:

gnocl::text

o new boolean option -spellcheck, cget also works, 

gnocl::spellcheck

o moved separate code back into the main module

gnocl::labelEntry

o added substitution strings %X %Y %W %H to -onIconPress/-onIconRelease callback scripts.

o cget -variable now works

gnocl::calendar

o added substitution strings %D %M %Y to -onDoubleDaySelect callback script.

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

json_shell_utils.tcl