Check-in [9a757d6209]

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:New state of tip510. oo::clas like widgets, dynamic configure, additional widgets
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9a757d6209d426f35b2dceb0ef174c748ef4011d9badb474f8f6dcd70f2e124b
User & Date: rene 2019-04-12 13:00:01
Context
2019-04-14
07:57
Fix minor nits found by AK check-in: c602e5096b user: dkf tags: trunk
2019-04-12
13:00
New state of tip510. oo::clas like widgets, dynamic configure, additional widgets check-in: 9a757d6209 user: rene tags: trunk
12:38
Update 262 based on experience while writing the implementation check-in: 4b8178d136 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tip/510.md.

13
14
15
16
17
18
19
20












































21
22
23
24


25
26
27
28
29
30
31
32
..
37
38
39
40
41
42
43




44
45
46
47
48
49
50
..
57
58
59
60
61
62
63
64
65
66

67
68
69
70

71

72
73
74
75
76
77

































78


79
80
81
82
83
84

85


86










87
88
89
90
91
92

93













94
95
96
97
98
99
100
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
	Votes-Against:  KBK, JN, FV
	Votes-Present:  BG
	Vote-Comments:  code not yet ready, needs porting to macOS; alternate
	                might be to just co-distribute, just as TDBC is with Tcl
-----

# Abstract













































[Rbc][] aka "Refactored [BLT][] Components" have graph widgets and Tk commands which are missing in *Tk*.

[Tkpath][] is a 2D-canvas like widget modelled after [SVG][].



This TIP intends to add the following command to Tk:

**rbc::graph**, **rbc::stripchart** and **rbc::barchart** as **graph**

> To get the original functionality a *-style* option will be added. This
option can only be set on creation time.

**rbc::vector** as **graph::vector**
................................................................................

> Only the snap functionality is needed here. The busy command already exists as "tk busy" :)

**tkp::canvas** as **path**

> The new path widget will contain the [SVG][] like items and an additional **window** item to include other windows. Support functions will be placed in the **::path** namespace.





# Rationale

## Rbc commands

*Tk* has already adopted some of [BLT][]/[Rbc][] commands.
Still missing are the above mentioned commands.

................................................................................

## Tkpath

The original developer of [Tkpath][] passed away. There are some mirrors, but with no real development. More information could be found on <https://wiki.tcl-lang.org/page/tkpath>.

The intent of [Tkpath][] was to substitute the *Tk* canvas. This leads to problems with advanced features (matrix transformations). Therefore the new **path** widget will only contain [SVG][] like items. The only exception is the **window** item. This item is necessary to embed other widgets.

# Specification

## Files


- C-source code will be put in `.../generic/rbc/`
  - `rcb*.[ch]` graph widget and vector command
  - `tk*.[ch]` tkpath widget

