TIG question

Hi,

So I created a script that tries to test what font type and size is used in certain areas of software where I need to find this information out. This little script seems to work fine when looking for longer words like technology but it seems to have problems with shorter words like ULC which isn’t even on the screen but repeatedly is found with most fonts and font sizes.

Here is the code

set fonts to (“Microsoft Sans Serif”, “Verdana”,“Arial Black”,“Arial”,“Courier New”,“Tahoma”,“Comic Sans MS”,“Impact”,“Trebuchet MS”,“Georgia”,“Times New Roman”, “Helvetica”, “Impact”)
set cnt to 1
set size to (8,8.25,8.5,8.75,9,9.25,9.5,9.75,10)
repeat with each item of fonts
repeat with each item of size
If ImageFound((Text:“ULC”, TextPlatform: “AboutBox”, TextSize: it, TextStyle:“Default”,TextFont: item cnt of fonts)) then
log “found”
log it
log item cnt of fonts
log FoundImageLocation()
else
log “not found”
log item cnt of fonts
end if
end repeat

set cnt to cnt + 1

end repeat

Any thing I could change to make it more accurate? The background and textcolor is set properly. Not sure why the shorter words are found but not even on the page. Also each font type finds the shorter words in different areas. From what I have read in the forums TIG works better for shorter words then longer words but that is not what I am seeing.

I am using TIG 1.02.

Hi Jeff–

For shorter strings, you want to want to reduce the tolerance some (ie make the search more precise). The Tolerance value tells Eggplant how many pixels are allowed to be different. In the case of the shorter string, the number of pixels allowed to be different makes the probable image match too generic, so you’ll see all those false positives.

You’ll probably need to tweak this a little, but you could say something like:

ImageFound((Text:"ULC", TextPlatform: "AboutBox", TextSize: it, TextStyle:"Default",TextFont: item cnt of fonts, Tolerance:50))

You probably won’t want to go lower than about 40 or 45, then you begin to run the risk of false negatives.

Hope this helps!

Ok that worked good for me. I am actually using tolerance: 30 at the moment and from my tests seems to be accurate. I will have to investigate a bit more still but that fixes the issue. Now I have another little problem. Here is the code snippet. Basically the code just loads a file with a text string and then looks for the text image.

set the CurrentTextPlatForm to “SMARTAboutBox”

	set the DefaultTextStyle to "Title"
	"Validate".Test("About SMART Notebook appears", (Text:"Table".Get(("SMARTAboutBox-Title", "Title")), Tolerance: 30)) 

When I run it I get the results below. I am confused because the textFont is stored in the DefaultTextStyle that I just set. So shouldn’t it use that font.

Wed, 25/03/09 1:03:55 PM set CURRENTTEXTPLATFORM = SMARTAboutBox
Wed, 25/03/09 1:03:55 PM set DEFAULTTEXTSTYLE = Title
Wed, 25/03/09 1:03:55 PM Exception Unable to get TextImage. No TextFont specified
Wed, 25/03/09 1:03:55 PM logerror About SMART Notebook appears
Wed, 25/03/09 1:03:55 PM logerror Failed

If you had just previously created that TextStyle in the Text Preferences you might just try going back and make sure your new platform got saved. We’ve had at least one report that someone had their style not be remembered. We’ve never been able to duplicate that problem however.

If you try it again and still have problems please let us know.

So the new textplatform and text styles under it have been saved. I even shutdown eggplant and relaunched to verify this. I can easily get around this by stating the textfont but would like to avoid this to simplify the code.

So i ran the below lines.

set the CurrentTextPlatform to “SMARTAboutBox”
set the DefaultTextStyle to “Title”
log getOptions(CurrentTextPlatform,DefaultTextStyle)

The log then says

Wed, 25/03/09 2:25:15 PM set CURRENTTEXTPLATFORM = SMARTAboutBox
Wed, 25/03/09 2:25:15 PM set DEFAULTTEXTSTYLE = Title
Wed, 25/03/09 2:25:15 PM log (CurrentTextPlatform:(AsTextFormat:"[[my name]]", Generator:(Host:“Current SUT”, Port:“5899”), Name:“SMARTAboutBox”, Styles:(Default:(:), Link:(TextBackgroundColor:"#E0E2EB", TextColor:"#0012FF", TextFont:“Microsoft Sans Serif”, TextSize:“8”, Underline:“Yes”), Title:(Bold:“Yes”, TextBackgroundColor:"#E0E2EB", TextColor:"#0E1010", TextFont:“Microsoft Sans Serif”, TextSize:“12”))), DefaultTextStyle:(:))
Wed, 25/03/09 2:25:15 PM Exception Unable to get TextImage. No TextFont specified

