By way of thanks to Tim (who helped with the flash code) and Mark (who
posted the CastTo clue last year) here's a working example that:

        - opens a browser
        - navigates to google
        - finds the query tag
        - flashes it
        - finds the button tag
        - flashes it

Thanks for your help.

If anyone wants to use it, know that I've not tested the code extensively.
The usual disclaimers about fitness definitely apply.

BTW, there's an interesting bit of fuss in getting the tag's screen
coordinates.  It turned out to be a bit trickier than I'd expected.

Regards,
Richard

--- code ---

import win32com.client
import win32gui
import win32ui
import pprint
import time

def flashTag(tag):
    top, left, bottom, right = cord(tag)
    flash(top, left, bottom, right)

def cord(tag):
    # get the offset
    # see http://www.webreference.com/dhtml/diner/realpos1/
    # see http://msdn2.microsoft.com/en-us/library/ms530302.aspx
    nL = tag.offsetLeft
    nT = tag.offsetTop
    eP = tag.offsetParent
    while eP:
        if eP.__class__.__name__ == 'IHTMLElement':
            eP = eP.document.all.item(eP.sourceIndex)
        if(eP.tagName <> 'TABLE'):              # modified from ref since
want on screen not BODY relative
            nL += eP.clientLeft
            nT += eP.clientTop
        nL += eP.offsetLeft
        nT += eP.offsetTop
        eP = eP.offsetParent
    # get the doc
    doc = tag.ownerDocument             # the doc
    pwin = doc.parentWindow             # its parent HTML style window
    pwin2 = win32com.client.CastTo(pwin, 'IHTMLWindow3')    # the cast to
get to screen...
    top = pwin2.screenTop + nT          # screen cords for HTML style window
    left = pwin2.screenLeft + nL
    return (top, left, top+tag.offsetHeight, left+tag.offsetWidth)

def flash(top, left, bottom, right):
    gui_dc = win32gui.GetDC(0)                      # int handle screen DC
    pycdc = win32ui.CreateDCFromHandle(gui_dc)      # PyCDC object
    pycdc.SetROP2(7)                                # R2_XOR
    brush = win32ui.CreateBrush(0, 0, 0)            # create a brush (solid,
no color)
    pycdc.SelectObject(brush)                       # put it in the dc
    pen = win32ui.CreatePen(0, 3, 0x00ff00)         # colorref is 0x00bbggrr
    pycdc.SelectObject(pen)                         # put it in the dc
    cord = (left, top, right, bottom)
    for i in range(0,5):
        pycdc.Rectangle(cord)                       # make a solid rectangle
        time.sleep(.250)                            # hang out
        pycdc.Rectangle(cord)                       # put the screen back
        time.sleep(.250)                            # hang out
    win32gui.ReleaseDC(gui_dc,0)                    # all I have to release?

def DomEleToNode(element):
    xx = element.document.all.item(element.sourceIndex)
    return xx

time.time()
ie = win32com.client.DispatchEx('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate('www.google.com')
time.sleep(3)

queryHTML = ie.Document.all.tags('INPUT').namedItem('q')
flashTag(queryHTML)

btnTag = ie.Document.all.tags('INPUT').namedItem('btnG')
flashTag(btnTag)

--- end code ---



_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to