Tk Source Code

View Ticket
Ticket UUID: 1477426
Title: TIP #324: standard font selection dialog
Type: Patch Version: TIP Implementation
Submitter: ghanke Created on: 2006-04-27 05:55:15
Subsystem: 33. Generic Dialog Support Assigned To: das
Priority: 7 High Severity:
Status: Closed Last Modified: 2010-01-05 20:48:41
Resolution: Fixed Closed By: patthoyts
    Closed on: 2010-01-05 13:48:41
This patch implements a new standard dialog box as a
new command: tk_chooseFont

There is a Tk-only implementation and a Win32
implementation. The Mac implementation is missing :-(

The Win32 implementation uses the Win32 API function

Input parameters: none at this time

Output parameters: Font description as a list "family
size ?style...?"

style is bold, italic

The label description of the generic Tk implementation
 is currently in German but stored in a array inside

The Win32 implementation is build with the Borland Free
Command Line Tools

Greetings from Leipzig
User Comments: patthoyts added on 2010-01-05 20:48:41:

allow_comments - 1

patthoyts added on 2010-01-05 20:48:40:
The scripted font dialog does close when the parent is destroyed on linux. The other issues can be raised as bugs at some point if they annoy people. Its just hidden in here.

dkf added on 2009-04-05 14:38:15:

IP - Comment Removed:

dkf added on 2009-04-05 14:37:42:

IP - Comment Removed:

dkf added on 2008-12-18 04:50:20:
Dropping prio; not a release-blocker now

das added on 2008-12-10 12:13:58:
leaving open as a reminder to fix a number of small issues with the pure-tcl implementation:
- [tk choosefont configure] option changes ineffective once dialog has been shown (except for -font)
- [tk choosefont configure] option querying fails with 'value for "-xxx" missing'
- font dialog does not close when parent window is destroyed

das added on 2008-12-10 12:05:02:

File Deleted - 303633: 

File Added - 304765: tip324-081210.diff

committed attached updated patch to HEAD

adds docs & demos and other minor changes (file renaming for consistency, deal with parent window destruction in macosx code) and removes [tk] conversion to ensemble (committed separately)
c.f. github for details
File Added: tip324-081210.diff

das added on 2008-12-02 02:03:19:

File Deleted - 303378: 

File Added - 303633: tip324-081201.diff

TIP now updated to match this implementation

updated patch with minor changes attached, c.f. github for details

File Added: tip324-081201.diff

das added on 2008-11-29 06:08:01:

File Deleted - 303377: 

File Added - 303378: tip324-081129.diff

File Added: tip324-081129.diff

das added on 2008-11-29 06:06:58:

File Deleted - 303352: 

File Added - 303377: tip324-081129.diff

updated to apply cleanly to HEAD
File Added: tip324-081129.diff

das added on 2008-11-29 01:09:44:
ack, obviously meant to say:
'that I have _not_ been able to test'

das added on 2008-11-29 01:08:52:
note that the tip324-081128 patch makes minor changes to the windows code that I have been able to test, so somebody needs to verify that the patch still builds & works correctly on windows.

das added on 2008-11-29 00:51:56:

File Added - 303352: tip324-081128.diff

attached updated patch that:
- integrates Adrian Robert's changes posted to tcl-core recently (with a rewrite of the TkMacOSXProcessFontEvent() changes that has some additional fixes)
- adds a virtual event sent when the chosen font changes (i.e. when the -cmd callback is called), 
- turns [tk] into an ensemble
- renames [tk::choosefont] to [tk fontchooser] (and similarly for all related symbols)

for full history, see
note that patch needs to be applied with -p1

TIP update to match this patch will follow shortly

File Added: tip324-081128.diff

dkf added on 2008-09-04 14:56:40:
Logged In: YES 
Originator: NO

You access the pure Tcl version using [tk_chooseFont] (or whatever the TIP says) on the correct platform. The manner in which the dialog is implemented (C code, Tcl script, whatever) is not defined in the spec: RTFS if you want to know. :-p

wordtech added on 2008-09-03 21:37:21:
Logged In: YES 
Originator: NO

I tested the OS X version with DAS's patch against the documentation outlined at

tk::choosefont configure -parent: returns "."--not sure this is relevant on the Mac because it's a native system dialog.
tk::choosefont configure -title: Title is hard-coded in dialog. 
tk::choosefont configure -font: Running this command in the console changed the selected font in the system dialog to the font specified by "configure", but the console display did not reflect the new font until I clicked on the font dialog. Not sure if this is a problem or not, but I wanted to document the behavior.
tk::choosefont configure -visible: works as expected.
tk::choosefont hide and tk::choosefont show: works as expected.

tk::choosefont configure -command: This is unclear to me: do individual developers need to worry about this or is it handled by the dialog? I'm wondering because this seems to be where a developer would add an additional command binding, i.e. writing the chosen font to a preferences file, etc. Further explanation of this would be helpful. 

Also, how does one access the pure-Tcl/script version of this dialog? That's not clear from the documentation.

das added on 2008-06-19 07:26:41:

File Added - 281800: tk_tip213-080619.diff

Logged In: YES 
Originator: NO

updated patch attached with aqua implementation added.
File Added: tk_tip213-080619.diff

patthoyts added on 2008-06-02 01:46:58:

File Deleted - 277430:

patthoyts added on 2008-06-02 01:46:57:

File Added - 279791: tk_chooseFont-20080516.patch

Logged In: YES 
Originator: NO

Updated the patch once more. This now implements introspection of the configuration options and adds a read-only -visible option which is needed for platforms using a non-modal dialog. I have also added a virtual <<TkChoosefontVisibility>> event that is sent to the parent window when the visibility of the dialog changes.
Implementations in pure-tcl and native for Windows.
File Added: tk_chooseFont-20080516.patch

patthoyts added on 2008-05-11 06:53:22:
Logged In: YES 
Originator: NO

New patch that implements both the script and Win32 versions as a tk::choosefont ensemble with configure, show and hide sub-commands. This has an example Font menu on the console which works fine in windows and should work as expected on MacOSX too (where Cmd-T should toggle the visibility of the dialog).
The API changes are in response to tcl-core input from the MacOSX people.
File Added: tk_chooseFont-20080511.patch

patthoyts added on 2008-05-11 06:53:21:

File Added - 277430: tk_chooseFont-20080511.patch

patthoyts added on 2008-04-18 17:44:24:

File Added - 275040: tk_chooseFont-20080418.patch

Logged In: YES 
Originator: NO

Another patch update. This has more tests and now uses Keith Vetter's script implementation with suitable updates for scripting and key navigation.
File Added: tk_chooseFont-20080418.patch

patthoyts added on 2008-04-15 07:19:39:

File Added - 274563: tk_chooseFont-20080415.patch

Logged In: YES 
Originator: NO

Updated the TIP and the sample implementation to permit MacOSX style usage. The script implementation is my ttk version of dkf's dialog but Keith Vetter has provided another that closely follows the Windows font chooser that possibly the unix people may prefer.
File Added: tk_chooseFont-20080415.patch

patthoyts added on 2008-04-03 06:28:43:

File Added - 272972: tk_chooseFont-20080403.patch

Logged In: YES 
Originator: NO

Added some tests and fixed a couple of bugs that appeared.
File Added: tk_chooseFont-20080403.patch

patthoyts added on 2008-04-02 21:48:25:

File Added - 272897: tk_chooseFont.patch

Logged In: YES 
Originator: NO

I've added a patch against 8.6 that merges the tkchat choosefont code for windows into a tk_chooseFont command. For platforms that don't implement a C tk_chooseFont tk.tcl will call to tk::choosefont::choosefont which is a rewrite of dkf's fontSel dialog code but using ttk widgets. This is in library/fontdlg.tcl

The interface to tk_chooseFont is close to that in the tip except for using -apply instead of -updatefont as all the currently extant implementations that I know of are using -apply.
A Mac implementation is welcome but I'll not be doing it.
File Added: tk_chooseFont.patch

patthoyts added on 2006-11-30 22:20:31:
Logged In: YES 
Originator: NO

I think that how mac users expect to see this work is pretty much irrelevant. At the moment they don't get anything and neither do windows and X users. We can arrange to have something done correctly for win32 and something nice for X users and leave the Mac people with something that at least lets them choose a font using a dialog. Once  some enterprising mac person sorts out how to do it for that platform then great.
In the meantime I have a couple of critcl units that provide a Win32 and a Gtk standard font dialog and the package degrades to use DKFs tcl font dialog. Currently this stuff is in the tkchat application.

dkf added on 2006-04-27 15:38:28:
Logged In: YES 

The key problem with doing this sort of thing is that Win
users expect font dialogs to behave one way (modal, with OK
button, etc.) and Mac users expect font dialogs to behave
another (non-modal, with main menu item to show/hide the

Resolving these differences is tricky. :-(

(TIP#213 is related, so classifying as
a TIP impl...)

ghanke added on 2006-04-27 12:56:58:

File Added - 175930: