Skip to main content

Dialog bindings completely re-written.

The legacy code to create a gnocl::dialog has always been problematic. The way the code was originally devised was to build up a set of control buttons using what Gtk libs describe as "activation widgets", that is: custom made widgets added to the bottom row of buttons. Apart from this approach going against the Gnome user interface guidelines, it always results in an application crash. Looking at other dialogs in the library indicates why. The idea is that the dialog 'runs' within its own loop which is only exited when a response button is activated. The dialog either gathers or gives information and then returns to the calling script a response decision obtained the user. Using activation widgets that call the -onResponse signal break this process. If programmers have used the activation widgets for something more complex then those widgets ought to be packed as children into the main body of the dialog.
I've now resolved this problem by completely re-writing the gnocl dialog bindings with the planned redundancy of the existing dialog code on the next incremental release.

The much simplified code has the following options:

-backgroundColor,
-backgroundImage
-buttons,
-child,
-extra,
-image,
-modal,
-parent,
-primary,
-resizeable,
-resizeGrip,
-secondary,
-setSize,
-title,
-tooltip,
-type,

Download and compile today's gnocl nightly build to test for yourselves. All comments and feedback most welcome especially regarding applications using glade or builder files.

The following test script shows how complex dialogs and alternative message dialogs can be made.

(In the development release the command gnocl::messageDialog is currently used to access this new  code, this will be changed to gnocl::dialog when the old code is retired.)

# test-dialog.tcl
#
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set vbox [gnocl::vBox]
set but1 [gnocl::button -text Dialog1-Chooser -onClicked { dialog1 $win} ]
set but2 [gnocl::button -text Dialog2-Message -onClicked { dialog2 $win} ]

set txt [gnocl::text]

$vbox add $but1
$vbox add $but2
$vbox add $txt -fill {1 1} -expand 1

set win [gnocl::window -child $vbox -setSize 0.25 -onDelete {exit}]

#---------------
# Test Form-Chooser Dialog.
#---------------
#
proc dialog1 {win} {
   
    set table [gnocl::table -homogeneous 1]

    $table addRow [list [gnocl::button -text "1"] "" [gnocl::button -text "2"]]
    $table addColumn [list [gnocl::button -text "3"] "" [gnocl::button -text "4"]]
    $table add [gnocl::button -text "5"] 1 0 -rowSpan 3
    $table add [gnocl::button -text "6"] 2 1 -columnSpan 2
   
    set response [gnocl::messageDialog \
        -parent $win \
        -primary HELLO \
        -modal 1 \
        -setSize 0.4 \
        -child $table \
        -title "HOW NOW BROWN COW." ]

    switch $response {
        "#OK" {
            puts "${::apple}. Well, that's alright then!"
            }
        "#CANCEL" {
            puts "Oh, maybe next time then!"
        }
        default {
            puts $response
        }
    }

}

#---------------
# Test Message Dialog, with widget and optional graphic.
#---------------
#

set apple "Granny Smith"

proc dialog2 {win} {
   
    # NOTE: variables created/access in global namespace

    set tmp $::apple

    set ent [gnocl::entry -variable tmp -tooltip "Change your mind here."]
    set txt [gnocl::text -wrapMode word]
    $txt lorem

    set im [gnocl::image -image %#Index -stockSize dialog -tooltip "Pointy Finger."]
   
    # the "-type question" setting will be overidden by "image $im"
   
    set response [gnocl::messageDialog \
        -resizable 1 \
        -title "CHOOSE!" \
        -buttons ok-cancel \
        -child $txt \
        -type  other \
        -image $im \
        -parent $win \
        -primary "WE RECOMMEND:\n$::apple" \
        -secondary "What do you like?" \
        -backgroundColor #F2F4C0 \
        -tooltip "It's time to decide."]
   
    switch $response {
        "#OK" {
            set ::apple $::tmp
            puts "${::apple}. Well, that's alright then!"
            }
        "#CANCEL" {
            puts "Oh, maybe next time then!"
        }
        "#DELETE" {
            puts "Dialog delete! How rude!"
        }
    }
    unset ::tmp
}

Comments

Popular posts from this blog

gnocl::calendar

Given this module some attention today. Added some of the more package wide options to the module and created customised handler for setting the month. (For some odd reason months are are counted 0-11 whereas days are 1-31.) There's still a little more to do to this one including the addition of code to store diary details. Here's the working test script to show the range of options at work. The percentage substitution string item %e explores something that I've been toying with, the name of the signal/event that initiated the call. Ok, a script can keep its own internal trace but who knows, it might prove useful. #--------------- # calendarTest.tcl #--------------- # Author:   William J Giddings # Date:     07/05/09 #--------------- #!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" #--------------- package require Gnocl set cal [gnocl::calendar] $cal configure -day 8 -month 7 -year 1956 $cal configure -rowHeight 1 -colWidth 1 $ca...

Gnocl Dashboard

Over the past few programming sessions I've been working on producing a central point, a dashboard, around which it's possible to see the various Gnocl widgets and commands in operation. In many ways like the demo script which shipped with the earlier releases of Gnocl but offers much more. The introspection functionality provides details of the various options and sub-commands of each Gnocl procedure which are displayed under the associated tab. Sample scripts are included for each item which offers newcomers a clearer insight into how make the most of what's on offer.

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...