Tk Source Code

View Ticket
Login
Ticket UUID: 3588460
Title: -typevariable buggy in X11
Type: Bug Version: None
Submitter: auriocus Created on: 2012-11-19 09:14:50
Subsystem: 37. [tk_get*File] Assigned To: fvogel
Priority: 6 Severity: Minor
Status: Closed Last Modified: 2016-10-30 18:05:26
Resolution: Fixed Closed By: fvogel
    Closed on: 2016-10-30 18:05:26
Description:
The -typevariable option is buggy in X11. According to TIP 242 the typevariable should hold the type as specified. This script:

package require tcltest
package require Tk

puts [tk_getSaveFile -initialfile foo -typevariable seltype -filetypes {{TEXT *.txt}}]
puts $seltype

# behaviour before the patch
# Win: TEXT
# Tk/Carbon: TEXT
# Tk/Cocoa: seltype is undefined
# X11: TEXT (*.txt)
#
# after the patch
# X11: TEXT

gives the expected output under Win and Tk/Carbon. The modified result in X11 prevents the use case of switching on the value of typevariable. The attached patch fixes the problem for X11.
User Comments: fvogel added on 2016-10-30 18:05:26:
Merged in core-8-6-branch and trunk.

fvogel added on 2016-10-21 20:05:44:

Commit [374cb204] now aligns the behavior in tk_strictMotif true to be the same as when tk_stricMotif is false, on the grounds of the use case brought by the OP, which is switching on the value of the typevariable.

Test filebox-3.5.1 updated to test this accordingly.

This change also fixes a bug of the file dialog in tk_strictMotif true: the labels of the radiobutton allowing to switch between file types showed their first word only.

Tests from filebox.test are 100% OK for me now (on Debian 8).

Will merge in a few days unless someone objects.


fvogel added on 2016-10-12 19:50:13:
Forgot to mention this. About your suggestion:

"A drop-in replacement, which not only fixes this bug, but also provides a modern appearance and comfort functions like creating new directories, is available from Schelte Bron at http://chiselapp.com/user/schelte/repository/fsdialog/index"

--> This looks appealing. I'm wondering whether going that way would need a TIP. Please proceed if you wish so.

fvogel added on 2016-10-12 19:23:43:

Test case filebox-3.5.0 broken by the patch now fixed by [f6c7486e].

This change also now serves as the non-regression test I planned to add for the patch.

Note that in strict Motif case, we still have:

% package require Tk
8.6.6
% set tk_strictMotif 1 
1
% tk_getSaveFile -initialfile foo -typevariable seltype -filetypes {{{Text files} *.txt}}
/home/francois/Documents/tcltk/fossil/tk/unix/foo
% puts $seltype
Text files (*.txt)
% 

i.e. the patch only changed the case when tk_strictMotif is false.

This result may be correct, I don't know.

And since I don't know I didn't try to change this nor to change the test result of filebox-3.5.1, which precisely checks the same thing as filebox-3.5.0 but in tk_strictMotif mode.

Opinions?


fvogel added on 2016-10-12 18:56:52:

Thanks for the clarification. Makes sense indeed.

I have put your patch in branch [bug-3588460fff].

Problem now is that this patch makes a test from the test suite fail:

==== filebox-3.5-0 tk_getOpenFile command FAILED
==== Contents of test case:

            catch {unset tv}
            catch {unset typeName}
            ToPressButton $parent ok
            if {[info exists tv]} {
            } else {
            }
            set choice [tk_getOpenFile -title "Press Ok"  -filetypes $filters($x) -parent $parent  -initialfile $fileName -initialdir $fileDir  -typevariable tv]
            if {[info exists tv]} {
                regexp {^(.*) \(.*\)$} $tv dummy typeName
            } else {
                set typeName "-unset-"
            }
            set typeName
        
---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: can't read "typeName": no such variable
    while executing
"set typeName"
    ("uplevel" body line 14)
    invoked from within
"uplevel 1 $script"
---- errorCode: TCL LOOKUP VARNAME typeName
==== filebox-3.5-0 FAILED


anonymous (claiming to be auriocus) added on 2016-10-12 06:38:59:
Because the file type is constructed as a string, not a list. It is not uncommon that the file types contain spaces; with the "simple" patch you proposed, the behaviour is:

% tk_getSaveFile -initialfile foo -typevariable seltype -filetypes {{{Text files} *.txt}}
/home/chris/Programmieren/foo.txt
% puts $seltype
Text

while, of course, it should return "Text files". It might also crash if the type contains a list metacharacter. 

A drop-in replacement, which not only fixes this bug, but also provides a modern appearance and comfort functions like creating new directories, is available from Schelte Bron at http://chiselapp.com/user/schelte/repository/fsdialog/index

fvogel added on 2016-09-24 22:16:18:
At first sight I fail to understand why the following simpler patch would not do the job:

Index: library/tkfbox.tcl
==================================================================
--- library/tkfbox.tcl
+++ library/tkfbox.tcl
@@ -1117,11 +1117,11 @@
            [info exists data(-typevariable)] && $data(-typevariable) ne ""
            && [info exists data(-filetypes)] && [llength $data(-filetypes)]
            && [info exists data(filterType)] && $data(filterType) ne ""
        } then {
            upvar #0 $data(-typevariable) typeVariable
-           set typeVariable [lindex $data(filterType) 0]
+           set typeVariable [lindex $data(filterType) 0 0]
        }
     }
     bind $data(okBtn) <Destroy> {}
     set Priv(selectFilePath) $selectFilePath
 }


Could you perhaps shed some light on this?

auriocus added on 2012-11-19 16:21:56:
See also bug 3588462

auriocus added on 2012-11-19 16:14:54:

File Added - 456735: ftypebug.patch

Attachments: