I'm sorry Bruce, but I just can't understand your point.

I don't believe my point is wrong, as I published an example to demonstrate
it; the only statement I made, is that the .focused.index property is
available during a listviewItemChange event, but you must test on "not
.focused is nothing" before using .focused.index, because several events are
generated when you change from one listview item to another. (I believe you
had said earlier it wasn't possible to use it).

If you have other points about how you can get other data other ways, I have
no arguments with those Bruce;  I only wished to point out how you can get
the documented data.

Maybe this will serve to straighten things out.

Chip


-----Original Message-----
From: LB [mailto:[email protected]] 
Sent: Sunday, January 19, 2014 11:09 PM
To: GW Scripting
Subject: Re: listbox change

Hi Chip,

    I guess we have beat this to death, but you are wrong Chip. For you have
just concluded there is no items list which there is, unless the Index is 0.

    You have tested the change but the list actually does exist in most
cases. So, the first test you say the Items does not exist, yes, no
collection made yet, so, use the Text, or Dcontrol.Text and this will give
you the item the list changed to even though the collection has not been
populated yet.

    so, test 2 says there is no list, for the item count is 0 and the list
starts at 1, so the second test will yield a dControl.Text of nothing, or
blank, which ever way you like it.

    Then the last one is only when focus has been obtained and you can get
the Index, now this can happen but have not tested it, when someone changes
the text or data of the selected item and I bet this will always show the
collection since we have not change the item pointer, so I will test that
suspicion and see if that is in fact correct.

    I am not taking anything away from your test, for this will in fact
cover all immediate options and I do mean immediate options.

    Now Jeff wanted to move up and down the list, so there is no focus until
the key or mouse click is released, thus my conclusion is correct and
justified.

    The focus event happens when you move away from the window and come back
or the first time there and it triggers. so if we are in the listview id of
your choosing you check either event and do something accordingly as I
showed in my example. I had not bothered with my Clipboard program until
Jeff asked a question and thought this might be something to add to my
program when wanting the index number on the fly and always track it.

    My list view does an array split for each line of the clipboard text and
this may also contain a list of file names from the copying of files from a
folder and my program takes the actual file list array and moves only the
names to the clipboard when it senses actual files copied to the clipboard.

    Thus when splitting that array out it moves each file name into the list
view and I also place the path in the second column and display only the
file name in the first column. Making it read easier.

    Then when I want to change the list either by sort or by just moving
items up or down, I can also move them to any location knowing the index,
but focus does that anyway, but it was a nice exercise to see how the list
view handles things and even the Microsoft web site says the collection is
not ready until focus has been obtained and the focus event is not sent when
moving up and down, but don't know why unless it has a different code which
GW has not listed; but have not checked other than what I found and Aaron
sent me. Code numbers fly in but some are not listed inside the Object Model
event list.

    So, the only thing I should add is the collection check and if it exists
and everyone will be happy for it at least allows you to move on if the
change happened with no key movement.

    Having all 3 tests are a good thing to have but do not give an accurate
result unless monitoring something else which tells you what you have to
wait for to get that index number; I.E. key up or button up events.

    Anyway, I was up all last night with a stubborn Sapi error inside my
Sapi class and discovered that the file stream can not be used again and
again without erasing and restarting and now have the convert text to wav
and read text file to sapi methods working properly. Inside my Cuckoo Clock
program I was doing that without a class, just embedded...and creating the
object each time I pressed the button.

    Thanks Chip, Bruce

Sent: Sunday, January 19, 2014 7:52 PM
Subject: RE: listbox change


Bruce,

I'm sorry to keep disagreeing with you, but you need to do a little more
testing here.  With a listview, you get several events generated with each
selection change, you do need to test on each property to make sure it
exists before you attempt to reference it, or indeed you will get the types
of errors you describe.  If you do test though, you will be able to get the
index property of the selected item, as the little test app I wrote should
demonstrate below.  I am able to get the index number each time I change the
selected listview item.

option explicit

Dialog "test_listview.xml", "test", "DialogEventHandler"

Function DialogEventHandler (dObj, dEvent, dId, dControl)
dim lv
dim items


DialogEventHandler = False

Select Case dEvent
case listviewItemChanged 
DialogEventHandler = True
set lv = dObj.control("test_lv")
set items = lv.items
if items is nothing then
queue "speakText", "no items collection"

else
if items.count = 0 then
queue "speakText", "items count is 0"

else
if not items.focused is nothing then
' you must test on the focused property to exist before referencing it, as
you get several events when a listview selection change occurs
queue  "speakText", "selected item " &  items.Focused.index
end if
end if
end if

Case dialogCreated
DialogEventHandler = True

Case buttonClicked
If dId = "close" then
dObj.Close
DialogEventHandler = True
End If
End Select

End Function


sub speakText(text)

speak text

end sub


<?xml version="1.0"?><wescriptui><language id="409"><dialog id="test"
modal="yes" caption="yes" frame="dialog" minimize="yes" sysmenu="yes"
resizable="yes"><![CDATA[test dialog for showing listview selection event
and how it will give the index]]><group orientation="horizontal" width="200"
height="300"><listview id="test_lv" selection="single" view="details"
columnheader="no"><listviewcolumn><![CDATA[column
1]]></listviewcolumn><listviewcolumn><![CDATA[column
2]]></listviewcolumn><listviewitem selected="yes"><![CDATA[first
item]]></listviewitem><listviewitem><![CDATA[second
item]]></listviewitem><listviewitem><![CDATA[third
item]]></listviewitem></listview><button id="close"
system="cancel"><![CDATA[Close]]></button></group></dialog></language></wesc
riptui>



-----Original Message-----
From: LB [mailto:[email protected]] 
Sent: Thursday, January 16, 2014 5:42 PM
To: [email protected]
Subject: Re: listbox change

Hi Chip,

    I just looked at that class and yes, class 31 shows an example which I
had discovered in my test but had not used in my app until Jeff had asked
the question.

    Your example I just looked at shows a use of the event to assign buttons
there enable state and nothing else.

    Also you mentioned the text part of the Listview which I mentioned does
work for you can get the text, but what about the Index number?

    It does not give that part of the control, it flat out says there is no
object, at least not yet. For it appears that this part of the control does
not come out until you have released the key you pressed. the index comes
out when the item has focus and I suspect that does not happen until the
action is done.

    The object model book states that some objects are not available and
that is one of them after trial and error and posting results to Jeff. Now
the difference is he is using a listbox not a listview and I have not tested
to see if the index number comes up while the event is happening.

    Now, I also had added the focused event where when moving away from the
window and back, interestingly it gives that part of the control which gives
out the index number. so you will note in my lengthy example I do not go
into any key pressed mode, I go directly to the routine to get the index
number for it.

    The reason why is that when this event is triggered the item has focus.
this event is only triggered when moving into the window of the control.

    but in the changed event there is no object given beneath the control
level. It says it needs an object, either inside the event if nor in the
Queue call to the routine, in both cases the error is, "Needs an object!"

    I just tested to see if the Items.Selected.Focused.Index works and "NO"
for this is doing the same thing, it first wants focus before giving up that
property.

    What I am saying when attempting to use the Items part of the list view
there is no object given until focus is complete. In other words the control
collection has not been formed until focus is obtained.

    So, in order to get the object I have to wait until the key is released,
or the key up event, in which the key modes are only given under
keyprossedUp event which makes sense for it means what it says.

    So at the moment I set a flag to extract the data I need and call the
routine to give me that information when the key is released. This is
actually the same thing your example does in setting button flags and
enabling them. For in doing so you have to make another key action after
focus is done to get to that button.

    You could test it and you would find the same problem, the items object
only under the listviewChanged event is not there, nor is the item object,
just the control properties and methods.

    I probably have talked too much on this and one can get lost when
stating too much.

    summary, under this event there has been no collection formed yet.

        Bruce

Sent: Thursday, January 16, 2014 1:19 PM
Subject: RE: listbox change


Bruce,

I'm still confused as to what you're problem is.

Class # 31 shows how to deal with detecting when a listview selected item
has changed.

Chip



-----Original Message-----
From: LB [mailto:[email protected]] 
Sent: Wednesday, January 15, 2014 7:50 AM
To: [email protected]
Subject: Re: listbox change

Hi Chip,

    My mistake, I am playing with the ListView and it has less features than
the ListBox and tried to mention that. I also had no time to test it out and
that makes it more confusing.

    For in the ListBox you have everything for setting and getting items but
no columns which I wanted at first but may not use in the future.

    At least Jeff has an example he can use but I did try to stress that all
the features he needed did exist in the ListBox but not the ListView.

    For when EventInfo is only given it defaults to the control and not it's
items in some case, for there is just no control for a selected item; it
says no object, and noticed it went to the control level instead.

    Buttons are nice but as I had stated, the keydown event and keyup even
can be used to compensate for control loss by setting and resetting a flag.

    Hopefully Jeff can get his app running using the example and yes, having
all the flags set for an app such as the Explicit is very important to
reduce debug time.

        Bruce

Sent: Tuesday, January 14, 2014 8:11 PM
Subject: RE: listbox change


Hi Jeff,

I'm sorry to keep disagreeing with Bruce, but I did take your example, made
several corrections, and it works just as expected.

You have several places where your names in the vbs don't match the names in
the xml, and you have a variable (or two) which aren't initialized (I think
sButton was one of them).  It might help if you added "option explicit" at
the top of the vbs.

