Tk Source Code

View Ticket
Login
Ticket UUID: 905c9af481e18e1ecd2c92c8ed86de1e6961b2bd
Title: Some embedded buttons do not get mapped in a Text peer.
Type: Bug Version: 8.6
Submitter: marc_culler Created on: 2017-10-19 16:07:01
Subsystem: 18. [text] Assigned To: fvogel
Priority: 1 Zero Severity: Cosmetic
Status: Closed Last Modified: 2017-10-28 18:09:13
Resolution: Invalid Closed By: marc_culler
    Closed on: 2017-10-28 18:09:13
Description:
In the widget demo, open the Text demo #4 ("A text widget with embedded windows
and other features") and click the "Split Windows" button.  In the right hand
window, scroll to the bottom.  All of the buttons for changing background
colors or borders which are present in the left window are missing from the
right window.

The principle seems to be that any button which is not visible when the peer
window opens will be permanently missing from the peer.  Scrolling to where
such a button is located does not cause it to get mapped.

I have tested this on macOS and 64-bit Windows (building with mingw-64).  I
see the same behavior on both platforms.
User Comments: marc_culler added on 2017-10-28 18:08:22:
Since this is not a bug, but a documented feature, I am closing the ticket.  (Sorry about that ...)

fvogel added on 2017-10-22 18:52:06:

And those missing buttons are advertised in the demo itself, in which we can read:

"Notice how peer widgets can have different font settings, and by default contain all the images of the 'parent', but many of the embedded windows, such as buttons will not be there.  The easiest way to ensure they are in all peers is to use '-create' embedded window creation scripts (the plot above and the 'Make A Peer' button are designed to show up in all peers)."

I would rather let this demo as it is now. It emphasizes the difference between -window and -create.

Conclusion: there is nothing to fix regarding the present ticket after all.


fvogel added on 2017-10-22 15:59:13:

TIP #169 states that the -window option is not shared between peers.

The absence of error looks intentional. This is explicitely tested in several places of the test suite, e.g. textWind-17.7


marc_culler (claiming to be Marc Culler) added on 2017-10-22 14:29:02:
If an error were generated then the demo script would have been fixed long ago.

fvogel added on 2017-10-22 13:58:40:
> Evidently the author of the twind.tcl demo was ignoring this "feature". Maybe this should be classified as a bug in twind.tcl.

Agreed.

Looking at the history of changes in twind.tcl it becomes obvious.
Originally (1998) there was no peering feature in the text widget. Then TIP #169 was implemented (2004), with additional text and buttons in the twind.tcl demo. But at this time it was unnoticed that the originally present buttons were not correctly mirrored in the peer.

I'll fix that demo.

What I'm wondering is whether an error should not be thrown instead of silently ignoring the embedded window in the peer. I guess it should complain (a peer is a peer, it should not be different than another peer).

fvogel added on 2017-10-22 13:41:16:
Looks like our both analyses crossed each other. Fortunately our conclusions are in agreement.

fvogel added on 2017-10-22 13:39:38:

In that [text] demo #4, buttons that DO show up in the peer are those that were created through:

.t window create end -create {button .b -text "A button"}

Those that DO NOT show up in the peer were created through:

button .b -text "A button"
.t window create end -window .b

Moreover, the images do show up because they are necessarily created through

set myim [image create photo -file $myfilename]
.t image create end -image $myim

It is an error to say

.t image create end -create {image create photo -file $myfilename}

The -create option is not supported for images, only for embedded windows.

So this explains why it works for images, and for some buttons.

I also find quite interesting that the following script:

package require Tk
text .t
.t peer create .tt
pack .t .tt
update
.t window create end -create {button .b -text "A button"}

errors out with "window name "b" already exists in parent".

In fact, reading the manual this is not really unexpected:

-create script
Specifies a Tcl script that may be evaluated to create the window for the annotation. If no -window option has been specified for the annotation this script will be evaluated when the annotation is about to be displayed on the screen. Script must create a window for the annotation and return the name of that window as its result.

The creation script is evaluated for each peer, and the second time it is discovered that the window name already exists.


marc_culler (claiming to be Marc Culler) added on 2017-10-22 13:27:29:

The issues here seem to be:

  • A Text widget cannot display an embedded window which is a child of another Text widget, e.g. one of its peers. Attempting to do this generates an error.
  • A Text widget cannot display an embedded window which is a sibling if that sibling has already been associated with a different Text widget. Attempting to do this does not generate an errror; the embedded window is silently ignored.

What this means in practice is that if you want peer Text widgets to display common embedded windows they must each have their own copy of the window. This essentially means that the subwindow should be specified with the -create option, giving a name containing the %W macro. But it is also possible to provide a script which returns the name of the embedded window, such as the script $myim in the posted image example.

Evidently the author of the twind.tcl demo was ignoring this "feature". Maybe this should be classified as a bug in twind.tcl.

Here is a simple script which illustrates this:

package require Tk
text .t
.t peer create .tt
pack .t .tt
button .b -text "A bad button"
.t window create end -window .b
.t window create end -create {button %W.g -text "A good button"}


fvogel added on 2017-10-21 14:41:20:

What I find interesting to note is that (with that same demo #4), the problem does not happen for the embedded image (Ousterhout picture), only for the embedded windows.

Implementations of these two embedded things in the text widget are very similar.

Short non-working script, with an embedded window:

package require Tk
text .t
.t peer create .tt
pack .t .tt
button .b -text "A button"
update
.t window create end -window .b

Short working script, with an embedded image:

package require Tk
set imdir /home/francois/Documents/tcltk/fossil/tk/library/demos/images/
text .t
.t peer create .tt
pack .t .tt
set myim [image create photo -file [file join $imdir ouster.png]]
update
.t image create end -image $myim


marc_culler (claiming to be Marc Culler) added on 2017-10-21 14:09:16:
If the script is modified so the text widget is 70 lines tall and all buttons are visible, then the same buttons are missing from the peer as when the window is left at its original size.  In fact the top two buttons are missing even without this modification.  So the principle that I stated is wrong, and I have no idea how to characterize which buttons will not be displayed in the peer.

fvogel added on 2017-10-21 13:45:49:
Also happens with the revised text widget (tested on Linux Debian 8).

marc_culler (claiming to be Marc Culler) added on 2017-10-19 23:47:16:
This bug also occurs in the Tcl/Tk 8.6 that is distributed with Ubuntu 16.04 LTS.