Tcl / Tk. Alternative file explorer for Linux and Android platforms

The longer I write various programs on tcl / tk , the more I admire its capabilities and thoughtfulness. But there was one thing that did not give me rest until recently. When developing a GUI, you often have to use the file explorer (tk_getSaveFile, tk_getOpenFile or tk_chooseDirectory). And if on Windows or OS X platforms, the native file explorer of these platforms is loaded, then on Linux platforms the explorer from tcl / tk is loaded (well, there is no native explorer in Linux):



What does not suit you in this explorer? This lack of elementary operations with folders / files in it - create, destroy, rename. No, don’t think in tcl itself all these mechanisms are, of course, implemented, they simply don’t exist in the Explorer GUI. But on Linux, this is not so noticeable. But on the Android platform, the conductor from Tcl / Tk causes a lot of inconvenience:



When we talk about the Android platform, we mean the development of applications on Androwish .

And then such times have come, self-isolation, etc. As a result, a balalaika was born (also called / packages for tcl) tkfe (tk file explorer).

When developing the tkfe package, we took into account not only that at least elementary operations with files / directories are necessary, but also the desire to have an explorer not only in a separate window, but also in a separate frame, which the user himself can place as he wishes in his GUI. The project has a comprehensive example of using the package. So, download the project, go to the ~ // TkFileExplorer / samples folder and run the example:

$wish tkfe_samplefull.tcl


Actually, the example clearly demonstrates all the features of the package. For example, run Explorer to select a folder in a separate window:



Explorer itself has an interface in two languages: Russian and English. Translation is carried out on the fly when you click the button with the flag:



In addition to the button with the flag, there is a button with tools (tools), when clicked, the context menu is displayed, what can be done in the current directory (create a directory / file) or with a selected file / folder ( delete / rename):



Any of the functions of the file explorer returns the name (underlining - NAME) of the variable (see the tkfe_samplefull.tcl example), into which the path to the selected file or directory will be written, or which will be empty if the choice is refused. After receiving the variable name, it remains to wait when any result is obtained, for example:

 . . .
#   
#   window -  ; frame -  
set typew "window"
#  
 set msk "*.txt *.doc *.crt * .*"
# 
set tekdir $env(HOME)
#  
 set vrr [FE::fe_getopenfile  $typew $w $tekdir $msk]
# 
 vwait $vrr
. . .

If you use the type of placement of the frame conductor, then you need to take care of its placement in your picture. Placement can be in any way (grid, pack or place). The preferred method is still the place method. You don’t have to worry about reformatting the image, since place, unlike grid and pack, allows you to overlay the frame on top of the existing image:



If you carefully look at the image, you will notice that the right screenshot differs from the left by the appearance of hidden folders on it (names begin from the point). To show hidden buttons, you must enable the button with an eye-shaped icon. Folders and files can also be sorted alphabetically, and files by size:



When the explorer is placed in the frame, you should also take care of blocking extraneous buttons (when the explorer is placed in the window, the tkfe balalaika takes care of this).

The tkfe package includes two functions that make widgets inaccessible (all_disable) or available (all_enable) within a given widget:

  proc all_disable {parent} {
    set widgets [info commands $parent*]
    foreach w $widgets {
	catch {$w configure -state disabled}
    }
  }
  proc all_enable {parent} {
    set widgets [info commands $parent*]
    foreach w $widgets {
	catch {$w configure -state normal}
    }
  }
  namespace export fe_getsavefile
  namespace export fe_getopenfile
  namespace export fe_choosedir
  namespace export all_enable
  namespace export all_disable

However, I prefer to use the tk busy features. This is clearly seen in the example:



This is a theory. In practice, the tkfe package was used in cryptographic workstation based on cryptoarmpkcs public key standards . Now the use of the file explorer in this application for the Linux platform looks like this:



But the explorer, located in the frame:



And, of course, it became very convenient to work with the explorer on the Android platform:



Someone may ask: What about Windows or OS X? Yes, everything is great. But as always on Windows - this is the problem of Russification, in our case it is the use of the Cyrillic alphabet in naming files and folders, as well as the use of a backslash. Therefore, the following lines must be added to the code:

#    
# MS Win    cp1251
set tekdir [encoding convertfrom cp1251 $tekdir ]
#       
set tekdir [string map {"\\" "/"} $tekdir]

This is what the tkfe explorer looks like on the Windows platform:



The package itself and examples of its use are here .

All Articles