Chip,

    Class 15 examples.
below are draft examples for tomorrow's class:
' draft Scripting class 15 (6/12/2011)
' example 1:
' shows how to find the app manager window, find the listview control it is
displaying, and find the name of the .vbs file
' currently highlighted.
' (these are all techniques which you may use in many of your apps)
dim hk
' setup a hotkey to speak the currently highlighted app's .vbs file name
set hk = keyboard.registerHotkey("alt-control-i", "sayIt")
sub sayIt()
Dim wins
Dim kids
Dim appman
Dim lv
' first find the app manager window using it's title
Set wins = windows.FilterByTitle("App Manager")
If wins.Count = 1 Then
' found it
Set appman = wins(1)
' now find the window of it's listview control, which is known to be named
"List3"
Set kids = appman.Children.FilterByName("List3")
If kids.Count = 1 Then
' found it
' now use the control property of this window, which allows us access to all
control properties
Set lv = kids(1).Control
' note: if we needed to know the index number of the selected row, it can be
found in lv.items.Selected(1).index
speak "The selected app has a .vbs file named " & _
lv.text(, 3) ' 3rd column has the .vbs file name
' note: omitting the first argument to the .text method above causes it to
use the currently selected row
End If '  kids.Count = 1
End If '  wins.Count = 1
end sub
' end of example 1
' example 2:
' this example shows you how to get the entire text of the statusbar window
in Notepad
' (it could be used as an example of how to get the entire text of any
window or one of it's child windows)
dim objMainWindow
dim objStatusBarWindow
dim objResults
set objMainWindow = activeWindow.overlap ' assumes Notepad is the active
application
' below assumes you have used TreeView to find that the statusbar is in it's
own window by the name of  "msctls_statusbar32"
set objResults = objMainWindow.children.filterByName("msctls_statusbar32")
if not objResults is nothing then
if objResults.count > 0 then
' found the window!
set objStatusBarWindow = objResults(1) ' this gets the first window of the
collection
which was returned by the search
' now speak it's contents
speak objStatusBarWindow.clips.clipstext
' the .clips property above holds all the text of a window, broken down into
it's various clips.
' if you want *all* of the text in the window, you can get it from a
property of the clips collection named clipsText, which holds it all in one
big string
end if
end if
' end of example 2
' Example 3:
' shows how to get the text of a specific line of an overlap window using
the Text object.
' the text object is very versatile, allowing you to navigate through an
overlap window going a character, word, sentence, or line at a time.
' Sometimes though the text you want to examine can best be specified by
it's location
' on the screen; in particular, by it's location within the overlap window
of the application.
' In this case, you may not want to use all the text in a window object, but
just the
' text at a certain place on the display. The place is usually specified by
screen
' point X and Y coordinants, or by 4 coordinants which define an enclosing
rectangle
' (by defining the location of it's top, bottom, left, and right sides).
This has the
' possibility to return to you text contained in multiple child windows, or
in multiple
' clipps, which are physically adjacent to one another on the screen, but
which may
' not be stored together in one easily accessed data structure.
' In this example, the WECursor object's position is used to retrieve a line
of text,
' from whatever window object the WECursor object is positioned within. This
line of
' text may be the result of text from more than one child window object,
and/or more than
' one of it's clips.
dim sText
dim oMonitorPosition, oText
dim lineClips
Set oMonitorPosition = WECursor.Position ' property returns x and y screen
coordinants
Set oText = Text
' A copy of the Text root level object is made, into the oText variable.
This is done
' because some of the methods of the Text object keep track of data (such as
the last
' position you used as input to one of it's methods),so that they can then
implement
' functionality such as "previous line". This requires the object to be able
to modify
' itself to store these values, and in such cases, if you don't make a copy
of the
' object (which your script then owns), the copy of the object owned by WE
will not
' allow your script to modify it; therefore, functionality such as "previous
line"
' will not function properly, as the previous position will not be saved.
The MSAAEventSource
' is another such object which may require you to make a copy of it in order
to use
 ' it fully.
set lineClips  = oText.Line(oMonitorPosition)
' the line method actually returns a clips object, and one property of the
clips object
' is the clipsText string, which contains all of the text in all of the
clips, concatenated
' together into one long string.
sText = lineClips.ClipsText
' Points for the Example Above
' first, the position of the WE cursor is determined, and returned to the
script as
' a screenPoint object.
' next, this position is passed into the line method of the text object,
which returns
' a line of text (as represented by a clips collection), where the line is
specified
' by the position passed in, and, the bounderies of the overlap window
containing the screenPoint
' (this is not obvious from reading the script, but is explained in the
documentation
' of the line method and the enclosingRectangle property of the text
object). This prevents .line from giving you text
' which may have "bled over" from windows next to, or under, the one you are
working
' with.
' end of example 3

Sent: Thursday, September 12, 2013 7:50 PM
Subject: RE: text.nextline 


Jonathin,

 

I think I had written a wiki article on the use of these methods and the "text" 
object to retrieve text; perhaps Aaron would post it here or in their KB as the 
wiki is gone and I didn't save copies of all the articles I had written, and I 
can't find any of them on the KB.

 

I seem to recall it mentioned several documentation errors or omisions which 
were really helpful to know.  I'm just going from memory here, but I don't 
think it's documented that you need to make your own copy of the text object to 
work with for these methods to work properly.  Also, by default, the enclosing 
rectangle is that of the active window.  It could be that these things are 
documented, just very hard to find.

I believe I covered this article in class #15, as well as other methods for 
getting text from the display (some of them either more reliable or easier than 
using the text object).

 

This is why the wiki was so important (if there was no other reason, it gave us 
a way to correct and update/ogment documentation deficiencies).

 

Hth,

 

Chip

 

Chip

 

 

From: Jonathan C. Cohn [mailto:jon.c.c...@gmail.com] 
Sent: Thursday, September 12, 2013 7:43 AM
To: gw-scripting@gwmicro.com
Subject: text.nextline 

 

I understand that text.nextline(aScreenPoint) will return a set of clips and 
that there is a bounding rectangle of some kind associated with the method. I 
do have two questions.

 

1. Is the aScreenPointer then updated to the new line of text so conseccutive 
calls would return new clips?

 

How is the bounding rectangle specified?

 

Thanks,

 

 

Jonathan Cohn

 

 

 

 

Reply via email to