pyWinAuto: c:\.projects\py_pywinauto\pywinauto\taskbar.py
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021"""Module showing how to work with the task bar
0022
0023This module will likely change significantly in the future!"""
0024
0025import warnings
0026
0027from pywinauto import win32defines
0028from pywinauto import findwindows
0029from pywinauto import application
0030
0031warnings.warn("The taskbar module is still very experimental", FutureWarning)
0032
0033def TaskBarHandle():
0034 "Return the first window that has a class name 'Shell_TrayWnd'"
0035 return findwindows.find_windows(class_name = "Shell_TrayWnd")[0]
0036
0037
0038def _get_visible_button_index(reqd_button):
0039 "Get the nth visible icon"
0040 cur_button = -1
0041 for i in range(0, SystemTrayIcons.ButtonCount()):
0042 if not SystemTrayIcons.GetButton(i).fsState & win32defines.TBSTATE_HIDDEN:
0044
0045 cur_button += 1
0046
0047 if cur_button == reqd_button:
0048 return i
0049
0050def ClickSystemTrayIcon(button):
0051 "Click on a visible tray icon given by button"
0052 button = _get_visible_button_index(button)
0053 r = SystemTrayIcons.GetButtonRect(button)
0054 SystemTrayIcons.ClickInput(coords = (r.left+2, r.top+2))
0055
0056def RightClickSystemTrayIcon(button):
0057 "Right click on a visible tray icon given by button"
0058 button = _get_visible_button_index(button)
0059 r = SystemTrayIcons.GetButtonRect(button)
0060 SystemTrayIcons.RightClickInput(coords = (r.left+2, r.top+2))
0061
0062
0063
0064
0065explorer_app = application.Application().connect_(handle = TaskBarHandle())
0066
0067
0068TaskBar = explorer_app.window_(handle = TaskBarHandle())
0069
0070
0071StartButton = TaskBar.Start
0072
0073
0074QuickLaunch = TaskBar.QuickLaunch
0075
0076
0077SystemTray = TaskBar.TrayNotifyWnd
0078
0079
0080Clock = TaskBar.TrayClockWClass
0081
0082
0083
0084SystemTrayIcons = TaskBar.NoficationArea
0085
0086
0087RunningApplications = TaskBar.RunningApplicationsToolbar