Anyway, below is a modified version of your vbs example which speaks some
extra text each time the selected listbox item changes.  First yu'll hear We
read the new listbox item, then you'll hear my modified example speak the
same line with some added text at the beginning so you can tell it apart
from what WE is speaking.
Aside from correcting variable names, all I did was to add a test for the
listboxSelectionChange event(and as Bruce pointed out), you do have to
initialize it to start with, so that it will work the very first time;
otherwise, it won't start working until the second time.

option explicit

Dialog "testlist.xml", "Dialoglistbox", "DialogEventHandler"

Function DialogEventHandler(dObj, dEvent, dId, dControl)
Dim Result : Result = ""


If dEvent = dialogCreated Then
dObj.Control("lst").Width = 800
BuildList dObj
End If

DialogEventHandler = False
Select Case dEvent
' Process dialog events
case ListboxSelectionChange
DialogEventHandler = True
queue "SaySelectedItem",  dObj.control("lst").text

Case dialogCreated
DialogEventHandler = True

Case buttonClicked
If dId = "btnCancel" Then
dObj.Close
DialogEventHandler = True
End If

If dId = "BtnOk" Then
Result = dObj.Control("lst").Text
queue "SaySelectedItem",  Result
DialogEventHandler = True
End If

End Select

End Function

Function BuildList(dObj)
dObj.Control("lst").Add "This is the first line in the listBox!"
dObj.Control("lst").Add "Here is the second line."
dObj.Control("lst").Add "Here is the third and longest line in the listbox!"