I am wondering why DefaultTextStyle says : instead of the actually properties not sure if this has something to do with it.

The problem is with this line:

set the DefaultTextStyle to "Title"

Although that looks perfectly reasonable, to set the DefaultTextStyle you must currently give it a property list containing the appropriate properties, not the name of a style. If “Title” is the name of one of the styles in the CurrentTextPlatform, you can set its values as the default like this:

set the DefaultTextStyle to the CurrentTextPlatform.styles.Title

I think we should consider this as a bug in Eggplant, or at least the documentation, since one of the examples suggests that it should work the way you tried it. So maybe we’ll support that in a future release, but for now you’ll need to provide an actual property list.

Excellent. Thanks Doug it works now.

I’m glad that helped.

By the way, I happened to notice that in the original script you posted at the beginning of this topic, you had a couple of nested repeat loops like this:

repeat with each item of fonts 
    repeat with each item of size
        -- some other code
    end repeat
end repeat

I just thought I’d mention that it’s not really recommended to nest repeats that don’t specify a repeat variable, since SenseTalk will use IT for both of them, which generally leads to problems. It looks like you worked around it in this case, but it might be clearer to work with if you specify a variable for at least one of them. There are several ways to include a variable name – here are a couple of them:

repeat with textFont = each item of fonts 
    repeat with each textSize of size
        -- some other code using textFont and textSize instead of It
    end repeat
end repeat

Hi, Jeff,

I wanted to mention that if you’re running against Windows, and you’re having to do a tolerance override anyway, you might also (or even instead) want to set the SearchType property to “Tolerant”. Eggplant is using the Text search type by default, which isn’t generally necessary for matching text on Windows which uses a lazier (i.e., less dynamic) form of antialiasing than is used on the Mac.

Thanks for the advice. I have used a lot of nested repeats in my scripts. I never really tried to reference it in both scripts but this could be the issue with slower times in some of my scripts. I will have to look into it more. Also ill definitely test out using various search types with TIG.

Here is one thing I noticed not sure if it is a bug or not.

set the CurrentTextPlatForm to “SMARTAboutBox”
set the DefaultTextStyle to the CurrentTextPlatform.styles.Title

–some code that uses these Text platforms and styles

set the DefaultTextStyle to the CurrentTextPlatform.styles.Default

–some code that uses the new style

The problem is that the style for the currenttextplatform doesn’t change to Default when I just call this line set the DefaultTextStyle to the CurrentTextPlatform.styles.Default. I actually have to do it like this for it to change. Both the styles are under the currenttextplatform that I set at the top of the code. It is the start of my script.

set the CurrentTextPlatForm to “SMARTAboutBox”
set the DefaultTextStyle to the CurrentTextPlatform.styles.Title

–some code that uses these Text platforms and styles

set the CurrentTextPlatForm to “SMARTAboutBox”
set the DefaultTextStyle to the CurrentTextPlatform.styles.Default

–some code that uses the new style

I would like to know if this is a bug or not. Not really a big issue but better to use 1 line of code then 2.

To explain briefly about this line:

set the DefaultTextStyle to the CurrentTextPlatform.styles.Default

This doesn’t actually do anything! As described in the documentation, “The DefaultTextStyle is a shortcut to the default text style for the current text platform”. Which means it’s just a simpler way to refer to the CurrentTextPlatform.Styles.Default – so this line is just assigning the default style to itself!

The reason your later code has any effect is because of this line:

set the CurrentTextPlatForm to "SMARTAboutBox"

This line actually makes a copy of the SMARTAboutBox text platform, which restores the default to what it was originally. Another option for you would be to make a copy of the default style before setting it to the Title style and then restore it from that copy later.

I hope that helps make it clear what’s happening here.

OK that makes sense to me now. Just a little confusing because the one TextStyle is named Default but then you are making a call to change the DefaultTextStyle.

set the DefaultTextStyle to the CurrentTextPlatform.styles.Link

So I was thinking that it was being flagged as the default one now so you would have set the named default one to be the default one again.