Version 3 of Gnocl Q's and A's

Updated 2009-03-06 14:37:32 by WJG

I'm looking into rewriting some or all of my apps in gnocl, and finding that some features I'd like to see don't appear to be there yet. What I'm working on right now is WISH Checkbook. I've got the basic GUI assembled (see below); I still have to get it to work (notice the lack of any calculated totals), but I'm pretty sure that can be done. I'm still not seeing how to squeeze the toolbar into a smaller vertical space, but I can live with that if necessary.

http://www.geocities.com/pa_mcclamrock/gwishcheck.gif

What I would really like is to be able to use the gnocl::spinButton to do the "date-spinning" trick I can do with a Tk spinbox. (If you look really closely at the screenshot, you'll see that the date on the entry line is shown in a Tk spinbox, inserted into the Gnocl GUI by way of a socket.) Here's the code I use:

 # Procedure to get spinbox to display correct date:
 proc datespin {way w} {
        set datoa [$w get]
        set oldsecs [clock scan $datoa -format {%Y/%m/%d}]
        if {$way eq "up"} {
                set newsecs [clock add $oldsecs 1 day]
        } else {
                set newsecs [clock add $oldsecs "-1" day]
        }
        set datoa [clock format $newsecs -format {%Y/%m/%d}]
        $w delete 0 end
        $w insert 0 $datoa
 }

This causes the displayed date to be moved forward or back when the Up or Down spin-button is pressed, just as if it were an integer in an unmodified spinbox. It will work with a Tk spinbox, which allows you to delete and insert arbitrary text, but (so far as I can see) not with a Gnocl spinButton, which doesn't. Apparently the use of a socket slows down the GUI loading by some seconds, so I'd really like to do without it if possible. Is there a way to do the same thing with the existing Gnocl spinButton, or else a prospect of modifying the spinButton to accept deletion and insertion of arbitrary text?

WJG (06-Mar-09) gnocl::spinBox implements the GtkSpinBox widget which, for some reason, only supports ints and floats! Until I've made some equivalent for inclusion in the core, try this Tcl solution. Infact I think that listSpinner would be useful addition to the widget set. The script below to create the spinner will obviously need a little wrapping to suite your needs. I've modified the datespin proc' to be Gnocl compliant, and I've added two convenience command to the gnocl::entry code as a result of this quest, that is "get" and "set". The intended way of using the widget was to set the '-variable' associate with the widget, so you may want to explore this alternative. Happy Hacking!

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

 package require Gnocl

 # Procedure to get spinbox to display correct date:
 proc datespin {way w} {
        # set datoa [$w get]
        set datoa [$w cget -value]
        set oldsecs [clock scan $datoa -format {%Y/%m/%d}]
        if {$way eq "up"} {
                set newsecs [clock add $oldsecs 1 day]
        } else {
                set newsecs [clock add $oldsecs "-1" day]
        }
        set datoa [clock format $newsecs -format {%Y/%m/%d}]
        # $w set $datoa
        $w configure -value $datoa
  }

 # Create our own entry spinner as gnocl::spinBox only supports ints and floats
 proc dateSpinner { date variable } {
  set dateEntry [gnocl::entry -value $date]
  set upArrow [gnocl::arrowButton -arrow up -relief normal -data $dateEntry -onClicked {datespin "up" [%w cget -data ] }]
  set downArrow [gnocl::arrowButton -arrow down -relief half -data $dateEntry -onClicked {datespin "up" [%w cget -data ]  }]
  set dateSpinner [gnocl::box -borderWidth 0 -padding 0 -spacing 0]
  $dateSpinner add [list $dateEntry $upArrow $downArrow] -fill {0 0} -expand 0
  return $dateSpinner

}

 gnocl::window -child [dateSpinner "2009/03/06" ::date]
 gnocl::mainLoop

PS> when I tried out the code I entered the date using British formatting, ie, 03/06/2009 and it crashed the script. Perhaps some error checking would be useful