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
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
peterc The GNU GPL2 license is a killer and quite different to most Tcl widget and extension licensing. I'd suggest the BSD license unless you want to significantly restrict its use.
Megabyte - peterc, your prayers have been heard. I decided to change the license to ISC, which is "the new BSD". Enjoy.
Megabyte - 12/29/2008
Thanks for the suggestions, Brian. I've changed the code accordingly to match tk_messageBox's behavior and cleaned the code a bit.
Megabyte - 12/30/2008
I noticed this piece of cleanup code on bind:
#A cleanup, just in case. bind $window_name <Destroy> { foreach name [image names] { if {![image inuse $name]} { image delete $name } } }
Was causing the file opening dialog to behave unpredictably when it was running, so I deleted it from the code. Would anyone explain me why does this happen?
Megabyte - 12/31/2008
Answer for the last question: unfortunately, not every dialog cleans itself after quitting, so I have to remove the images I create on my own.
12/28/2008
12/29/2008
12/30/2008
12/31/2008
1/09/2009
1/31/2009
2/2/2009