• tcl/tk widget - default values scheme - used to specify common option v

    From Lawrence Emke@21:1/5 to All on Thu Mar 16 16:22:14 2023
    newbee to tcl.

    I want to create a widget that has all of the common default values for an entire application, so there is only one place to reference/change.

    Most of the values are just character strings. but some are
    more complicated structures. For example consider a font specification.
    I can copy the font definition string into every widget. but when the command is executed, it seems to create that new structure in the new namespace.

    I would like to have only one copy of the structure in the application
    and not create redundant copies. To do this, my guess is that I have to reference structure in the original namespace. How do I do this?

    I want to pass the default value object to the new widget as an "option"
    value and have the constructor reference the same font structure in every widget as needed..

    Is this possible? (good?). How do you access the font definition in the
    new widget's constructor that has/may have a new/different namespace?

    A calling procedure (uplevel 1) may instantiate the first default value object instance or may receive it after it is created and passes it to the next widget. The default-value structure may reside in a completely separate namespace to isolate it from
    the application.

    I also thought about placing a variable in the global scope that points to the default value object and access it via this path. I don't like placing any data in the global namespace. Maybe using a specific namespace value is a better choice.

    Any help is appreciated!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to Lawrence Emke on Sat Mar 18 14:51:46 2023
    On 17/03/2023 00:22, Lawrence Emke wrote:
    I want to create a widget that has all of the common default values for an entire application, so there is only one place to reference/change.

    The option command may be what you are looking for. For example:

    option add *Cursor hand1 startupFile

    This will cause all subsequently created widgets to have "hand1" as
    their -cursor option, unless overridden with an explicit -cursor option.

    If you want a different cursor for just one class of widgets (e.g. ttk::buttons), then add:

    option add *TButton.Cursor heart startupFile


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)