next up previous contents
Next: 8.4 Implementing custom features Up: 8 Designing Custom Qddb Previous: 8.2 The tools

8.3 A simple example

  Suppose you have the following Schema for the relation MyRelation:

        a ( b c )* d

Here is a simple Fx script tailored to this Schema:

    #!/usr/local/qddb/bin/qwish -f
    lappend auto_path $qddb_library/fx
    if [info exists blt_library] {
        lappend auto_path $blt_library
    }
    set s [qddb_schema open MyRelation]
    set fx_config_dir .myapplication_config
    Fx:Init $s
    Fx_Menubar menubar -w .mb -schema $s -array gv_attr \
        -config_dir $fx_config_dir
    menubar configure -aftersearchmode {wm title . "Search Mode"}
    menubar configure -afterchangemode {
        global gv_attr ; wm title . $gv_attr(a.b)
    }
    menubar configure -afteraddmode {
        wm title . "Add Mode"
        uplevel \#0 [list set gv_attr(a.c) "My default value"]
    }
    Fx_Frame a -w .a -setschema $s -attr a -side top \
        -anchor nw -relief raised -afteradd {
            uplevel \#0 [list set gv_attr(a.c) "My default value"]
    }
    Fx_Entry a.b -w .a.b -searchfor_entry [menubar SearchForEntry] \
        -setschema $s -attr a.b -relief sunken -bd 3 -side left
    Fx_Entry a.c -w .a.c -attr a.c -relief sunken -bd 3 -side left
    a configure -focus [a.b GetEntry]
    Fx_Entry d -w .d -attr d -relief sunken -bd 3 -side left
    menubar configure -instances [Fx_Entry :: GetInstances] \
        -frames [Fx_Frame :: GetInstances]
    menubar SearchModeProc ;# start out in Search Mode

The example first sets up the auto_path global Tcl variable, opens the schema, and initializes Fx with Fx:Init. It defines the menubar and configures it to perform certain tasks when entering Search, Change, and Add Mode. Next, it builds the Fx_Frame and Fx_Entrys corresponding to the schema. It passes a schema to the first call to Fx_Frame and Fx_Entry and a searchfor_entry to the first call to Fx_Entry. The frame is configured with the -focus option after all the nested Fx_Entrys are defined; this is to specify where the focus will be placed after pressing the Add or View button for that frame. Finally, we associate all the Fx_Frames and Fx_Entrys with the menubar and go to Search Mode. Note: within the call to menubar configure -afteraddmode we use an uplevel \#0 to set the value of the linked variable gv_attr(a.c) (created with Tcl_LinkVar); this is necessary due to an interaction with [incr Tcl]. You must use uplevel \#0 when setting the value of a linked variable from within an [incr Tcl] class.



Herrin Software Development, Inc.