1

I'm trying to automate software installer (NSIS) with pywinauto. There is the TreeView as follow Some items a disabled (gray out).

I discovered that I can find if item disabled/enabled by analysing pattern of the state code returned.

app = Application()
app.start('some_path_to_exe_file')
dialod = app.window(title_re='some_title', enabled_only=True)   
item = dialog.child_window(class_name='SysTreeView32').get_item(r'\ABCD')
st = item.state()
print('{:b}'.format(st))

101000000000000

The difference between disabled and enabled item state in one bit, which was set for disabled item.

0101 0000 0000 0000

So, I can check this bit, but I wonder if there any other, more convenient method? Moreover, I'm not sure if state code consistent between applications.

shurkam
  • 81
  • 1
  • 5
  • Oh, this method is really not implemented! Thanks for point this out! Feel free to send pull request on GitHub. New method should be very simple like [is_selected at line 1393 of common_controls.py](https://github.com/pywinauto/pywinauto/blob/master/pywinauto/controls/common_controls.py#L1393). – Vasily Ryabov Jan 19 '18 at 13:27
  • Just need to think how to unit test it. We have unit tests with an sample app (not sure this MFC app contains disabled tree items). – Vasily Ryabov Jan 19 '18 at 13:29
  • 1
    @VasilyRyabov Thanks! I've implemented method [IsEnabled](https://github.com/shurkam/pywinauto/blob/77046d7067ec3cd4bc7702237586e7620d157efa/pywinauto/controls/common_controls.py#L1407) and [test for it](https://github.com/shurkam/pywinauto/blob/77046d7067ec3cd4bc7702237586e7620d157efa/pywinauto/unittests/test_common_controls.py#L772). However, I'm still not sure it will works across all applications. The test apps don't have any disabled items. Moreover, I didn't find a standard approach in creating disabled items. Most of recommendation was about changing colour, and make actions dormant. – shurkam Jan 21 '18 at 12:03
  • 1
    The test, also, doesn't cover the case when item disabled. So, I'll try to make more research and send pull request when I'll be sure that method robust enough. – shurkam Jan 21 '18 at 12:09
  • Thanks a lot for doing this job! The test apps source code can be changed in [PywinautoTestapps](https://github.com/pywinauto/PywinautoTestapps) repo if necessary. – Vasily Ryabov Jan 21 '18 at 12:24
  • This is probably TreeViewEx control. MSDN contains [article about TVITEMEX structure](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773459(v=vs.85).aspx) with `TVIS_EX_DISABLED` constant mentioned at the very bottom. – Vasily Ryabov Jan 21 '18 at 12:26
  • By the way, alias `IsEnabled` is not necessary because it's new method. These aliases were added for backward compatibility for old methods only. – Vasily Ryabov Jan 21 '18 at 12:29

0 Answers0