Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Preferences item in Apple menu (Mac OS X/ActiveTcl)

25 views
Skip to first unread message

Synic

unread,
Jul 11, 2007, 6:21:41 AM7/11/07
to
Hi all.

Using the following on Mac OS X 10.4.10/ActiveTcl 8.4.14.0.272572:

menu .menubar
catch { destroy .menubar.apple }
.menubar add cascade -label "Apple" -menu .menubar.apple
menu .menubar.apple -type menubar -tearoff 0
.menubar.apple add command -label "About Blah" -command showAbout
.menubar.apple add command -label "Preferences..." -command EditPrefs \
-accelerator "Meta-,"
. configure -menu .menubar

The About menu item appears correctly and is active. The 'Preferences...'
menu item I've set also appears correctly and works. However, it doesn't
replace the disabled default 'Preferences...' item, which appears in
the next menu item below.

Any suggestions?

Kevin Walzer

unread,
Jul 11, 2007, 9:25:44 AM7/11/07
to

Do something like this:

#call preferences with keybinding
proc ::tk::mac::ShowPreferences {} {
EditPrefs
}

Tk-Aqua since 8.4.14 hard-codes the "preferences" item in the Apple
menu, and the only way to access it is with the
::tk::mac::ShowPreferences command. This is undocumented and it took me
some time to figure it out. Inserting your own "preferences" command in
the Apple menu results in two Preferences items being shown, as you've
discovered.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

Daniel A. Steffen

unread,
Jul 11, 2007, 9:37:44 AM7/11/07
to
On Jul 11, 8:21 pm, Synic <flavp+hfr...@nhgbaf.arg.nh> wrote:
> The About menu item appears correctly and is active. The 'Preferences...'
> menu item I've set also appears correctly and works. However, it doesn't
> replace the disabled default 'Preferences...' item, which appears in
> the next menu item below.
>
> Any suggestions?

do not add your own Preferences menu item, use the system provided
one, it causes the [::tk::mac::ShowPreferences] proc to be called (if
it exists), c.f. tk/macosx/tkMacOSXHLEvents.c;
i.e. the following would replace your [ .menubar.apple add command -
label "Preferences..." ]:


proc ::tk::mac::ShowPreferences {} {EditPrefs}

The reason things work this way is that the sytem preferences menu
item sends a 'pref' apple event (receipt of which causes the tk::mac
proc to be called), but that apple event can also be generated by
other means, e.g. an external source such as an applescript or another
app...

Cheers,

Daniel

Synic

unread,
Jul 11, 2007, 2:43:12 PM7/11/07
to
Kevin Walzer and "Daniel A. Steffen" wrote with info on the currently
undocumented ::tk::mac::ShowPreferences command.

Thanks guys, that's worked for me. It definitely needs to be documented
in the Tk Menu manual page. (I've added the lack of documentation on
this as a bug in Tk at http://sourceforge.net/bugs/?group_id=12997)

Daniel A. Steffen

unread,
Jul 12, 2007, 2:00:17 PM7/12/07
to
On Jul 12, 4:43 am, Synic <flavp+hfr...@nhgbaf.arg.nh> wrote:
> It definitely needs to be documented
> in the Tk Menu manual page. (I've added the lack of documentation on
> this as a bug in Tk at http://sourceforge.net/bugs/?group_id=12997)

I've posted the following reply there:

as explained on c.l.t this has absolutely nothing to do with menus,
[::tk::mac::ShowPreferences] is an apple event handler for the 'prefs'
event (that could be replaced with your own handler using e.g. tclAE),
it has been present in tkMacOSXHLEvents.c from the start (i.e. since
the intial TkAqua port committed 2001-10-15), c.f
http://rutherglen.ics.mq.edu.au/fisheye/browse/Tk/tk/macosx/tkMacOSXHLEvents.c?r=1.1.2.1
nothing new in 8.4.14 about it...

I agree that core documentation is missing about MacOSX specific
features like this (nothing new about this either, such docs have been
missing since the Tk Mac Classic days), some docs are available on the
wiki:
http://wiki.tcl.tk/12987
please feel free to contribute to this, or even better have a go at
reformatting it in nroff format and submit it for inclusion in the tk
manpages in some form...

there is essentialy only one core maintainer working on TkAqua ATM
(me) and doc updates are very low on the todo list, sorry. However
this is one area where anybody can help out, no C coding experience
necessary...

Cheers,

Daniel

Synic

unread,
Jul 13, 2007, 4:38:50 AM7/13/07
to
Daniel A. Steffen <daniel....@gmail.com> wrote:
> On Jul 12, 4:43 am, Synic <flavp+hfr...@nhgbaf.arg.nh> wrote:
>> It definitely needs to be documented
>> in the Tk Menu manual page. (I've added the lack of documentation on
>> this as a bug in Tk at http://sourceforge.net/bugs/?group_id=12997)
>
> I've posted the following reply there:
>
> as explained on c.l.t this has absolutely nothing to do with menus,

Yep. True. However, a note on this behaviour should be added to
http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm#M22 to go along with the
mention of the various platform specific special menus. That's all
I'm really asking for here.

While ::tk::mac::ShowPreferences code has nothing to do with the code
for Tk menus, it's a solid bet that everyone looking to add a
Preferences entry in their OSX app will be looking at the Tk menu docs
and the OS specific stuff there first.

If you want some text, you could always use the following (with
apologies to those in this thread whose words I'm stealing) as
an addition to the content on Apple specifics already there:

Tk on Aqua hard-codes the "preferences" item in the Apple
menu, and the only way to access it is outside the menu command
using ::tk::mac::ShowPreferences. For example:

# Sets Preferences command with keybinding
proc ::tk::mac::ShowPreferences {} { YourPrefsCommand }

The sytem preferences menu item sends a 'pref' apple event (receipt

of which causes the tk::mac proc to be called), but that apple event

can also be generated by other means, such as an applescript or
through another app.

> there is essentialy only one core maintainer working on TkAqua ATM
> (me) and doc updates are very low on the todo list, sorry. However
> this is one area where anybody can help out, no C coding experience
> necessary...

Don't worry, I'm not expecting it to appear right away ;-). Just so
long as it's on a triage list somewhere. The Google Groups archive
of this thread is probably enough in the meantime (even with its
recent UI nosedive).

0 new messages