On Thu, 27 Jun 2024 23:41:16 +0000, Robert Heller wrote:
Snit always seemed to have good enough documentation for me.
Of course I am not very bright (or I have no previous experience with
OOP if you want to be kind), but I am struggling with using snit at all
because of this:
The world famous snit faq says:
"For example, the following code creates a read-only text widget... "
etc. etc.
::snit::widgetadaptor rotext {
constructor {args} {
# Create the text widget; turn off its insert cursor
installhull using text -insertwidth 0
# Apply any options passed at creation time.
$self configurelist $args
}
# Disable the text widget's insert and delete methods, to
# make this readonly.
method insert {args} {}
method delete {args} {}
# Enable ins and del as synonyms, so the program can insert and
# delete.
delegate method ins to hull as insert
delegate method del to hull as delete
# Pass all other methods and options to the real text widget, so
# that the remaining behavior is as expected.
delegate method * to hull
delegate option * to hull
}
Yeah, the document has some examples.
Now, how do I call that? I did it like this:
rotext .rox
and nothing happened. Well, I got the Tk gray box.
The world famous snit faq says:
"For example, the following code creates a read-only text widget... "
Where is the text widget then?
After a lot of struggle, I fixed it by adding 'pack $win' within the
constructor. Why can't the manual tell me that? Why can't the example
code include it?
There was more struggle.
snit::widget TopWindow {
hulltype toplevel
delegate option * to hull
component of
variable of
constructor {args} {
wm withdraw .
wm resizable $win 1 1
wm attributes $win -zoomed 0
wm geometry $win 600x100+0+0
wm title $win "test"
tk appname "test"
bind $win <Alt-q> {exit 0}
bind $win <Alt-Q> {exit 0}
install of using frame $win.of
pack $of -fill both -expand 1
$self configurelist $args
}
}
TopWindow .toplevel
Now, how do I add the read-only text widget to that toplevel?
Again, a lot of struggle to figure this out:
rotext .toplevel.of.rox
Why can't the manual tell me that?
And I can only do that by explicitly referencing ".toplevel"
which seems inadequate. There should be a variable that contains
that toplevel path. There probably is, but heck if I know what
that is.
I'm still struggling with other things. Anyway, my point is
the documentation has multiple examples of how to create a
type but no examples whatsoever of how to call what the code
is creating. It just assumes the reader knows because it's obvious.
But it took me a long time to guess on my own.
Thank you for your guidance once again.
-- Luc>