Re: My hang-up about OOP (snit)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: My hang-up about OOP (snit)
De : luc (at) *nospam* sep.invalid (Luc)
Groupes : comp.lang.tcl
Date : 28. Jun 2024, 01:27:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240627212704.46c26379@lud1.home>
References : 1 2 3 4 5 6
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
>


Date Sujet#  Auteur
25 Jun 24 * My hang-up about OOP (snit)22Luc
25 Jun 24 +* Re: My hang-up about OOP (snit)10Rich
25 Jun 24 i`* Re: My hang-up about OOP (snit)9Luc
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i `* Re: My hang-up about OOP (snit)5Rich
27 Jun 24 i  +* Re: My hang-up about OOP (snit)3Luc
27 Jun 24 i  i`* Re: My hang-up about OOP (snit)2Rich
27 Jun 24 i  i `- Re: My hang-up about OOP (snit)1Lawrence Woodman
27 Jun 24 i  `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 +- Re: My hang-up about OOP (snit)1saito
26 Jun 24 +* Re: My hang-up about OOP (snit)9Robert Heller
27 Jun 24 i`* Re: My hang-up about OOP (snit)8Luc
27 Jun 24 i `* Re: My hang-up about OOP (snit)7Robert Heller
27 Jun 24 i  `* Re: My hang-up about OOP (snit)6Luc
28 Jun 24 i   `* Re: My hang-up about OOP (snit)5Robert Heller
28 Jun 24 i    `* Re: My hang-up about OOP (snit)4Luc
28 Jun 24 i     `* Re: My hang-up about OOP (snit)3Robert Heller
28 Jun 24 i      `* Re: My hang-up about OOP (snit)2Luc
28 Jun 24 i       `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 `- Re: My hang-up about OOP (snit)1Luis Mendes

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal