pyWinAuto: c:\.projects\py_pywinauto\pywinauto\taskbar.py

0001# GUI Application automation and testing library
0002# Copyright (C) 2006 Mark Mc Mahon
0003#
0004# This library is free software; you can redistribute it and/or
0005# modify it under the terms of the GNU Lesser General Public License
0006# as published by the Free Software Foundation; either version 2.1
0007# of the License, or (at your option) any later version.
0008#
0009# This library is distributed in the hope that it will be useful,
0010# but WITHOUT ANY WARRANTY; without even the implied warranty of
0011# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0012# See the GNU Lesser General Public License for more details.
0013#
0014# You should have received a copy of the GNU Lesser General Public
0015# License along with this library; if not, write to the
0016#    Free Software Foundation, Inc.,
0017#    59 Temple Place,
0018#    Suite 330,
0019#    Boston, MA 02111-1307 USA
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# windows explorer owns all these windows so get that app
0065explorer_app = application.Application().connect_(handle = TaskBarHandle())
0066
0067# Get the taskbar
0068TaskBar = explorer_app.window_(handle = TaskBarHandle())
0069
0070# The Start button
0071StartButton = TaskBar.Start
0072
0073# the Quick Launch toolbar
0074QuickLaunch = TaskBar.QuickLaunch
0075
0076# the system tray - contains various windows
0077SystemTray = TaskBar.TrayNotifyWnd
0078
0079# the clock is in the system tray
0080Clock = TaskBar.TrayClockWClass
0081
0082# these are the icons - what people normally think of
0083# as the system tray
0084SystemTrayIcons = TaskBar.NoficationArea
0085
0086# the toolbar with the running applications
0087RunningApplications = TaskBar.RunningApplicationsToolbar