Documented but Unimplemented Features

I’ve come across some features documented in the Apple’s AS Studio Reference that don’t work! While it’s possible I’m doing something wrong (and I’d love to know if I am), it seems they just aren’t implemented in AS Studio.

I’m curious if they might be possible as calls to cocoa, and if so, how I would go about doing that.

Here are two features which are documented, but don’t work:

set background color of table view “MyTable” of scroll view “MyScroll” of window “main” to {65535, 0, 0}

set header view of table view “MyTable” of scroll view “MyScroll” of window “main” to true


Also, I’m seeking to programmatically set the font for a table view. AFAIK, this might be possible by using a ‘prototype cell’ and a cocoa call, but i have no idea how to accomplish this.

They are implemented. Try this script (it targets the demo app I referenced in another thread: [url=http://homepage.mac.com/jonn8/as/dist/update_ds.hqx]http://homepage.mac.com/jonn8/as/dist/update_ds.hqx[/url]):

set the_colors to {{65535, 0, 0}, {0, 65535, 0}, {0, 0, 65535}, {65535, 65535, 65535}}
set show_header to {false, true, false, true}
tell application "update ds"
	activate
	tell table view "MyTable" of scroll view "MyScroll" of window "main"
		repeat with i from 1 to count of the_colors
			set background color to item i of the_colors
			tell header view
				set visible to item i of show_header
			end tell
			update
			delay 1
		end repeat
	end tell
end tell

The two things to note is that you need to update the object to get the change to display correctly and that the header view is an object, not a boolean property. The header view has its own properties and I think visible is the one you are looking for.

Jon

As to setting the font, I’ve had nothing but trouble with this. Here’s some code that may get you going:

tell application "update ds"
	activate
	tell table view "MyTable" of scroll view "MyScroll" of window "main"
		set text color of data cell of table column 2 to {65535, 0, 0}
		try
			--this should work but it just causes all sorts of problems
			--set font of data cell of table column 2 to "Courier"
		end try
		update
		return properties of data cell of table column 2
	end tell
end tell

Jon

  • Background Color

that works, of course. the problem was that i had “Use Alternating Row Backround” checked in IB. unchecking it successfully allowed the script to set background color.

  • Header View

this basically doesn’t work, or at least not how i’d expect. setting “visible” of “header view” to false doesn’t make the header row disapper. it just produces a display glitch blank row.

i’m trying to programmatically control what the “Display Column Headers” checkbox in IB does. any other suggestions? does “header view” have any other properties besides “visible”? i can’t find any documentation.

  • Font

good things come to those who scour the AS Studio mailing list search engine.

i got it to work! i figured out something before Jon! (does little dance around the living room.) i’m contributing an answer rather than just asking questions! (does another little dance around the living room.)

replace:

set font of data cell of table column 2 to “Courier”

with:

set font of data cell of table column 2 to call method “fontWithName:size:” of class “NSFont” with parameters {“Courier-Bold”, 12}

  • And finally a question

any ideas of how to let my user specify a font or color using the font and color panels?

I’m not quite sure how to resurrect it once it’s gone, but this will remove the header row entirely:

tell application "update ds"
	activate
	tell table view "MyTable" of scroll view "MyScroll" of window "main"
		tell header view
			delete
		end tell
		update
	end tell
end tell

Jon

Yeah, I do need to be able to toggle the header row somehow.

a couple more notes on setting the font of table views.

  • no spaces permitted in the font name.

  • the word regular (non-bold, non-italic) gets omitted.

so if we’re working with Lucida Grande:

this gets you regular: {“LucidaGrande”, 10}
and this gets your bold: {“LucidaGrande-Bold”, 10}

Is there a way to change the font to only one row? I changed your code above to point to a data row but it didn’t work?

Thanks!

the short answer is no.

in table views, using this call method technique listed above, you can affect all kind of characteristics of columns, but not rows or cells.


the long answer is maybe.

there is apparantly some workaround for affecting individual table cells i saw on the Applescript Studio mailing list archives. i did not explore this workaround, because it is apparantly buggy, and causes huge amounts of slowdowns every time the table is updated in any way. (a user resizes the window, for example.)

but i did not try this technique myself, so i’m not sure how impractical it really is.

if you want to pursue, i found it here: (the mailing list archive is an amazing resourse, BTW)

http://search.lists.apple.com/applescript-studio

if you explore and manage to get it working, i’m sure i wouldn’t be the only one who’d be interested.