Skip to main content

Posts

Showing posts from June, 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}_

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 d

Creating temporary files

The C stdio package has two function calls related to the creation of temporary files: tmpFile and tmpnam. The Glib too has similar functions in its api such as g_mkstemp, g_file_open_tmp and so on. For someone programming in C, both of these approaches are excellent resources but someones scripting in Tcl more suitable approaches can be taken these C procedures will require a significant amount code to produce an effective binding which, may not offer worthwhile advantages. The inclusion of a new command gnocl::tmpFile into to the core offers a convenient way of producing unique filenames. The command takes a single argument, an optional prefix, and returns a unique name with a randomized suffix. If a prefix is specified: puts [gnocl::tmpFile aaa] /tmp/aaa.SYzqiJQA8Eeg4GZC1eDb puts [gnocl::tmpFile bbb] /tmp/bbb.VIT88L2zjeynnHn5dVfH puts [gnocl::tmpFile ccc] /tmp/ccc.3IkQqXjYtwDowshdjjCc Without a prefix, the defaul 'TclScript' will be used. puts [gnocl::tmpFile] /tmp/TclScript

May 2021 News!

 Just a handful on modifications this month.   2021-05:     gnocl::winfo parent $wid         o no longer crashed when parent == null.     gnocl::menu         o -data and cget -children now work correctly.     gnocl::text         o fixed minor internal issues relating to getPos, lineStart/lineEnd keyword usage.     gnocl::notebook         o intermittant crash using the remove/removePage subcommand fixed.         o began implementation of embedded tab widgets     gnocl::eventBox         o fixed problems with -child command.             (For some strange reason, the gnoclOptChild call would not work             for eventBoxes after it had been modified to remove previous             the child. The same functionality is not handled by the local             configure/cget functions and it works fine.)     gnocl::list/tree         o new command: autosize.     gnocl::window         o new option  -hideOnDelete, hides window when deleted,           useful for preventing toolpalette window from