RE: [Pywinauto-users] Re: Question About Trackbar Automation
Status: Alpha
Brought to you by:
mcmahon_m
From: Comstock, D. <dco...@av...> - 2006-05-25 18:10:13
|
>You could also use the keyboard, right arrow =3D one tic, page up =3D = one >'page' End, end =3D last position. > >Not sure if that helps you (and requires a bit less calculation) :-) The calculations weren't that bad. My working assumption is that the trackbar is centered vertically within the enclosing rectangle; this may not be true in every case, but it holds true in mine. The trackbar also appears to be centered horizontally within the rectangle, but I'm not sure if the borders are a fixed width or some percentage of the rectangle's width. In my case, I determined empirically that the borders were 13 units wide: clicking within those 13-unit borders did not move the slider. So I created the following method to calculate the vertical coordinate within the rectangle for all mouse clicks and the minimum and maximum horizontal click positions: def GetTrackbarCoordinates(trackbarHandle): trackbarInformation =3D [] =20 trackbarProperties =3D trackbarHandle.GetProperties() trackbarRectangle =3D trackbarProperties["ClientRects"] trackbarCoordinates =3D trackbarRectangle.pop(0) =20 # X-coordinate of the minimum clickable position on the trackbar trackbarInformation.append(trackbarCoordinates.left + 13) =20 # X-coordinate of the maximum clickable position on the trackbar trackbarInformation.append(trackbarCoordinates.right - 14) =20 # Y-coordinate for all mouse clicks along the trackbar trackbarInformation.append((int)((trackbarCoordinates.bottom - trackbarCoordinates.top) / 2)) =20 # minimum slider position (hardcoded to 0; not in the properties!?!?) trackbarInformation.append(0) =20 # maximum slider position (hardcoded to 100; not in the properties!?!?) trackbarInformation.append(100) =20 # initial x-coordinate of the trackbar slider (0 in the range 0-100) trackbarInformation.append(trackbarCoordinates.left + 13) return trackbarInformation And the following method (which still needs bounds checking) moves the slider to any position on the trackbar. I've only tested it with my 0-100 sliders, but I think I've made it generic: def MoveTrackbarSlider(trackbar, newSliderPosition): trackbarHandle =3D trackbar["handle"] trackbarHandle.PressMouse(coords =3D = (trackbar["currentXcoordinate"], trackbar["yCoordinate"])) trackbarHorizontalLength =3D (trackbar["maxXcoordinate"] - trackbar["minXcoordinate"] + 1) newXcoordinate =3D (int(round((trackbarHorizontalLength * (newSliderPosition - trackbar["minimumSliderPosition"])) / (trackbar["maximumSliderPosition"] - trackbar["minimumSliderPosition"] + 1))) + trackbar["minXcoordinate"]) trackbarHandle.MoveMouse(coords =3D (newXcoordinate, trackbar["yCoordinate"])) trackbarHandle.ReleaseMouse() trackbar["currentXcoordinate"] =3D newXcoordinate Dave Comstock |