I’m looking for a bash template that uses zenity or yad to maintain a list of records. The template could be a shopping check list with print option or it could be a list of servers to monitor ping time. In either case I’d like to take that code and adopt it to my needs.
Here is a sample dialog box mock-up:
The dialog box allows selecting a record and clicking the following buttons:
Insert before
(insert before selected record). A new input form is mounted to enter fields.Edit
(edit selected record). Mounts same form as "Insert before" except with existing values displayed.Delete
(delete selected record). Contents of existing record are displayed and confirmation is requested.Run
– runs a lengthy update process that updates status column with “MatcheOK / Different / Error”. User is prompted to run update on selected record or all records. Progress display bar displayed when all records are processed.Cancel ALL
– DO NOT save any changes and exit bash script. Pressing Escape or closing window by clickingX
performs same action. If any records have been changed, confirmation is requested.Save
– save changes to disk and exit bash script.
NOTE: It appears zenity only allows relabeling “OK” and “Cancel” buttons. New buttons cannot be defined in zenity. As such yad (Yet Another Dialog) which is installed by default in Ubuntu, and based on zenity, is the way to go. However zenity remains in the question because a script based on it can be easily converted to yad.
I’ve googled existing examples and these are the closest, but still far from satisfactory:
-
Using yad (Yet Another Dialog) a fork of Zenity for multiple buttons
-
Source Forge’s yad examples to Power Off / Reboot / Suspend / Logout
NOTE: I’m not looking for a complete solution but something close which can be adapted to this project. Although this project uses a flat text file an existing script that uses SQL, ISAM or RDMS could be adapted. The only imperative is it is written in bash and not python, perl or C, etc.
Can anyone point out an existing bash script that uses zenity (or yad) to insert/edit/delete records?
Best Answer
YAD (Yet Another Dialog) is the best method
YAD is a fork of Zenity and provides advanced controls over buttons, lists and GTK interfaces. For example when entering a file name in this answer YAD easily provides us the regular GUI system interface:
Sample main dialog window
The main window hides the record number column which you can reveal for debugging purposes:
Sample Insert / Edit window
The same window is used for inserting records before an existing record or editing an existing record:
Notice the "File name" field. When you enter it the file selection dialog box in the first section appears.
The bash code
Here is the bash code to make the sample YAD insert/edit/delete records template. Note extra coding is still needed to read in the file and add processing logic for the "Run" command. Additional coding is probably required to support file names with embedded spaces but that hasn't been tested yet.
Summary
Hopefully this saves others lots of time getting their own record management system going using
bash
andyad
. Of course more bullet proof and probably faster methods can be done using Python or C but that probably comes at the expense of more lines of code and higher learning curve.At the end of the day this project is targeted at those that want to learn more about bash and what can be accomplished in a bash-only environment.
Perhaps AskUbuntu is the wrong forum for posting this and Stack Overflow or Unix & Linux forums might be better Stack Exchange candidates. I look forward to comments on that as I'm really not sure the best place.
Of course I always look forward to general comments and constructive criticisms as well :)