D Groth schrieb am Dienstag, 21. März 2023 um 15:23:23 UTC+1:
Christian Gollwitzer schrieb am Montag, 20. März 2023 um 19:20:28 UTC+1:
Am 20.03.23 um 14:51 schrieb D Groth:
Dear all,
I played a little bit around of using TclOO for the creation of megawidgets. Usually I use snit, but TclOO offers the benefit of redefining methods at runtime. Using TclOO from my side for the first time everything was straight forward. In my
second version I implemented :
- inheritance
- composition
- mixins
If I have missed an existing package which does a similar thing, please tell me.
Maybe also have a look at "snot", which is a reimplementation (not 1:1)
of Snit in TclOO. Looks very promising to me:
http://chiselapp.com/user/aspect/repository/snot/dir?ci=tip
Christian
Thanks Christian,
I knew this project before, but having another syntax to learn was something I did not like at that time. My goal was to have a widget creation framework which does not introduce a new syntax. That's one of the reasons I was looking into oo::class,
arguing that knowing oo::class better opens more possibilities outside of megawidget creation ;)
At the bottom of the Readme: https://github.com/mittelmark/oowidgets I have a comparison of a snit vs a oowidget, the latter is much easier to read for someone coding in TclOO. The only non TclOO syntax is the class declaration using oowidgets::widgets
instead of oo::class create ... (callback instead of mymethod will be introduced with 8.7).
I will add a few more examples of real megawidgets later, currently just two a dlabel based on ttk::label and a composite widget based on label, frame and progressbar..
Detlef
May be a code example explains it at best, here the at that time amazing implementation, no OOP in the core, of the read only text widget in snit:
https://wiki.tcl-lang.org/page/Snit's+Not+Incr+Tcl (rotext).
Here is now the implementation using oowidgets based on TclOO:
```
package require oowidgets
namespace eval ::test { }
::oowidgets::widget ::test::Rotext {
variable textw
constructor {path args} {
# we need the real widget (underline at the end)
set textw ${path}_
# Create the text widget; turn off its insert cursor
my install tk::text $path -insertwidth 0 -border 5 -relief flat
my configure {*}$args
}
# Disable the text widget's insert and delete methods
# to make this readonly even if the user writes text.
method insert {args} { }
method delete {args} { }
# programmatically we can still insert and delete ...
method ins {args} { $textw insert {*}$args }
method del {args} { $textw delete {*}$args }
}
```
That are just 10 lines of code with no special keywords anywhere (install is a method defined in the base class). BTW: the widget is then test::rotext (lowercase R).
I was my self wondering how short and clear this can be ...
Detlef
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)