This tutorial constructs a more complex dialog, that acts as a graphical user interface to the tar command line program.
When using the tar program, there is always a main choice. This choice might be to extract, to append to, to create or perhaps list the contents of an archive. The user must select one of these choices and to allow them to do this we're going to setup some radio buttons inside a button group box.
Create a new dialog by going to File -> New and selecting the form type 'Dialog'. A new dialog should appear in the Editor main window. Start by selecting the Button Group widget from the Kommander toolbar
The next step is to actually insert our buttons. Double click the radio button widget in the Kommander toolbar
Append to archive
Create archive
Find differences between archive and file system
Delete from archive
Append to the end of an archive
List contents
Update archive
Extract from archive
Don't be surprised if the text label you set for each widget doesn't show up, it's just because the borders of the widget are cutting it off. Click in some empty space of the button group that the radio buttons are in so that the only widget selected is the Button Group itself. In the Layout toolbar, click the 'Lay Out Horizontally' button; all of the widgets are automatically aligned for us. You may need to resize the dialog and/or the button group to see the effect. What you have so far should look something like the screenshot below. Make sure that all of the radio buttons are in the order presented in the screenshot because we make this assumption for the rest of the tutorial. If you find they they're not, simply click the layout you want to redo and then click the Break Layout button from the Layout toolbar
Next we need to set up our text associations for the widgets we have created so far, including the buttons and group box. The widget text of the group box is the evaluated text associations of all of its chlidren, together in the order the widgets were created. The fact that only one widget will ever be selected in our Button Group means the widget text of the Button Group will be the text association of the selected radio button. This is exactly what we want in this case, as it means the text association of the ButtonGroup will effectively be the portion of the the command line to tar that determines the type of action to be taken. We'll see how this works together in '3. Putting it together'.
First set the name property of the ButtonGroup to be 'mainChoice', which you do by setting the value for the name property in the Property Editor window. Next, right click on the ButtonGroup and select the menu option 'Edit Text Associations'; the text association editor dialog pops up. Click the 'Widget Text' button in the Insert frame to the right of the text edit. This inserts the special '@widgetText' and saves us typing it manually. Click OK - text associations are setup for the Button Group.
Now for the text associations of the buttons themselves. We haven't yet configured text associations for widgets with more than one state. A radio button has two states in Kommander - 'checked' and 'unchecked'. If a radio button is unchecked in our dialog, we want its text association to evaluate to nothing so that it does not have an effect in the overall text generation, so we leave all text associations for state 'unchecked' blank. When setting text associations, you select the state by selecting an item from the 'States' combo box at the top of the text associations editor dialog.
Set the text associations for state 'checked' for each of our radio buttons, in the order we created them, to these strings(without quotes).
A
c
d
-delete
r
t
u
X
You would be correct if you recognised these as command line options to the tar program. Below is a screenshot showing the editing of the text association for the first widget. Notice the 'States' combo box is set to state checked, which is the state we want to associate our command line option with. You should have set this combo box to state checked when we set our text associations.
We don't need to set the names of the radio buttons, as we never reference them directly and only access their text associations through the ButtonGroup widget.
Options for tar change the way the primary choice behaves, and are in the form of additional command line options to the tar program. The option to tar can be broken into two groups - read and write. You might guess correctly that we will use a GroupBox widget widgets buttons as the GUI elements that represent these options.
Start by creating a ButtonGroup widget - click the ButtonGroup widget in the Kommander toolbar
We now need to use some buttons to represent the different command line options to the tar program. For example, if the user wants to extract with absolute file names and keep existing files, the -P and -k options must be passed to tar respectively. Notice in this last sentence that we talked about multiple selections; the user needs to able to select any number of the available buttons unlike when we setup the Main Choice ButtonGroup in the previous section, we only gave the user one choice in the form of radio buttons where only a single radio button can be selected inside the ButtonGroup. In this case, we use CheckBox buttons so that the user can select multiple options to suit their needs.
Double click the CheckBox widget in the Kommander toolbar
Ignore failed read
Keep existing files
Extract all protection information
Absolute path names
Click in some empty space inside the ButtonGroup you inserted the CheckBox widgets into, and then click the “Layout Vertically” in the Layout toolbar. The widgets should be aligned vertically inside the ButtonGroup, and what you have so far should look like the screenshot below.
Make sure that the order of your CheckBox widgets inside the ButtonGroup matches the order in the screenshot, as we assume this for the rest of the tutorial. If they are not, simply click inside some empty space inside the GroupBox. Click the 'Break Layout' button
The last thing we need to do for the Read options ButtonGroup is setup our text associations. Right click on the ButtonGroup and select the menu option "Edit Text Associations'. Click the 'Widget Text' button, which inserts the '@widgetText' special into the association. Click OK. For each check box of the four check box widgets inside the group box, edit their text associations, select the state 'checked' from the States combo box, and set the text association to the following(without quotes) -
--ignore-failed-read
-k
-p
-P
These are the corresponding command line options of the widgets to the tar program that control the way tar reads its input.
Setting up the write options of the tar program is much the same as the read options, so rather than repeat previous material we outline briefly what needs to be done, and explain more indepth only the abberations from the previous section.
Insert a ButtonGroup preferably to the right of the previous ButtonGroup and under the 'Main Choice' GroupBox, and set its title property to 'Write options' and its name property to 'writeOptions'. Insert four check boxes inside it, and set each of their labels to the following (without quotes) -
Dump files, not just symlinks
Remove files after adding to archive
Verbosely list files proceeded
Compression
For the last option “Compression”, there are actually two types of options - “bzip” and “gzip”. To represent these two sub-options, we are going to have another ButtonGroup with two radiobuttons which acts as a sub-option selector for the compression type.
Start by creating a ButtonGroup widget inside the “Write options” ButtonGroup. You don't need to set its title property to anything, as later we will make the frame of the widget unvisible. However, still sets its name property to be 'compressionType'.
Seeing as the RadioButtons inside the ButtonGroup are going to be sub-options of the “Compression” CheckBox, it makes visual and representational sense for the RadioButtons to be tabbed on the left slightly which we will take care of now. Inside the newly created ButtonGroup insert two RadioButtons, one below the other. Set the first RadioButton's label to “bzip” and the second RadioButton's label to “gzip”. Click the first RadioButton, then hold shift and click the second RadioButton and then click 'Layout Vertically' from the Layout toolbar
The two sub-option RadioButtons are now tabbed, but it still doesn't look quite right. The layouts we made infact have spacing between other widgets, and between other layouts. To alter this, first select the Layout aligning the two RadioButtons vertically. Sucessfully selecting the two RadioButtons looks something like the image below.
While the layout is selected, set the 'layoutSpacing' and 'layoutMargin' properties both to 0. Now select the 'compressionType' ButtonGroup by clicking in some of its empty space, and then set the same properties both to 0. This brings the two RadioButtons closer to the 'Compression' CheckBox, so that they look like a part of it rather than separate. Align all of the buttons by clicking in the 'Write options' ButtonGroup so that it is the only widget selected and then clicking the 'Layout Vertically' Button [IMAGE layoutvertically.png]. Finally, we said we wanted to 'compressionType' ButtonGroup to not have a frame so that it simply looks like the RadioButtons are tabbed inside the “Compression” CheckBox. To do this, select the 'compressionType' ButtonGroup and in the Property Editor window, set the 'lineWidth' property to 0 which doesn't draw the line at all. The result should look something similar to the following -
We are almost finished setting up the “Write options” ButtonGroup, but we have yet to setup text associations. For the CheckBox widgets, set their text associations for state “checked” to the following(without quotes) -
--de-reference
--remove-files
-v
@compressionType
Notice for the 4th CheckBox which is “Compression”, its text association is the ButtonGroup that contains the RadioButtons. In other words, the “Compression” CheckBox's text association will end being the association of the checked RadioButton.
Finally, set the text association for state “checked” of the “bzip” RadioButton to be “-j” and the “gzip” RadioButton to “-z”. These text associations are the command line options to the tar program that specify compression type, one of which will be the text association for the “Compression” CheckBox.
There are two other things that the tar program needs to know; the output archive name and the files you wish to work with, which might be a file/folder name or perhaps even a regular expression.
For the first case, a FileSelector widget that allows the user to select a file to save to will be ideal. First insert a Text Label widget
The second case is even simpler as a LineEdit will be sufficient for getting the files to work with. Again insert a text label, but this time set its text label to (without quotes) “Files”. Then, click the LineEdit widget in the Kommander toolbar
We have added most of the widgets we need, except for the all important ExecButton and the CloseButton. In this section we will see how the ExecButton references the other widgets in the dialog and therefore initiates the evaluations of text associations. In the text association tree, the ExecButton is the first to evaluate its text association and can therefore be considered as the root node for those familiar with the tree data structure.
Insert a Spacer, followed by an ExecButton, followed by another Spacer, followed by a CloseButton concluded by another Spacer. These should all be horizontal to eachother and below all other widgets in the dialog, although the former is optional as long as you select the widgets in the same order when you align them in the next section.
Set the text association for ExecButton for state “default” to be the following string (without quotes):
“tar @mainChoice @readOptions @writeOptions -f @outputName @files”
Here we see that the text association for the ExecButton is made up of the text associations of all the other widgets in the dialog, and because of the order we've specified them in the association, the text association will be expanded into a valid command line to the tar program. The ExecButton executes this text and the tar program is run with the options the user selected. All that is left is the final superficial touches. What you should have so far is something like the image below.
The functionality of the dialog is complete. The only thing left to do is layout the widgets we've created.
We will work from bottom to top. Start by selecting the Spacer, the ExecButon, the second Spacer, the CloseButton, and the last Spacer. Do this by clicking the first Spacer, then Shift+Clicking the other widgets. From the Layout toolbar, select “Layout Horizontally”
Next, click the “Files” text label widget, and then Shift+Click the corresponding LineEdit below it. Click the 'Layout Vertically' button from the Layout toolbar
The next thing we need to align is the two options ButtonGroups side by side. Click the “Read options” ButtonGroup, and then Shift+Click the “Write options” ButtonGroup. Click the “Layout Horizontally” button in the Layout toolbar
Finally, click in some empty space of the dialog so that no other widgets are selected. Make sure that all of your widgets are roughly in their correct position vertically, then click the “Layout Vertically” button in the Layout toolbar