Forum Discussion

John_OR's avatar
John_OR
Occasional Contributor
7 years ago
Solved

Python cluelessness with lists

Hi, I'm trying to transition from VBScript to Python and having some trouble understanding lists in Python.  What I'm trying to do is find all the comboboxes in a dialog and add them to a list.  Once they are in the list I iterate through the list setting the indexes of the comboboxes.  Unfortunately it's not working. 

 

Here is a simplified version of the code omitting the iteration through the list with a 'for' statement:

 

dlg = some_dialog

combos = [(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))]

combos[0].QComboBox_setCurrentIndex(1)

 

When I run the code I get this error:

AttributeError: 'SafeArrayWrapper' object has no attribute 'QComboBox_setCurrentIndex'

 

What is this "SafeArrayWrapper" business? 

 

Many thanks, John

  • It looks like I figured it out.  I changed :

    combos = [(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))]

     

    to

     

    combos = list(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))

     

    Removing the brackets per your suggestion and adding "list" did the trick.  Now setting the index is working and I'm able to append to the list.

     

     

     

9 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    Try to remove square brackets from your statement:

     

    combos = dlg.FindAllChildren(QtClassName,"OnOneComboBox",7)

    Otherwise you will receive array in array, something like:

     

    [[obj1, obj2, obj3]]
    • John_OR's avatar
      John_OR
      Occasional Contributor

      Hi, thanks for the tip.  Removing the brackets works but later when I want to append to the combos list/array it's not working.  Following on from my example I tried something like this:

      combos.append (some_other_combo_here)

       

      That gives me the familiar error:  "AttributeError" 'SafeArrayWrapper' object has no attribute 'append'.

       

      Any idea how I can successfully append to combos?

       

      Thanks,

      John

    • John_OR's avatar
      John_OR
      Occasional Contributor

      It looks like I figured it out.  I changed :

      combos = [(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))]

       

      to

       

      combos = list(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))

       

      Removing the brackets per your suggestion and adding "list" did the trick.  Now setting the index is working and I'm able to append to the list.

       

       

       

      • baxatob's avatar
        baxatob
        Community Hero

        FindAllChildren() returns list anyway. You can omit adding a list():

         

        combos = dlg.FindAllChildren(QtClassName,"OnOneComboBox",7)

         

  • NisHera's avatar
    NisHera
    Valued Contributor

    You said you are creating a list ...

    So what do you suppose to do with combos[0].QComboBox_setCurrentIndex(1) ?

    what the message saying is there is no attribute call "QComboBox_setCurrentIndex(1)" in lists class/object

     

    what index are you going to set?   

     

    for Iterate you can use combos[i] in for loop which iterate from 0 to len(combos)

     

    to understand python lists read this and this

     

     

    • John_OR's avatar
      John_OR
      Occasional Contributor

      Hi, thanks for the reply.  I'm expecting combos[0] to return the combobox object at index zero in the combos list.  Provided that happens QComboBox_setCurrentIndex(1) will select the second item in the combobox.  

       

      The problem is I'm not getting an object back with combos[0].  Instead of the combobox object I'm getting a "SafeArrayWrapper".  If I don't get the combobox back then QComboBox_setCurrentIndex(1) will obviously fail.

       

      Also, I can't find any information in Python documentation regarding a "SafeArrayWrapper" object.  My assumption is SafeArrayWrapper is a SmartBear/TestComplete construct that doesn't exist natively in Python.  I could be wrong about that though.

       

       

  • seco's avatar
    seco
    New Member

    I have a problem with VBScript for a long time. Wondering that there are some people still using it!

    However, I found this tutorial very useful for Python lists.