- Tcl-source code will be put in `.../library/`

  - [`graph.tcl`](https://core.tcl.tk/tk/doc/tip-510/library/graph.tcl) graph widget bindings
  - [`path.tcl`](https://core.tcl.tk/tk/doc/tip-510/library/path.tcl) path widget helper function under **::path**
- Documentaion files will be put in `.../doc/`
  - [`graph.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/graph.n.md) graph widget documentation
  - [`vector.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/vector.n.md) graph::vector command documentation
  - [`path.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/path.n.md) path widget documentation

































- Test files will be put in `.../tests/rbc/`


  - [`graph.test`](https://core.tcl.tk/tk/doc/tip-510/tests/rbc/graph.test) graph widget tests
  - [`graph_vector.test`](https://core.tcl.tk/tk/doc/tip-510/tests/rbc/graph_vector.test) graph::vector command tests
  - [`path.test`](https://core.tcl.tk/tk/doc/tip-510/tests/rbc/path.test) path widget tests

The new files are  added to the makefiles.
The calls to the initialization functions are in tkWindow.c




## ::oo::class widgets











The new widgets **graph** and **path** are implemented as **oo::class**. This will make it easy to extent the functionality. As an example see the file `.../library/graph.tcl` in which the method **binding** of the **graph** widget is implemented.

## C Interface

Alle new functionality is in the two header files [`rbcInt.h`](https://core.tcl.tk/tk/doc/tip-510/generic/rbc/rbcInt.h) and [`tkPathInt.h`]((https://core.tcl.tk/tk/doc/tip-510/generic/rbc/tkPathInt.h). No functionality is currently exported.

 













# Discussion

See also discussion at the [wiki](http://wiki.tcl.tk/55360).

A first voting was rejected, mostly because of the missing Mac implementation. See:

<http://code.activestate.com/lists/tcl-core/20357/>  
................................................................................
and with some analysis from Donal:

<http://code.activestate.com/lists/tcl-core/20384/>  

# Open issues

- Mac implementation of **graph** widget. May be borrow code from **path**
- Remove or change old code in `generic/rbc/rbc*` files <http://code.activestate.com/lists/tcl-core/20384/>
- Hardcoded usage of compiler and libraries in [`win/Makefile.in`](https://core.tcl.tk/tk/doc/tip-510/win/Makefile.in), [`win/makefile.vc`](https://core.tcl.tk/tk/doc/tip-510/win/makefile.vc) and [`unix/Makefile.in`](https://core.tcl.tk/tk/doc/tip-510/unix/Makefile.in) (search for "#RZ TODO").
- Add **path** files in Mac implementation. It works at least in [Androwish][].
- Which platforms should be used in **path**
  - SDL/AGG: platform independent, more work is needed using [`tkSDLAGGPath.cpp`](https://core.tcl.tk/tk/doc/tip-510/generic/rbc/tkSDLAGGPath.cpp). See in [Androwish][]
  - GDI+ on Windows => working with [`tkWinGDIPlusPath.cpp`](https://core.tcl.tk/tk/doc/tip-510/generic/rbc/`tkWinGDIPlusPath.cpp)
  - Cairo on unix => working with [`tkUnixCairoPath.c`](https://core.tcl.tk/tk/doc/tip-510/generic/rbc/tkUnixCairoPath.c)
  - For Mac see [`tkMacOSXPath.c`](https://core.tcl.tk/tk/doc/tip-510/generic/rbc/tkMacOSXPath.c)
- Provide demos
- Add more **path** tests
- Is it necessary to translate the documentation into man format?
- It is currently not possible to use unique abbreviations of slass method names p.e. "graph .g; .g conf" A workaround would be to add all those method names. May be this can be solved in tcl::oo directly?

Any help especially with the Mac implementation would be great!

And could please look someone with `configure` foo at the Makefile's

# Implementation

A patch implementing these changes is available in the fossil
repository in the [tip-510 branch](https://core.tcl.tk/tk/timeline?r=tip-510).

Test files are available in the .../tests/rbc/ directory.

Documentation is available in md-Format in the .../doc/ directory.

# Alternatives

- Wait on new [BLT][].
- Develop widgets in extensions.

# Copyright








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
|







 







>
>
>
>







 







|

|
>

<
|
<
>
|
>
|
<
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
|
|

<
<
>

>
>
|
>
>
>
>
>
>
>
>
>
>
|
<
|
<

<
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|



|
|
|
|









<
<
<
<
<
<
<
<
<







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
107
108
109
110
111
112
113
114
115
116
117
118

119

120
121
122
123

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

184

185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233









234
235
236
237
238
239
240
	Votes-Against:  KBK, JN, FV
	Votes-Present:  BG
	Vote-Comments:  code not yet ready, needs porting to macOS; alternate
	                might be to just co-distribute, just as TDBC is with Tcl
-----

# Abstract

## oo::class like widgets

The new widgets are implemented in C as oo::classes. The base class is **tko::widget**. These class create and handles the internal Tk\_Window and provide **cget** and **configure** methods. The **configure** method has additional functionality to add or delete options. The new widget functionality is documented in the [`tkoWidget.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/tkoWidget.n.md) file.

The new widgets **graph** and **path** are implemented as **oo::class**. This will make it easy to extent the functionality. As an example see the file `.../library/graph.tcl` in which the method **binding** of the **graph** widget is implemented.

## Enhanced **configure** functionality

**configure** *args*

> **configure**

> > If *args* is empty the method will return a sorted list of all configuration options.

> **configure** *-option*

> > If we have one element in *args* starting with a minus sign ("-") then the method return the configuration list including the current value of the given *-option*.

> **configure** *-option value ..*

> > If we have an even number list in *args* and the first element starts with a minus sign ("-") then the method does configure all the given option-value pairs. If an error occurs the the corresponding element is not set and the method gives an error. Alrready successfull set options remain.

> **configure init**

> > This is an internal function used in constructing new widgets. It is used in the *unknown* method to initialize all options.

> **configure optionadd** *-synonym -option*

> > Add a *-synonym* for a given *-option*. The *-option* needs not to be defined at this time.

> **configure optionadd** *-synonym dbnam dbclass ?default? ?flags?*

> > Add a new option. If ?flags? is equal "1" then the option is readonly and can only be set in this call. Before adding a new option a *-option* method must created. The method will be called without any arguments. The method can access the new value using the *tko(-option)* array variable. If the method throws a n error the array variable will be reset to the old value.

> **configure optiondel** *-option*

> > Delete the given option and unset the entry in the tko array variable. The created *-option* method's are not deleted. This is the task of the caller.

> **configure optionvar**

> > The method return the global varname of the tko array variable holding all option values.

## New widgets

[Rbc][] aka "Refactored [BLT][] Components" have graph widgets and Tk commands which are missing in *Tk*.

[Tkpath][] is a 2D-canvas like widget modelled after [SVG][].

*Tk* has already **frame**, **labelframe** and **toplevel** widgets. These widgets have class like behaviour but are no real classes. It is p.e. not possible to add functionality to these widgets.

This TIP intends to add the following commands to Tk:

**rbc::graph**, **rbc::stripchart** and **rbc::barchart** as **graph**

> To get the original functionality a *-style* option will be added. This
option can only be set on creation time.

**rbc::vector** as **graph::vector**
................................................................................

> Only the snap functionality is needed here. The busy command already exists as "tk busy" :)

**tkp::canvas** as **path**

> The new path widget will contain the [SVG][] like items and an additional **window** item to include other windows. Support functions will be placed in the **::path** namespace.

**tko::frame** **tko::labelframe** and **tko::toplevel**

> These widgets have the same functionality like the normal tk widgets. They are implemented as oo::classes and it is possible to add/delete options.

# Rationale

## Rbc commands

*Tk* has already adopted some of [BLT][]/[Rbc][] commands.
Still missing are the above mentioned commands.

................................................................................

## Tkpath

The original developer of [Tkpath][] passed away. There are some mirrors, but with no real development. More information could be found on <https://wiki.tcl-lang.org/page/tkpath>.

The intent of [Tkpath][] was to substitute the *Tk* canvas. This leads to problems with advanced features (matrix transformations). Therefore the new **path** widget will only contain [SVG][] like items. The only exception is the **window** item. This item is necessary to embed other widgets.

# Implementation

A patch implementing these changes is available in the fossil
repository in the [tip-510 branch](https://core.tcl.tk/tk/timeline?r=tip-510).


## Documentation


Documentation is in markdown syntax understood by fossil and can therefore accessed online. The files will be put in the directory `.../doc/`.

- [`tkoWidget.3.md`](https://core.tcl.tk/tk/doc/tip-510/doc/tkoWidget.3.md) tko::widget C-function documentation

- [`tkoWidget.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/tkoWidget.n.md) tko::widget Tcl command documentation
- [`graph.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/graph.n.md) graph widget documentation
- [`vector.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/vector.n.md) graph::vector command documentation
- [`path.n.md`](https://core.tcl.tk/tk/doc/tip-510/doc/path.n.md) path widget documentation

## C interface

Alle new functionality is in the following header files:

- [`tkoWidget.h`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoWidget.h) tko::widget function
- [`tkoGraph.h`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoGraph.h) graph functions
- [`tkoPath.h`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoPath.h) path functions

No functionality is currently exported. The new files are  added to the makefiles.

The initialization function **Tko\_Init** is added to the *tkInt.h* file and will be called in *tkWindow.c*.

## C sources

C-source code will be put in the directory `.../generic/tko/`

- [`tkoWidget.c`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoWidget.c) tko::widget implementation
- [`tkoFrame.c`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoFrame.c) tko::frame, tko::labelframe and tko::toplevel implementation
- `tkoPath*.c` tkpath widget implementation
- `tkoGraph*.c` graph widget implementation
- `tkoRbc*.c` graph related common [Rbc][] functions.
- `tkoVector*.c` graph vector commadn implementation

## Tcl source

Tcl-source code will be put in the directory `.../library/`

- [`graph.tcl`](https://core.tcl.tk/tk/doc/tip-510/library/graph.tcl) graph widget bindings
- [`path.tcl`](https://core.tcl.tk/tk/doc/tip-510/library/path.tcl) path widget helper function under **::path**

## Tests

Test files will be put in the directory `.../tests/tko/`

- [`tkoFrame.test`](https://core.tcl.tk/tk/doc/tip-510/tests/tko/tkoFrame.test) tko::frame, tko::labelframe and tko::toplevel widget tests. The tests are mostly identical to the corresponding tk widget tests.
- [`tkoGraph.test`](https://core.tcl.tk/tk/doc/tip-510/tests/tko/tkoGraph.test) graph widget tests
- [`tkoGraph_vector.test`](https://core.tcl.tk/tk/doc/tip-510/tests/tko/tkoGraph_vector.test) graph::vector command tests
- [`tkoPath.test`](https://core.tcl.tk/tk/doc/tip-510/tests/tko/tkoPath.test) path widget tests



# Examples

Add options at class level:

    oo::class create myWidget {
      {*}$::tko::unknown
      superclass ::tko::frame
      variable tko
      method -myoption {} {puts $tko(-myoption)}
      method -myreadonly {} {puts $tko(-myreadonly)}
      constructor {optionlist arglist} {
        next [concat {
          {-myoption myOption MyOption value}
          {-myreadonly myReadonly MyReadonly value 1}
        } $optionlist] $arglist
      }

    }



Deal with optons at object level. This is the raw part. May be we should add some sugar to it.

    myWidget .w
    oo::objdefine .w method -o1 {} {puts $tko(-o1)}
    oo::objdefine .w method -o2 {} {puts $tko(-o2)}
    .w configure optionadd -o1 o1 O1 v1 1
    .w configure optionadd -o2 o2 O2 v2
    ...
    .w optiondel -o1

Widget option values are saved in an option array. The option name is the field name in the array. Additionally is an field "**.**" containing the tk widget path name of the widget. The name of the option array variable can be retrieved using the following code:
    set myVar [.w configure optionvar]
    parray $myVar


# Discussion

See also discussion at the [wiki](http://wiki.tcl.tk/55360).

A first voting was rejected, mostly because of the missing Mac implementation. See:

<http://code.activestate.com/lists/tcl-core/20357/>  
................................................................................
and with some analysis from Donal:

<http://code.activestate.com/lists/tcl-core/20384/>  

# Open issues

- Mac implementation of **graph** widget. May be borrow code from **path**
- Remove or change old code in `generic/tko/tkoGraph*` and  `generic/tko/tkoRbc*` files <http://code.activestate.com/lists/tcl-core/20384/>
- Hardcoded usage of compiler and libraries in [`win/Makefile.in`](https://core.tcl.tk/tk/doc/tip-510/win/Makefile.in), [`win/makefile.vc`](https://core.tcl.tk/tk/doc/tip-510/win/makefile.vc) and [`unix/Makefile.in`](https://core.tcl.tk/tk/doc/tip-510/unix/Makefile.in) (search for "#RZ TODO").
- Add **path** files in Mac implementation. It works at least in [Androwish][].
- Which platforms should be used in **path**
  - SDL/AGG: platform independent, more work is needed using [`tkoPath_SDLAGG.cpp`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoPath_SDLAGGPath.cpp). See in [Androwish][]
  - GDI+ on Windows => working with [`tkoPath_WinGDIPlus.cpp`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoPath_WinGDIPlus.cpp)
  - Cairo on unix => working with [`tkoPath_UnixCairo.c`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoPath_UnixCairo.c)
  - For Mac see [`tkoPath_MacOSX.c`](https://core.tcl.tk/tk/doc/tip-510/generic/tko/tkoPath_MacOSX.c)
- Provide demos
- Add more **path** tests
- Is it necessary to translate the documentation into man format?
- It is currently not possible to use unique abbreviations of slass method names p.e. "graph .g; .g conf" A workaround would be to add all those method names. May be this can be solved in tcl::oo directly?

Any help especially with the Mac implementation would be great!

And could please look someone with `configure` foo at the Makefile's










# Alternatives

- Wait on new [BLT][].
- Develop widgets in extensions.

# Copyright