Version 10 of ttk::messageBox

Updated 2008-12-29 16:18:50 by oakley

Megabyte

tk_messageBox is very ugly within Linux. Ever since I saw it, I've been unhappy. Until I saw some good work that inspired me. Schelte Bron created a replacement that works great under Unix for the file selection dialogs, present at: [L1 ]. I was inspired by his work and created a brand new ttk::messageBox widget.

What does it do? Its syntax is exactly like a tk_messageBox command, but within Linux it'll draw something much prettier. It uses a subset of icons from the Tango project, which can be changed if you're not happy with them.

See ttk::messageBox in action

[L2 ] [L3 ]

Install it

Place these files in a directory listed by $auto_path, or use the command "lappend" to append the directory containing the files to auto_path

Download it

The files are available at: [L4 ]

Feedback is appreciated. Enjoy!


Bryan Oakley - the default behavior is not the same as a standard tk_messageBox. Compare the result of "tk_messageBox -message Foo" with "ttk::messageBox -message Foo". In your case you're using no icon when an info icon should be the default. You also neglect to add a default "OK" button as well, making it impossible to properly dismiss the dialog (since you fail to add a WM_DELETE_WINDOW protocol handler to cancel the vwait).

I'd also like to suggest a way to reduce the amount of code and (arguably, at least) make the code more readable and easier to maintain.

You have a lot of code that looks like the following, where you have a switch that sets a variable to the pattern that matched:

switch $parameter {
    ok {
        set default_button "ok" 
    } 
    cancel {
        set default_button "cancel"
    }
    .... 
    default {
        error [format $unrecognized_parameter "-default"]
    }
}

I suggest you replace that with something like the following, using the new "in" operator:

if {$parameter in {ok cancel ...}} {
    set default_button $parameter
else {
    error ...
}

In the case of the -default switch, that replaces 29 lines of code with 5, a hefty savings. A similar change can be made each time you are using a switch merely to assign the pattern to a variable.

Another comment: in the unix_messageBox_check_default_parameter function you are using "puts" to signal errors. You should be calling error (or better, return -code error) instead.

Your use of TkDefaultFont is incorrect. You do this:

font create ttk_message_dialog_Italic_font -family TkDefaultFont -slant italic

However, TkDefaultFont isn't the name of a font family. It is a named font. Using the expand operator and the knowledge that the font command uses the last option in the case of duplicates, you can do this instead (though I personally don't think it's a good idea to create a named font as a side effect of using this dialog)

font create ttk_message_dialog_Italic_font {*}[font actual TkDefaultFont] -slant italic

And a final comment: make sure you add a protocol handler for WM_DELETE_WINDOW


Changelog

12/28/2008

* Fixed a few bugs with the "-parent" option

* Fixed a few cleanup issues.

* Finished implementing the option "-default", which I forgot to do. "-default" focus on a requested button.