dObj.Control("lst").FocusedIndex = 1
End Function

Sub SaySelectedItem(Result)
Speak "The item you selected was " & VbCrLf & Result
End Sub



Hth,

Chip

-----Original Message-----
From: Jeff Weiss [mailto:[email protected]] 
Sent: Tuesday, January 14, 2014 12:12 PM
To: [email protected]
Subject: Re: listbox change

I was unable to get any info while still in the list.  I found another way
to do what I wanted.  
I added an extra button, made it the default button with enter as its
shortcut, and by pressing enter while still in the list, I can get extra
information.  That's not exactly what I wanted, but it's close.

Below is a .vbs and a .xml file showing a simple listbox with 2 buttons.
The files are nameed 

DialogListBoxFromScript.vbs
DialogListBoxFromScript.xml

If anybody wants to try to add something to the select case section to
automatically speak additional information when you are just up or down
arrowing through the list, I would certainly appreciate knowing how to do
this.
thanks again,
Jeff Weiss


' DialogListBoxFromScript

Dim IsVisible : IsVisible = 0

Dim myHotkey : Set myHotkey =
Keyboard.RegisterHotkey("Alt-Control-Shift-I","LaunchDialog")

Sub LaunchDialog()
'This routine is called when the hotkey is pressed.

If isVisible = 0 Then
Queue "DisplayDialog"
End If
End Sub

Sub DisplayDialog()
Dialog "DialogListBoxFromScript.xml", "Dialoglistbox", "DialogEventHandler"
End Sub

