FE 'tkGooie' Utilities'File Managers' group
tkScriptApplicator
|
This script-selector GUI appears after a file(s)-selector is used to select one or more filenames. This GUI is initially positioned at the directory that holds the 'feNautilusScripts' file hierarchy of scripts. |
FE Home Page >
FE Downloads Page >
FE 'tkGooies' DESCRIPTION Page >
FE 'tkGooies' 'FileManagers' Page >
This 'tkScriptApplicator' Description-and-CODE Page
INTRODUCTION to 'tkScriptApplicator' I have a set of about 450 'Nautilus' scripts that I find quite handy to use for computing activities in many categories. In fact, I have the scripts stored in directories whose names indicate the areas of functionality:
I use those Nautilus scripts via the Nautilus file manager that was available in the Gnome 2 Linux desktop environment. The general idea of 'Nautilus scripts' : 1) You use the Nautilus file manager to navigate to a directory (for example, a directory of image files). 2) Then you 'select-file(s)-and-apply-a-script-to-them'. Here is a little more detail on how it works.
Here is an example that shows what the 'Nautilus scripts' hierarchy of menus can look like --- after a 'right-click' on a filename --- in this case, in a directory named 'IMAGE_CAPTURE'. In this example, we are going to select a script in the 'TERMtools' toolchest of the 'feNautilusScripts' system. |
Click on this image to see this image
in a separate browser window or tab.
In this case, I right-clicked on a file in the Nautilus window and the Nautilus menu popped up with the 'Scripts >' option showing in the menu. By simply moving the mouse cursor over that 'Scripts' line, another menu in the cascade opens up showing names of Nautilus scripts and/or names of sub-directories containing Nautilus scripts. (In Gnome 2, Nautilus assumed that the hierarchy of scripts started at the directory $HOME/.gnome2/nautilus-scripts.) In my setup, subdirectory names like the ones listed above showed up. I moved the mouse cursor over the 'TERMtools' category (sub-directory name) and another menu in the cascade opened up --- showing the names of the several scripts in the 'TERMtools' category. At that point, I could have clicked on the name of one of the scripts. The script would have started up and the menu cascade would disappear. For example, I could have clicked on the script named 00_anyfile4Dir_ START-Gterminal-here_ gnome-terminal.sh That script, as the name suggests, does not use the filenames passed to it, other than to determine the directory name that contains the selected file. That directory name is used to start up a terminal window with a shell prompt that is positioned at that directory as the 'current working directory'. As the script-name suggests, the script starts up a 'Gterminal', using the 'gnome-terminal' command. THE RUB Here's the rub. Around 2010, the developers of the Gnome desktop environment came out with Gnome 3. They took a view of the desktop environment that essentially threw out what they considered a lot of bathwater --- but that bathwater included many babies. In trying to 'super-simplify' the user interface, the Gnome3 developers made it difficult to use the file manager efficiently. The Nautilus 2.28 file-manager that I was using suffered some major 'regressions'. Some of the handy features of the Nautilus right-click menu were deemed no longer worth supporting. For example, the 'Open With > Other Application ...' option of the menu no longer worked in releases of Nautilus soon after the 2.28.1 version. Not only Nautilus 3.x versions lacked formerly provided handy capabilities, but even some 2.x versions after 2.28.1 suffered 'regressions'. I became concerned about the loss of capabilities, especially the likelihood of loss of the 'Nautilus scripts' capability --- which was never even mentioned in press-releases, articles, reviews, etc. about Gnome 3. I was not the only one concerned about the abandonment of many 'productivity features'. Some Gnome 2 users in Argentina were so concerned that they forked the Gnome 2 desktop environment (with the Nautilus file manager that is central to that environment) to a new MATE (MAH-tay) desktop environment. They forked the Nautilus file manager to a file manager called 'Caja' (CAH-hah, Spanish for box). (The 'Caja' file manager looks for 'Nautilus scripts' starting at the directory $HOME/.config/caja/scripts.) Unfortunately, they forked Caja from a 2.x release that already included some regressions. At that point, I realized that I could no longer depend on either Gnome 3 developers or MATE developers to preserve the 'Nautilus scripts' capability. I realized that I could develop my own file(s)-selector --- along with a script-selector --- using Tcl-Tk to make the GUI's. In fact, around 2011, I created a system that I called 'feHappyScripts', as one of the subsystems of my Freedom Environment systems, available (for free) at www.freedomenv.com. I rushed that system out, because I wanted the comfort of knowing that I could devise (and use) a Tcl-Tk system that provides the 'Nautilus scripts' capability. That 'feHappyScripts' system is quite rough around the edges. It was basically a 'proof of concept' with a lot of unpolished code. Even though it was unpolished, I was pleased to see that the Tk GUI listboxes could be filled with filenames even faster than the Nautilus file manager could present the names. For example, for directories containing more than 1,500 files, the filenames came up in a fraction of a second, whereas Nautilus took more than 5 seconds to complete showing the names. This page is meant to provide a more polished implementation of a 'Nautilus scripts' capability --- using a few file-selector Tk scripts. For one thing, in my first pass at this, I used the 'ls -Ap' command to get the file lists with which to put directory names and 'regular' file names in the GUI's. This time around I eventually decided to use the Tcl 'glob' command. Furthermore, my first pass did not handle 'symbolic link' files --- for directories or for 'regular' files. This time around, I wanted to at least make an attempt to handle 'symbolic links' --- even 'broken' links. So here is a 'tkScriptApplicator' mini-system. THE GOALS My two main goals for the 'tkScriptApplicator' mini-system were to provide two main Tk GUI scripts:
In the process of developing the 'file(s)-selector' Tk script, I found that I needed one more Tk script:
This 'directory-selector' script was to also provide the option of editing a list of 'favorite directories'. The two main Tk GUI's of this utility (the 'file(s)-selector' and the 'script-selector') could be implemented in many different ways. For example, a SINGLE listbox could be used to hold both sub-directory names and filenames of a 'current directory'. But I decided to use a TWO-listbox layout --- ONE listbox for sub-directory names and ONE listbox for 'regular' filenames. I was influenced in this by a file-selector GUI that was used in a CAD/CAM/CAE system called 'I-DEAS' that was developed by SDRC (Structural Dynamics Research Corporation) of Milford, Ohio --- around 1990 to 2003. (SDRC and the I-DEAS software was eventually acquired by the company that developed the Unigraphics CAD/CAM/CAE software, around 2003 --- and Unigraphics was eventually acquired by Siemens, around 2008.) In both the 'file(s)-selector' GUI and the 'script-selector' GUI, the TWO listboxes are side-by-side:
and
I should point out here that I was not especially interested in coming up with a 'beautiful utility'. I just wanted a utility that would make sure that I had a 'Nautilus scripts' capability --- a capability that is not subject to the whims and regressions of the Gnome 3 developers. I am certainly interested in making pretty GUI's --- as my pages on and have indicated. But at this time, I am satisfied to implement the 'functionality', and let the 'beauty' go for a later date (when I have more beauty tools/code at hand). SCREENSHOTS OF THE GUI's On the basis of considerations mentioned above, I ended up with the several GUI's seen in the following several images. The 'file(s)-selector' GUI : |
The 'directory-selector' GUI --- which is called (optionally) by using the 'Jump2Dir' button on the 'file(s)-selector' GUI (above) :
The list of sub-directories shown in this 'directory-selector' GUI is contained in a text file named 'fave_dirs.lis'. The user can edit that file --- via the 'EditDirs' button on this GUI. The 'script-selector' GUI --- which is called by the 'Apply-a-Script' button on the 'file(s)-selector' GUI (above) : |
The 'script-selector' GUI image above shows the main 'category' directories of the FE 'feNautilusScripts' system --- which are available as a (free) package at www.freedomenv.com. However, the files-listbox in the 'script-selector' GUI is essentially empty, because the FE Nautilus scripts are in sub-directories of '$HOME/.gnome2/nautilus-scripts'. Here is an image captured after I clicked on the 'IMAGEtools' subdirectory of the 'feNautilusScripts' directory structure. |
The names of the many 'IMAGEtools' scripts of the 'feNautilusScripts' system are shown in the files-listbox to the right. And sub-directories (that contain even more 'IMAGEtools' scripts) are shown in the directories-listbox to the left. I use four-part script names that are described in a description of the 'feNautilusScripts' system on this FE (Freedom Environment) site. One very pleasing aspect of the Tcl-Tk implementation is its speed. When I navigated to the directory '/usr/lib' with the 'file(s)-selector' GUI, the list of over 2,500 files was displayed in a fraction of a second. "Blink and you miss it." |
It takes about 5 seconds for these '/usr/lib' files to be displayed in the Gnome2 Nautilus GUI file manager --- at least the first time the directory is accessed. (Nautilus shows the files faster in subsequent navigation to the directory in the same session.) I suppose Nautilus is slower than these Tcl-Tk scripts (in spite of Nautilus being a compiled program and the Tcl-Tk scripts being 'interpreted') because of overhead, such as showing, or trying to show, little image icons representing various types of directories and files. BASIC OPERATING SEQUENCE Here is a quick overview of the operation of the 3 GUI's above.
Other options (such as Rename, Delete, Copy, Move, Properties, etc.) could be added (eventually) to the 'file(s)-selector' GUI to make it a more full-featured file manager. But note that many functions that a user may want to perform can be implemented in Nautilus scripts. For example, a file-manager may be set up to play a '.mp4' file with the 'Totem' movie player when a user clicks on the '.mp4' file. Alternatively, a user could have a Totem-player Nautilus script, say in the 'VIDEOtools' subdirectory of 'feNautilusScripts'. The user could click on the '.mp4' file in the 'file(s)-selector' GUI of this 'tkScriptApplicator' mini-system and choose to run the Totem-player script. One advantage of this is that the script could supply (or prompt-for) special 'start-up' parameters to the movie player program. DESCRIPTION OF THE CODE Below, I provide the Tk script code for the three Tk GUI's of this 'tkScriptApplicator' mini-system --- along with a 'fave_dirs.lis' text file to be used by the 'directory-selector' Tk script. I follow my usual 'canonical' structure for Tk code for these 3 Tk scripts: |
0) Set general window & widget parms (win-name, win-position,
win-color-scheme, fonts-for-widgets, widget-geometry-parms,
text-array-for-labels-etc, win-size-control).
1a) Define ALL frames (and sub-frames, if any).
1b) Pack ALL frames and sub-frames.
2) Define & pack all widgets in the frames, frame by frame.
Within each frame, define ALL the widgets.
Then pack the widgets.
3) Define keyboard and mouse/touchpad/touch-sensitive-screen
action ('event') BINDINGS, if needed.
4) Define PROCS, if needed.
5) Additional GUI initialization (typically with one or more of
the procs), if needed.
This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations. This structure makes it easy for me to find code sections --- while generating and testing a Tk script, and when looking for code snippets to include in other scripts (code re-use). I call your attention to step-zero. One thing that I started doing in 2013 is use of a text-array for text in labels, buttons, and other widgets in the Tk GUI's that I author. This can make it easier for people to internationalize my scripts. I will be using a text-array like this in most of my Tk scripts in the future. (I have put some of the info/warning/error messages in the text-array --- but I have left some messages hard-coded in the procs. I may someday put all the messages in the text-array assignment section of the Tk scripts.) Experimenting with the GUI's As in all my Tk scripts that use the 'pack' geometry manager (which is all of my 100-plus Tk scripts, so far), I provide the four main 'pack' parameters --- '-side', '-anchor', '-fill', '-expand' --- on all of the 'pack' commands for the frames and widgets. That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window. I have never encountered a situation where I preferred to use the 'place' or 'grid' geometry managers of Tk, rather than the 'pack' geometry manager. I find the 'pack' geometry manager is more flexible in handling cases where I want to allow resizing the Tk GUI window. --- I think that I have used a pretty nice choice of the 'pack' parameters for the 'file(s)-selector', 'script-selector', and 'directory-selector' Tk scripts. The label and button widgets stay fixed in size and relative-location if the window is re-sized --- while the entry widgets expand/contract horizontally whenever the window is re-sized horizontally. And the listbox widgets expand/contract both vertically and horizontally when the window is resized in either direction. You can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want. Additional experimentation: You might want to change the fonts used for the various GUI widgets. For example, you could change '-weight' from 'normal' to 'bold' --- or change '-slant' from 'roman' to 'italic' --- or change the font sizes. Or change font families. In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing. I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding. And I have included the '-relief' parameter on the definitions of frames and widgets. Feel free to experiment with those 'appearance' parameters as well. If you find the gray palette of the three GUI's is not to your liking, you can change the value of the RGB parameter supplied to the 'tk_setPalette' command near the top of each of the 3 Tk scripts. Some features in the code There are plenty of comments in the code, to describe what most of the code-sections are doing. You can look at the top of the PROCS section of the code of any of the 3 Tk scripts to see a list of the procs used in each script, along with brief descriptions of how they are called and/or what they do. The main procs of the 'file(s)-selector' GUI are as follows. |
'fill_lists' - fills the 'dirs' and 'fils' listboxes based on
var DIRFILmask
'get_subdirs_inCURdir_inclLinks' - called by 'fill_lists' proc
'get_files_inCURdir_inclLinks' - called by 'fill_lists' proc
'get_selected_files' - uses selected relative-filename[s] to
set 'FULFILnames'
'navigate' - changes dir in 'DIRFILmask' entry field & runs
proc 'fill_list'
'jump2dir' - gets a new dir for dirfilmask; uses Tk script
'dirSelector_orEditListOfFavorites_1listbox.tk'
'selectANDapply_script' - gets a script and applies it to 'FULFILnames' ;
uses Tk script 'scriptSelector_2listboxes.tk'
'set_status_msg' - puts supplied msg into the Status msg frame
The following 6 procs are for the window/widget resizing buttons:
'dir_listbox_width_increase'
'dir_listbox_width_reduce'
'fil_listbox_width_increase'
'fil_listbox_width_reduce'
'tall_win'
'short_win'
'toggle_fontsize' - called by the 'TogFontSize' button
'toggle_ybars' - called by the '<-Ybars->' button
'popup_msgVarWithScroll' - used to show the $HELPtext var ; also used
to show user various popup messages for
info, warnings, errors, etc.
One thing worth noting is the use of the -selectmode parameter on the various listbox definitions in the 3 Tk scripts. In the 'file(s)-selector' script: We use '-selectmode single' on the 'dirs' listbox, but we use '-selectmode extended' in the 'fils' listbox --- because we want to allow the user to select multiple 'regular' files, but only one 'directory' file at a time. In the 'script-selector' script: We use '-selectmode single' on BOTH the 'dirs' listbox and the 'fils' listbox --- because we want to allow the user to select only one script at at time, AND only one 'directory' file at a time. In the 'directory-selector' script: There is only one listbox and we use '-selectmode single' because we want to allow the user to 'jump' to only one directory at a time. Another thing worth noting is the implementation of the
buttons on the 'file(s)-selector' and 'script-selector' GUI's. I find it frustrating to grab the edge of the window to resize it. It seems that the 'sensitive edge' is only about 1 pixel wide --- perhaps a hold-over from the days when a 640x480 monitor was big. By simply clicking on the 'naroDir', ... , 'shortWin' buttons, I can resize the listboxes (either width or height) with a minimum of frustration. If you prefer the vertical-scrollbar of the 'dirs' and 'fils' listboxes --- of the 'file(s)-selector' and 'script-selector' GUI's --- to be on the right rather than the left, you can click on the '<-Ybars->' button --- to toggle the 'y(vertical)-scroll-bars' right and left. Comments in the code It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this. Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch hours and hours of 'fractal animation' videos on YouTube --- until their minds turn to mush. Here is a link to CODE for the Tk script 'tkScriptApplicator_multifilesSelector_2listboxes.tk'. Here is a link to CODE for the Tk script 'scriptSelector_2listboxes.tk'. Here is a link to CODE for the Tk script 'dirSelector_orEditListOfFavoriteDirs_1listbox.tk'. Here is a link to a TEXT FILE of 'directory favorites' 'fave_dirs.lis'. INSTALLING THE SCRIPTS: The 3 Tk scripts and the 'lis' file could be put in a sub-directory of the user's home directory, such as $HOME/apps/tkScriptApplicator. Then the user can use their desktop system (such as Gnome or KDE) to set up the 'main' 'file(s)-selector' Tk script as an icon on the desktop. Then, whenever the user wants to apply some Nautilus scripts to one or more files, the user can click on the icon to startup the main script of the 'tkScriptApplicator' mini-system. In addition, a few variables may need to be set in the Tk scripts. In the 'file(s)-selector' Tk script, the statement set DIRFILmask "$env(HOME)/*" at the bottom of that script can be changed to have the file(s)-selector GUI start up positioned at a different directory from the user's home directory. In the 'script-selector' Tk script, the location of the 'Nautilus scripts' can be changed in a 'set DIRshellScripts' statement near the bottom of that script. In the 'directory-selector' Tk script, the text editor can be set in a 'set EDITORtext' statement near the bottom of that Tk script. Furthermore, the 'fave_dirs.lis' text file could be edited to start off with a set of 'favorite' directories suited to the user-installer. SOME POSSIBLE ENHANCEMENTS The copious amount of code here lends itself to many possible enhancements. Some examples :
CODE SNIPPETS NOTE that even if you do not ever implement these scripts, there may be some code here that would be of use. For example, the code that implements the 'fill_lists' procs is a big step forward from the similar code of the 'dirview' script in the Eric Johnson book "Graphical Applications with Tcl & Tk", first edition (1996), page 225-226, Chapter 6 'Lists, Files, and Directories'. The 'dirview.tcl' script in chapter 6 gives an example of using a 'foreach' loop to extract directories and non-directories from 'glob' output. But that code would have to be made more robust to handle 'symbolic links' properly --- and exclude special files like fifo, socket, and device files.
Another example: IN CONCLUSION As I have said on several of my code-donation pages on wiki.tcl.tk ... There's a lot to like about a utility that is 'free freedom' --- that is, no-cost and open-source so that you can modify/enhance/fix it without having to wait for someone else to do it for you (which may be never). A BIG THANK YOU to Ousterhout for starting Tcl-Tk, and a BIG THANK YOU to the Tcl-Tk developers and maintainers who have kept the simply MAH-velous 'wish' interpreter going. |
Bottom of To return to a previously visited web page location, click on the Back button of your web browser a sufficient number of times. OR, use the History-list option of your web browser. OR ...
< Go to Top of Page, above. >Page history: The code on this page was originally created in 2014 --- and was posted on 2014 Jul 29 at http://wiki.tcl.tk/40417.
This FE web page was created 2015 Jan 13.
NOTE: |