Skip to main content

Posts

Showing posts from 2024

Significant Re-write of how Gnocl Handle Commands

offset idx to accommodate point at which options occur  idx = objc no options gnocl::device  idx = 1 no subcommand but with options gnocl::device -option AAA -option AAA...  idx = 2 subcommand with options gnocl::device cmdName -option AAA -option AAA...  idx = 3 gnocl::device cmdName string -option AAA -option AAA...    gnoclParseCommandOptions   /** \brief    Command Template. **/ int gnoclTemplateCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) {     static const char *description = "description";     static GnoclCommand commands[] = {         { "cmdName", "args", "description", "default" },         { NULL }     };     static GnoclOption options[] = {         /* command/widget specfic options */     ...

Remove Stray Repeated Spaces from a String

      #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" package require -exact Gnocl 3.24 set str "\tAbc  def  ghi   klm    a. \tYes!   " ## reduce multiple spaces within a string but retain \t, trim all external spaces. # args: str        string to modify # returns:        updated string # proc removeSpaces { str } {     while 1 {         if { [string first "  " $str] == -1 } { break }         set str [string map [list "  " " "] $str]     }     return [string trim $str " "] } puts >[removeSpaces $str]<

Search for Named Icons

      # # return a sorted list of available icons with a name matching search pattern # proc findIcon {pattern} {          # load list of available icons     set contexts [gnocl::icon contexts]     foreach context $contexts {         lappend ICONS $context [lsort [gnocl::icon icons -context $context]]     }              foreach {k v} $ICONS {         foreach i  [lsearch -all -glob $v $pattern ] {             lappend res [lindex $v $i]             }       }     return [lsort $res] }

Simple Tcl/Gnocl based widget message bar.

The gtk api provides it own status bar widget which could be used for embedded widget feedback but this it aimed at being used as part of a application's toplevel window. A complex UI may have several component zone each of which giving its own feedback. This simpler messaging areas provided this capability by making feedback available by directly displaying the contents of global variables rather than pushing items onto a status message stack. if 0 { +-------------------------------------------------------------------------+ | msg0                                      |  msg1   |  msg2   |  msg3   |    +-------------------------------------------------------------------------+ } ## # Simple Tcl/Gnocl based message bar # ref = unique ref  (could...

Using GnoclOption functions to Return Values for Customised Widget Options.

What to do... Make changes to the widgetFunc function to enable the GnoclOption function for that option to return a value by setting the ret to point ot a TclObj. /* this is a gnocl option handler ?? */ case GNOCL_CGET_NOTHANDLED: { /* cget for gnocl options handled in option function * the caveat here is that different widgets with the same option name may act differently, * if this is the case, then would it be more practical to create specific option functions? * (08/09/25) */ Tcl_Obj *ret = NULL; options[idx2].func ( interp, &options[idx2], G_OBJECT ( area ), &ret ); Tcl_SetObjResult (interp, ret); }

Dynamic Allocation of an Array of Strings in C.

   https://www.geeksforgeeks.org/how-to-create-a-dynamic-array-of-strings-in-c/ In C, dynamic arrays are essential for handling data structures whose size changes dynamically during the program’s runtime. Strings are arrays of characters terminated by the null character ‘\0’. A dynamic array of strings will ensure to change it’s size dynamically during the runtime of the program as per the user’s needs. In this article, we will learn how to create a dynamic array of strings in C. Create a Dynamic Array of Strings in C To create a dynamic array of strings in C, we can use the concept of double pointer and dynamic memory allocation. The double pointer is the pointer that stores the memory address of another pointer. We create an array of pointers to characters (i.e. strings) and then store the address of this array in the double-pointer to characters. Each of the pointer to the character is again allocated memory based on the size of the string it is storing. Ap...

Overhaul of widget cget functionality.

The current basis of the cget function for widgets is based upon code written over 20yrs ago and, whilst it works reasonably well for the simple setting of gtk widget properties, support for more complex custom options is hit and miss.   typedef struct GnoclOption_ {     const char *optName;       enum GnoclOptionType type;     const char *propName;     gnoclOptFunc *func;     const char *args;     const char *description;     const char *values;      enum GnoclOptionStatus status;     union {         gboolean b;         gint     i;         gdouble  d;           gchar    *str;           Tcl_Obj  *obj;           } val; } GnoclOption;   With the recent upda...

Obtaining the index of value from an array of strings or an array of structures.

     static char *options[] = {         "-opt1", "-opt2", "-opt3",NULL     }; static enum  optsIdx {     opt1Idx, opt2Idx, opt3Idx     };  gint idx; /* obtain idx from an array of strings */ Tcl_GetIndexFromObj ( interp, objv[1], options, "option", TCL_EXACT, &idx ); /* obtain idx from array of structures, not an array of strings */ Tcl_GetIndexFromObjStruct ( interp, objv[1], ( char ** ) &commands[0].cmdName, sizeof ( GnoclCommand ), "command", TCL_EXACT, &idx );

Remove named items from a list

Sometimes you just want to trim down a list of items but you're not quite certain where the items are so its not possible to use lreplace or lremove directly as these require indices. In order to obtain these lsearch can be used.  The following code example shows how wrap these operations into a single procedure call where mylist is the list to alter, and args a list of items to remove. The procedure returns a new list rather than modifying the original directly.   proc remove {mylist args} {          foreach value $args {         set idx [lsearch -exact $mylist $value]         set mylist [lreplace $mylist $idx $idx]     }          return $mylist }