setting widget names in STklos

From: Erik Ostrom <eostrom_at_research.att.com>
Date: Wed, 4 Sep 1996 21:56:14 GMT

(I apologize in advance for the ignorance about X resources that I'm
about to display.)

In order to make good use of X resources, it seems that in some cases
I have to be able to make guarantees about the names of my widgets.
For example, I currently want a user or site administrator to be able
to set a default font for the text input sections of my bug-reporter
widget:

   STk*Bug-Reporter*input*font: -Adobe-Helvetica-Medium-R-Normal--*-120-*

In order for this to work, I need to be able to make sure the word
"input" is in the widget ID for each widget that this should apply to
(and is _not_ in the ID for widgets that it _shouldn't_ apply to).
But if I use STklos, all my widgets have names like .v1.v3.v6.v10, and
the numbers may vary widely from instantiation to instantiation.

I'd like to propose a small addition. Allow the programmer to pass in
an initializer, say `:name', when creating any widget with `make'. If
present, this is appended to the parent's ID to create the new
widget's ID (e.g., ".v1.v3.v6.input"). If not, it's generated
automatically in the old way.

This requires a change to Tk::make-tk-name (changing the meaning of
the second argument, which seems to be unused in the library) and a
change to the initialize method for <Tk-simple-widget>. In addition,
I think composite widgets should pass the :name initializer to their
frames; so that requires a change to the initialize method for
<Tk-composite-widget>.

Code follows; I'd like it if something like this were integrated
into the main STk distribution, or if someone explained to me a better
way to do this.

Thanks
--Erik


----------------------------------------------------------------------
In Tk-methods.stklos:

  redefine Tk::make-tk-name:

    ;;; (Tk::make-tk-name parent value)
    ;;;
    ;;; parent must be a widget. value, if true, is a string or symbol
    ;;; containing the `subname' of a new widget, i.e., the part that's
    ;;; appended to the parent's name. if false, a subname will be
    ;;; generated automatically.
    
    (define Tk::make-tk-name
      (let ((counter 0))
        (lambda (parent subname)
          (format #f "~A.~a~a"
                  (if (or (eq? parent *root*) (eq? parent *top-root*))
                      ""
                      (widget->string (slot-ref parent 'Id)))
                  (if subname "" "v")
                  (or subname
                      (begin (set! counter (+ counter 1)) counter))))))

In Basics.stklos:

  In <Tk-simple-widget>'s initialize method, change the definition of `Eid':

              (set! Eid (apply (tk-constructor self)
                               (Tk::make-tk-name parent
                                                 (get-keyword :name initargs #f))
                               tk-options))

  In <Tk-composite-widget>'s initialize method, change the definition of `frame':

             (frame (make <Frame> :parent parent
                                   :name (get-keyword :name initargs #f)))
Received on Thu Sep 05 1996 - 09:38:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST