Pywinauto to control the media player

1.6k Views Asked by At

i am trying to control the windows media player using python with pywinauto framework. I am able to access the menu for example with app.WindowsMediaPlayer.MenuSelect("View->GoTo->Library") but when i try to access the library items, using the dialog unable to do so. similarly for the taskbar on the left want to access it directly without accessing the menu , by clicking the button on the left.... need help on this...

1

There are 1 best solutions below

0
On
>>> wmp.WindowsMediaPlayer.MenuSelect("View->Library")
>>> wmp.WindowsMediaPlayer.print_control_identifiers()
Control Identifiers:
WMPAppHost - 'WMPAppHost'   (L40, T152, R731, B648)
        'WMPAppHost' 'WMPAppHostWMPAppHost'
WMP Skin Host - ''   (L40, T188, R731, B588)
        '' '0' '1' 'WMP Skin Host'
ATL:5BB55150 - 'LibraryContainer'   (L40, T188, R731, B588)
        'ATL:5BB55150' 'LibraryContainer' 'LibraryContainerATL:5BB55150'
ATL:5BB550C0 - ''   (L190, T220, R193, B588)
        '2' 'ATL:5BB550C0'
ToolbarWindow32 - ''   (L40, T188, R40, B188)
        '3' 'Toolbar' 'Toolbar0' 'Toolbar1'
ToolbarWindow32 - 'View Toolbar'   (L416, T189, R461, B219)
        'Toolbar2' 'View Toolbar' 'View ToolbarToolbar'
ToolbarWindow32 - ''   (L705, T193, R729, B215)
        '4' 'Toolbar3'
ToolbarWindow32 - 'Command Toolbar'   (L44, T189, R414, B219)
        'Command Toolbar' 'Command ToolbarToolbar' 'Toolbar4'
Edit - 'Search'   (L465, T197, R663, B213)
        '5' 'Edit'
ToolbarWindow32 - ''   (L663, T194, R689, B214)
        '6' 'Toolbar5'
ToolbarWindow32 - ''   (L689, T194, R703, B214)
        '7' 'Toolbar6'
SysListView32 - 'PrimaryListView'   (L193, T220, R731, B588)
        'ListView' 'PrimaryListView' 'PrimaryListViewListView'
SysHeader32 - ''   (L193, T220, R716, B244)
        '8' 'Header'
SysTreeView32 - 'Library Treeview'   (L40, T220, R190, B538)
        'Library Treeview' 'Library TreeviewTreeView' 'TreeView'
ATL:5BB62F40 - 'ServiceBar'   (L40, T538, R190, B588)
        'ATL:5BB62F40' 'ServiceBar' 'ServiceBarATL:5BB62F40'
ToolbarWindow32 - 'Service Selector'   (L46, T541, R184, B585)
        'Service Selector' 'Service Selector0' 'Service Selector1' 'Service SelectorToolbar' 'Servic
e SelectorToolbar0' 'Service SelectorToolbar1' 'Toolbar7'
ToolbarWindow32 - 'Service Toolbar'   (L184, T541, R184, B585)
        'Service Toolbar' 'Service ToolbarToolbar' 'Toolbar8'
ToolbarWindow32 - 'Service Selector'   (L184, T541, R184, B585)
        'Service Selector2' 'Service SelectorToolbar2' 'Toolbar9'

The PrimaryListView looks like it may be what we need - so let's check by drawing a box around that control.

>>> wmp.WindowsMediaPlayer.PrimaryListView.DrawOutline()
>>>

Seems good :). So let's see if we can get the items from that listview

>>> wmp.WindowsMediaPlayer.PrimaryListView.ItemCount()
1217

so far so good

>>> for item_index in range(wmp.WindowsMediaPlayer.PrimaryListView.ItemCount()):
...   print  wmp.WindowsMediaPlayer.PrimaryListView.GetItem(item_index)
...
{'text': u'', 'state': 0L, 'indent': 240, 'image': 0}
{'text': u'', 'state': 0L, 'indent': 240, 'image': 0}
{'text': u'', 'state': 0L, 'indent': 240, 'image': 0}
...

Hmm = now that doesn't look too good :( And there I get stuck without more research