Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help with applescript studio table



Bastiaan, in his email below, has identified the key reason why Peter's original script was not working. But perhaps a few additional comments are worth making ...

1. data sources can be addressed directly from anywhere in any script within an AppleScript Studio application. This is a very good thing!

In relation to this script it means that in the "getContactInfo" handler there is no need for the "tell theWindow" and "end tell" lines. They are quite redundant, you can just cut them out, and you don't need to pass the variable theWindow. You just need to pass the two things: the reference to the data row and the data you want inserted into that data row.

A further minor consequence of data sources' global availability is that while you can, as has been done in this script, store the data source in a variable, you don't actually have to. I tend to simply address my data sources by name - just one less thing to keep track of - so, for instance, would say:
set theRow to make new data row at the end of the data rows of data source "contacts"
and
set data source of table view "contacts" of scroll view "contacts" of window "main" to data source "contacts"
This is purely a matter of preference.


2. I don't know how, Peter, you are constructing your application, but I just wonder whether the "on open" handler is the right one in which to create the data source and assign it to the table view. I think I am right in saying - and if I'm not, I am sure someone will correct me - that the "on open" handler gets called every time a window is opened whether for the first time when the application is run or after it has been closed while the application is running. If you want your data source to be created just once (which is probably how it's normally done), then the "awake from nib" handler would be the better one to put it in.

3. As a matter of course, I would use "content" not "contents", so would say:

	set content of data cell "Name" of theRow to item 2 of item 1 of myData

There is a note in the studio reference about the use of "content" and "contents". You will often get away with "contents" but "content" is generally safer.

Regards

Philip



On 7 Jul 2005, at 08:13, Bastiaan Boertien wrote:

Are you working in OS 10.4? Because 'window of theObject' does not work on my computer. So I named the window "main"
The other problem was that you define myData after you would like to fill in the table view.
myData will not go automaticly to the getContactInfo handler. I send myData as an argument to the handler but you can also make a property of myData just like contactsDataSource.
Also data source of table view "contacts" of scroll view "contacts" of window "main" is not there when you never made one. Well my OS is 10.3.9 and it returns a missing value. In the on will open handler I make a new data source.


well here's my solution

property contactsDataSource : missing value

on clicked theObject --button "Populate"
set theRow to make new data row at the end of the data rows of contactsDataSource
display dialog class of theRow
set myData to {{"item1", "item2", "item3", "item4", "item5", "item6", "item7"}, {"empty"}}
getContactInfo(window "main", theRow, myData)
end clicked


on will open theObject
set contactsDataSource to make new data source at end of data sources with properties {name:"contacts"}
tell contactsDataSource
make new data column at the end of the data columns with properties {name:"Name"}
make new data column at the end of the data columns with properties {name:"Page"}
make new data column at the end of the data columns with properties {name:"Bounds"}
make new data column at the end of the data columns with properties {name:"Scale"}
make new data column at the end of the data columns with properties {name:"Horizontal Scale"}
make new data column at the end of the data columns with properties {name:"Vertical Scale"}
make new data column at the end of the data columns with properties {name:"File Path"}
end tell
set data source of table view "contacts" of scroll view "contacts" of window "main" to contactsDataSource
end will open


on getContactInfo(theWindow, theRow, myData)
tell theWindow
set contents of data cell "Name" of theRow to item 2 of item 1 of myData
set contents of data cell "Page" of theRow to item 3 of item 1 of myData
set contents of data cell "Bounds" of theRow to item 7 of item 1 of myData
set contents of data cell "Scale" of theRow to item 6 of item 1 of myData
set contents of data cell "Horizontal Scale" of theRow to item 4 of item 1 of myData
set contents of data cell "Vertical Scale" of theRow to item 5 of item 1 of myData
set contents of data cell "File Path" of theRow to item 1 of item 1 of myData
end tell
end getContactInfo


Op 6-jul-05 om 16:52 heeft Pete Kincaid het volgende geschreven:

Hello, Im trying to import information into my table object. This is my
script. I know the names of the tableView, ScrollView are correct. But I
keep getting an error when ever I hit my populate button


property contactsDataSource : null
on clicked theObject --button "Populate"
set theRow to make new data row at the end of the data rows of
contactsDataSource
display dialog class of theRow
getContactInfo(window of theObject, theRow)
set myData to {{"item1", "item2", "item3", "item4", "item5", "item6",
"item7"}, {"empty"}}
end clicked
on will open theObject
set contactsDataSource to data source of table view "contacts" of scroll
view "contacts" of window of theObject
tell contactsDataSource
make new data column at the end of the data columns with properties
{name:"Name"}
make new data column at the end of the data columns with properties
{name:"Page"}
make new data column at the end of the data columns with properties
{name:"Bounds"}
make new data column at the end of the data columns with properties
{name:"Scale"}
make new data column at the end of the data columns with properties
{name:"Horizontal Scale"}
make new data column at the end of the data columns with properties
{name:"Vertical Scale"}
make new data column at the end of the data columns with properties
{name:"File Path"}
end tell
end will open
on getContactInfo(theWindow, theRow)
tell theWindow
set contents of data cell "Name" of theRow to item 2 of item 1 of
myData
set contents of data cell "Page" of theRow to item 3 of item 1 of
myData
set contents of data cell "Bounds" of theRow to item 7 of item 1 of
myData
set contents of data cell "Scale" of theRow to item 6 of item 1 of
myData
set contents of data cell "Horizontal Scale" of theRow to item 4 of
item 1 of myData
set contents of data cell "Vertical Scale" of theRow to item 5 of
item 1 of myData
set contents of data cell "File Path" of theRow to item 1 of item 1
of myData
end tell
end getContactInfo
-- Peter Kincaid
Data Conversion
Schawk, Inc.
(815)444-2338


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/ email@hidden


This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/ email@hidden


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-studio mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden
References: 
 >Need help with applescript studio table (From: Pete Kincaid <email@hidden>)
 >Re: Need help with applescript studio table (From: Bastiaan Boertien <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.