Function DialogEventHandler(dObj, dEvent, dId, dControl)
Dim Result : Result = ""
dObj.Control("lst").Width = 800 

If dEvent = dialogCreated Then
BuildList dObj, Result
End If

DialogEventHandler = False

Select Case dEvent

' Process dialog events
Case dialogCreated

DialogEventHandler = True

Case buttonClicked

sButton = dControl.Text
sButton = Replace(sButton, "&", "")
Speak sButton

If sButton = "Close" Then
dObj.Control("lst").Clear
dObj.Close
Exit Function
End If

If sButton = "Ok" Then
Result = dObj.Control("lst").Text
SaySelectedItem dObj, Result

Result = ""
Exit Function
End If

End Select
End Function

Function BuildList(dObj, Result)

dObj.Control("lst").Add "This is the first line in the listBox!"
dObj.Control("lst").Add "Here is the second line."
dObj.Control("lst").Add "Here is the third and longest line in the listbox!"

dObj.Control("lst").FocusedIndex = 1
End Function

Sub SaySelectedItem(dObj, Result)
Sleep 200
Speak " "
Speak "The item you selected was " & VbCrLf & Result
Sleep 1000
End Sub


' here is the .xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wescriptui>
<options>
<languageorder>
WE,OS,en-us
</languageorder>
</options>
<language id="en-us">

<dialog id="Dialoglistbox" modal="yes">
ListBox from Script
<group>
<group>

<static shortcut="l">
List
</static>
<listbox id="lst" sort = "no">
</listbox>

</group>
<group justify="center">
<button id="BtnOk" default="yes" widthclass="button" shortcut="Enter">
Ok
</button>
<button id="btnCancel" system="cancel" widthclass="button">
Close
</button>
</group>
</group>
</dialog>

</language>
</wescriptui>



From: Chip Orange [mailto:[email protected]] 
Sent: Monday, January 13, 2014 12:21 PM
To: [email protected]
Subject: RE: listbox change

Jeff,

I don't see that you're initializing the variable Temp anywhere, and I also
don't see that you are setting the focusedIndex property of the listbox
anywhere (which is usually done when you add items to the listbox; you
usually set it to 1 when you add your listbox items).

Take out the line:
If fObj("lst").FocusedIndex <> Temp Then
And you should then hear something spoken each time your listbox item is
changed.

Chip


From: Jeff Weiss [mailto:[email protected]] 
Sent: Sunday, January 12, 2014 10:33 PM
To: [email protected]
Subject: Re: listbox change

Thank you for all of the suggestions.
This is indeed my own xml listbox dialog and I can get the button to work
but not the listbox change to register where I can do something when it
changes.
The list works fine and displays 12 spelling words.
Here is the function:
 
Function DialogEventHandler3(fObj, fEvent, fId, fControl)
DialogEventHandler3 = False
 
Dim Result : Result = ""
fObj.Control("lst").Width = 200 
 
If fEvent = dialogCreated Then
BuildList fObj, Result
End If
 
DialogEventHandler3 = False
 
Select Case fId
Case fId = "lst"
If fEvent = listboxSelectionChange Then
If fObj("lst").FocusedIndex <> Temp Then
Temp = fObj.Control("lst").FocusedIndex 
Result = fObj.Control("lst").Text
Speak Result
Speak Temp
Speak "this is a test."
Result = ""
Exit Function
End If
End If
 
Case "button_MainMenu"
If fEvent = buttonClicked Then
Speak ""
Sleep 200
Speak "Returning to Main Menu"
Sleep 200
fObj.Control("lst").Clear
fObj.Close
DialogEventHandler3 = True
Exit Function
End If
 
Case Else
If fEvent = dialogCreated Then
DialogEventHandler3 = True
 
Exit Function
End If
 
End Select
End Function
 
I must be missing something here.  Please let me know what I am missing
here.
thanks
Jeff Weiss


Jeff Weiss, M.Ed.
Director of Life Skills
Rehabilitation Teacher
World Services for the Blind
2811 Fair Park Blvd.
Little Rock, AR 72204
Email: [email protected]
www.wsblind.org

The mission of World Services for the Blind is empowering blind or visually
impaired adults in the United States and around the world to achieve
sustainable independence.


---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


---
This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com

Reply via email to