6 Replies Last post: Nov 20, 2009 7:15 AM by Mark Mc Mahon  
Raghav Beginner 27 posts since
Nov 10, 2009
Currently Being Moderated

Nov 18, 2009 11:09 AM

Differences in the code behaviour

Hi Mark, 
I have a sample.py file like this 

imports ....
imports....


Class Test TreeView(UnitTest.testcases) :

 def setUp(self) 
      app= Application()
       app.connect_( ...... ) I connect to application here, that is already opened.

     # get the dialog and ensure it is correct...
     my_dialog = app.window_(class_re = "...")  # there is probably nothing to do with tree view on this line
     my_dialog.DrawOutline("red")  # you should see a red outline around the dialog
 
     # try to get the treeview window...
     my_tree = my_dialog.TTreeView1
     my_tree.DrawOutline("green")    # should see a green outline around the tree view
 
     print my_tree.__class__.__name__  # is maybe printing windowspecification
 
     # force to TreeViewWrapper
     from pywinauto.controls.common_controls import TreeViewWrapper
     my_tree = TreeViewWrapper(my_tree.handle)
 
     print my_tree.__class__.__name__  # IS PRINTING  TreeVIewWrapper
 
        my_tree.Select((0,1))  # 


 def testSelect(self) 
     "Selecting the testcases"

if __name__ == "__main__"
unittest.main()

When I execute this in command prompt using " python samlpe.py "he clicks on TreeNode with no errors.




But when I have the code( with out class and func def) in a separate file called TriewView.py like this 

#  I have the necesay imports here ....
imports ....
imports....

 app= Application()
  app.connect_( ...... ) I connect to application here, that is already opened.

# get the dialog and ensure it is correct...
my_dialog = app.window_(class_re = "...")  # there is probably nothing to do with tree view on this line
my_dialog.DrawOutline("red")  # you should see a red outline around the dialog
 
# try to get the treeview window...
my_tree = my_dialog.TTreeView1
my_tree.DrawOutline("green")    # should see a green outline around the tree view
 
print my_tree.__class__.__name__  # is maybe printing windowspecification
 
# force to TreeViewWrapper
from pywinauto.controls.common_controls import TreeViewWrapper
my_tree = TreeViewWrapper(my_tree.handle)
 
print my_tree.__class__.__name__  # *******************IS PRINTING DIALOGWrapper INstead of TreeViewWrapper**********
my_tree.Select((0,1))  # 



When I try to execute this from cmd prompt it throws an attribute error

Attribute Error:  DialogWrapper object does not have attribute select.

The difference between the two is I have a Class and two functions inside that , I have the code 
in first approach, in the second one i dont have any class definition; 

The mode of execution like shown in second approach is very important for me since I am trying to 
parameterize the execution of python from Boost C++ Library

Could You please tell me where the mistake is ? 

with regards,
Raghav

Mark Mc Mahon Expert 278 posts since
Mar 17, 2006
Currently Being Moderated
1. Nov 19, 2009 9:58 AM in response to: Raghav
Re: Differences in the code behaviour

Hi Raghav,

 

Hmm - I have never used Boost.Python - and working with Embedded python is quite a bit different (or at least can bring up new challenges).

 

I would check first of all that you ONLY have one version of pywinauto on your machine.

 

Then in the Boost code - I would check what are the values of sys.path (e.g. "print sys.path"). Similarly you can try in both versions (with def's and without) to print out the module, which will show you the path it was loaded from.

e.g.

>>> import os
>>> print os
<module 'os' from 'c:\_tools\python261\lib\os.pyc'>

 

The only two ways I can think of you getting a DialogWrapper is ...

a) If you have added TTreeView to the windowclasses of DialogWrapper (don't do this )

b) you are passing the handle of a dialog and you haven't modified TreeViewWrapper.windowclasses  (note again - you need to modify the file, and not try to modify it in code, and remember that you need the updated __new__ from my earlier posting ALSO)

 

Finally where you say...

print my_tree.__class__.__name__  # is maybe printing windowspecification


If you change that to

print my_tree.WrapperObject().__class__.__name__  # is maybe printing windowspecification


After explicitly wrapping with TreeViewWrapper() - you need to use the original - as there is no WrapperObject in a TreeViewWrapper

 

Thanks

  Mark

Mark Mc Mahon Expert 278 posts since
Mar 17, 2006
Currently Being Moderated
4. Nov 20, 2009 5:30 AM in response to: Raghav
Re: Differences in the code behaviour

DAmn - lost a long reply to you because clearspace crashed

 

to make it short:

I suggest to remove your differnt versions - and have only one verion of pywinauto (where you make the changes I outlined earlier).

 

I believe at this point that the problems are actually in your environment rather than pywinauto.

 

I am out all next week on vacation - so I may well not be able to follow up on this until later.

 

Thanks

  mark

Mark Mc Mahon Expert 278 posts since
Mar 17, 2006
Currently Being Moderated
6. Nov 20, 2009 7:15 AM in response to: Raghav
Re: Differences in the code behaviour

Hi Raghav,

 

Just delete the folder pywinauto folder   (though I suggest to copy the HwndWrapper.py and common_controls.py first so that you have a history of the changes you made).

 

Thanks

  Mark

More Like This

  • Retrieving data ...